otsdaq  v2_00_00
NetworkDevice.h
1 #ifndef _ots_NetworkDevice_h_
2 #define _ots_NetworkDevice_h_
3 
4 #include <string>
5 #include <map>
6 #include <netinet/in.h>
7 
8 struct ifaddrs;
9 
10 namespace ots
11 {
12 
14 {
15 public:
16  NetworkDevice(std::string IPAddress, unsigned int port);
17  ~NetworkDevice();
18 
19  int initSocket (std::string socketPort="");
20  int initSocket (unsigned int socketPort);
21  //int closeSocket(std::string socketPort="");
22  int ping (int socketDescriptor);
23  int send (int socketDescriptor, const std::string& msg);
24  int receive (int socketDescriptor, std::string& msg);
25  int listen (int socketDescriptor, std::string& msg);
26  std::string getFullIPAddress(std::string partialIpAddress);
27  std::string getInterfaceName(std::string ipAddress);
28  std::string getMacAddress (std::string interfaceName);
29 
30 protected:
31  enum {maxSocketSize=65536};
32 
33  struct sockaddr_in deviceAddress_;
34  // socket,socket port
35  std::map<int,int> openSockets_;
36 
37 private:
38  enum{FirstSocketPort=10000,LastSocketPort=15000};
39 
40  int getInterface(std::string partialIpAddress);
41 
42  struct ifaddrs* communicationInterface_;//Interface communicating with device aka computer interface
43 };
44 
45 }
46 
47 #endif