00001 #ifndef _ots_NetworkDevice_h_
00002 #define _ots_NetworkDevice_h_
00003
00004 #include <string>
00005 #include <map>
00006 #include <netinet/in.h>
00007
00008 struct ifaddrs;
00009
00010 namespace ots
00011 {
00012
00013 class NetworkDevice
00014 {
00015 public:
00016 NetworkDevice(std::string IPAddress, unsigned int port);
00017 ~NetworkDevice();
00018
00019 int initSocket (std::string socketPort="");
00020 int initSocket (unsigned int socketPort);
00021
00022 int ping (int socketDescriptor);
00023 int send (int socketDescriptor, const std::string& msg);
00024 int receive (int socketDescriptor, std::string& msg);
00025 int listen (int socketDescriptor, std::string& msg);
00026 std::string getFullIPAddress(std::string partialIpAddress);
00027 std::string getInterfaceName(std::string ipAddress);
00028 std::string getMacAddress (std::string interfaceName);
00029
00030 protected:
00031 enum {maxSocketSize=65536};
00032
00033 struct sockaddr_in deviceAddress_;
00034
00035 std::map<int,int> openSockets_;
00036
00037 private:
00038 enum{FirstSocketPort=10000,LastSocketPort=15000};
00039
00040 int getInterface(std::string partialIpAddress);
00041
00042 struct ifaddrs* communicationInterface_;
00043 };
00044
00045 }
00046
00047 #endif