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