• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

ibrcommon/ibrcommon/net/udpsocket.h

Go to the documentation of this file.
00001 /*
00002  * udpsocket.h
00003  *
00004  *  Created on: 02.03.2010
00005  *      Author: morgenro
00006  */
00007 
00008 #ifndef UDPSOCKET_H_
00009 #define UDPSOCKET_H_
00010 
00011 #include "ibrcommon/net/NetInterface.h"
00012 #include "ibrcommon/Exceptions.h"
00013 #include <list>
00014 #include <netinet/in.h>
00015 #include <arpa/inet.h>
00016 #include <sys/socket.h>
00017 #include <sys/types.h>
00018 
00019 namespace ibrcommon
00020 {
00021         class udpsocket
00022         {
00023         public:
00024                 class SocketException : public ibrcommon::Exception
00025                 {
00026                 public:
00027                         SocketException(string error) : ibrcommon::Exception(error)
00028                         {};
00029                 };
00030 
00031                 class peer
00032                 {
00033                         friend class udpsocket;
00034 
00035                 protected:
00036                         peer(udpsocket &socket, const struct sockaddr_in &dest, const unsigned int port);
00037 
00038                         struct sockaddr_in _destaddress;
00039                         udpsocket &_socket;
00040 
00041                 public:
00042                         int send(const char *data, const size_t length);
00043                 };
00044 
00045                 virtual ~udpsocket();
00046 
00047                 virtual void shutdown();
00048 
00049                 int receive(char* data, size_t maxbuffer);
00050                 int receive(char* data, size_t maxbuffer, std::string &address);
00051 
00052                 udpsocket::peer getPeer(const std::string address, const unsigned int port);
00053 
00054         protected:
00055                 udpsocket(u_char proto = 0) throw (SocketException);
00056                 int _socket;
00057                 struct sockaddr_in _sockaddr;
00058         };
00059 }
00060 
00061 #endif /* UDPSOCKET_H_ */

Generated on Thu Nov 11 2010 09:49:47 for IBR-DTNSuite by  doxygen 1.7.1