pvAccessCPP  7.1.1
inetAddressUtil.h
1 /**
2  * Copyright - See the COPYRIGHT that is included with this distribution.
3  * pvAccessCPP is distributed subject to a Software License Agreement found
4  * in file LICENSE that is included with this distribution.
5  */
6 
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, //!< Our address
25  peer, //!< point to point peer
26  bcast,//!< sub-net broadcast address
27  mask; //!< Net mask
28  bool loopback,
29  validP2P, //!< true if peer has been set.
30  validBcast; //!< true if bcast and mask have been set
31  ifaceNode();
32 };
33 typedef std::vector<ifaceNode> IfaceNodeVector;
34 epicsShareFunc int discoverInterfaces(IfaceNodeVector &list, SOCKET socket, const osiSockAddr *pMatchAddr = 0);
35 
36 /**
37  * Encode IPv4 address as IPv6 address.
38  * @param buffer byte-buffer where to put encoded data.
39  * @param address address to encode.
40  */
41 epicsShareFunc void encodeAsIPv6Address(epics::pvData::ByteBuffer* buffer, const osiSockAddr* address);
42 
43 /**
44  * Decode IPv6 address (as IPv4 address).
45  * @param buffer byte-buffer where to get encoded data.
46  * @param address address where to decode.
47  * @return success status (true on success).
48  */
49 epicsShareFunc bool decodeAsIPv6Address(epics::pvData::ByteBuffer* buffer, osiSockAddr* address);
50 
51 /**
52  * Check if an IPv4 address is a multicast address.
53  * @param address IPv4 address to check.
54  * @return true if the adress is a multicast address.
55  */
56 epicsShareFunc bool isMulticastAddress(const osiSockAddr* address);
57 
58 /**
59  * Parse space delimited addresss[:port] string and populate array of <code>InetSocketAddress</code>.
60  * @param ret results stored hre
61  * @param list space delimited addresss[:port] string.
62  * @param defaultPort port take if not specified.
63  * @param appendList list to be appended.
64  * @return array of <code>InetSocketAddress</code>.
65  */
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_ */
Copyright - See the COPYRIGHT that is included with this distribution.