pvAccessCPP  7.1.7
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
inetAddressUtil.h
1 
7 #ifndef INETADDRESSUTIL_H_
8 #define INETADDRESSUTIL_H_
9 
10 #include <vector>
11 
12 #include <osiSock.h>
13 #include <shareLib.h>
14 
15 #include <pv/pvType.h>
16 #include <pv/byteBuffer.h>
17 
18 namespace epics {
19 namespace pvAccess {
20 
21 typedef std::vector<osiSockAddr> InetAddrVector;
22 
23 struct ifaceNode {
24  osiSockAddr addr,
25  peer,
26  bcast,
27  mask;
28  bool loopback,
29  validP2P,
30  validBcast;
31  ifaceNode();
32 };
33 typedef std::vector<ifaceNode> IfaceNodeVector;
34 epicsShareFunc int discoverInterfaces(IfaceNodeVector &list, SOCKET socket, const osiSockAddr *pMatchAddr = 0);
35 
41 epicsShareFunc void encodeAsIPv6Address(epics::pvData::ByteBuffer* buffer, const osiSockAddr* address);
42 
49 epicsShareFunc bool decodeAsIPv6Address(epics::pvData::ByteBuffer* buffer, osiSockAddr* address);
50 
56 epicsShareFunc bool isMulticastAddress(const osiSockAddr* address);
57 
66 epicsShareFunc void getSocketAddressList(InetAddrVector& ret, const std::string & list, int defaultPort,
67  const InetAddrVector* appendList = NULL);
68 
69 epicsShareFunc std::string inetAddressToString(const osiSockAddr &addr,
70  bool displayPort = true, bool displayHex = false);
71 
72 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
73 
74 // comparators for osiSockAddr
75 
76 struct comp_osiSock_lt {
77  bool operator()(const osiSockAddr& a, const osiSockAddr& b) const {
78  if(a.sa.sa_family<b.sa.sa_family) return true;
79  if((a.sa.sa_family==b.sa.sa_family)&&(a.ia.sin_addr.s_addr
80  <b.ia.sin_addr.s_addr)) return true;
81  if((a.sa.sa_family==b.sa.sa_family)&&(a.ia.sin_addr.s_addr
82  ==b.ia.sin_addr.s_addr)&&(a.ia.sin_port
83  <b.ia.sin_port)) return true;
84  return false;
85  }
86 };
87 
88 }} // namespace epics::pvAccess
89 
90 #endif /* INETADDRESSUTIL_H_ */
void encodeAsIPv6Address(epics::pvData::ByteBuffer *buffer, const osiSockAddr *address)
Encode IPv4 address as IPv6 address.
bool decodeAsIPv6Address(epics::pvData::ByteBuffer *buffer, osiSockAddr *address)
Decode IPv6 address (as IPv4 address).
void getSocketAddressList(InetAddrVector &ret, const std::string &list, int defaultPort, const InetAddrVector *appendList=NULL)
Parse space delimited addresss[:port] string and populate array of InetSocketAddress.
bool isMulticastAddress(const osiSockAddr *address)
Check if an IPv4 address is a multicast address.