remove unused, and un-useful, IP address utils
This commit is contained in:
@ -685,7 +685,10 @@ void initializeUDPTransports(bool serverFlag,
|
||||
|
||||
// TODO configurable local NIF, address
|
||||
osiSockAddr loAddr;
|
||||
getLoopbackNIF(loAddr, "", 0);
|
||||
memset(&loAddr, 0, sizeof(loAddr));
|
||||
loAddr.ia.sin_family = AF_INET;
|
||||
loAddr.ia.sin_port = ntohs(0);
|
||||
loAddr.ia.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
|
||||
|
||||
// TODO configurable local multicast address
|
||||
std::string mcastAddress("224.0.0.128");
|
||||
|
@ -79,17 +79,6 @@ bool isMulticastAddress(const osiSockAddr* address) {
|
||||
return msB >= 224 && msB <= 239;
|
||||
}
|
||||
|
||||
void intToIPv4Address(osiSockAddr& ret, int32 addr) {
|
||||
memset(&ret, 0, sizeof(ret));
|
||||
ret.ia.sin_family = AF_INET;
|
||||
ret.ia.sin_addr.s_addr = htonl(addr);
|
||||
ret.ia.sin_port = 0;
|
||||
}
|
||||
|
||||
int32 ipv4AddressToInt(const osiSockAddr& addr) {
|
||||
return (int32)ntohl(addr.ia.sin_addr.s_addr);
|
||||
}
|
||||
|
||||
void getSocketAddressList(InetAddrVector& ret,
|
||||
const std::string & list, int defaultPort,
|
||||
const InetAddrVector* appendList) {
|
||||
@ -140,23 +129,6 @@ string inetAddressToString(const osiSockAddr &addr,
|
||||
return saddr.str();
|
||||
}
|
||||
|
||||
int getLoopbackNIF(osiSockAddr &loAddr, string const & localNIF, unsigned short port)
|
||||
{
|
||||
if (!localNIF.empty())
|
||||
{
|
||||
if (aToIPAddr(localNIF.c_str(), port, &loAddr.ia) == 0)
|
||||
return 0;
|
||||
// else TODO log error
|
||||
}
|
||||
|
||||
// fallback
|
||||
memset(&loAddr, 0, sizeof(loAddr));
|
||||
loAddr.ia.sin_family = AF_INET;
|
||||
loAddr.ia.sin_port = ntohs(port);
|
||||
loAddr.ia.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
|
||||
return 1;
|
||||
}
|
||||
|
||||
ifaceNode::ifaceNode()
|
||||
{
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
|
@ -15,9 +15,6 @@
|
||||
#include <pv/pvType.h>
|
||||
#include <pv/byteBuffer.h>
|
||||
|
||||
|
||||
// TODO implement using smart pointers
|
||||
|
||||
namespace epics {
|
||||
namespace pvAccess {
|
||||
|
||||
@ -36,11 +33,6 @@ struct ifaceNode {
|
||||
typedef std::vector<ifaceNode> IfaceNodeVector;
|
||||
epicsShareFunc int discoverInterfaces(IfaceNodeVector &list, SOCKET socket, const osiSockAddr *pMatchAddr = 0);
|
||||
|
||||
/**
|
||||
* Returns NIF index for given interface address, or -1 on failure.
|
||||
*/
|
||||
epicsShareFunc int discoverInterfaceIndex(SOCKET socket, const osiSockAddr *pMatchAddr);
|
||||
|
||||
/**
|
||||
* Encode IPv4 address as IPv6 address.
|
||||
* @param buffer byte-buffer where to put encoded data.
|
||||
@ -63,20 +55,6 @@ epicsShareFunc bool decodeAsIPv6Address(epics::pvData::ByteBuffer* buffer, osiSo
|
||||
*/
|
||||
epicsShareFunc bool isMulticastAddress(const osiSockAddr* address);
|
||||
|
||||
/**
|
||||
* Convert an integer into an IPv4 INET address.
|
||||
* @param ret address stored here
|
||||
* @param addr integer representation of a given address.
|
||||
*/
|
||||
epicsShareFunc void intToIPv4Address(osiSockAddr& ret, epics::pvData::int32 addr);
|
||||
|
||||
/**
|
||||
* Convert an IPv4 INET address to an integer.
|
||||
* @param addr IPv4 INET address.
|
||||
* @return integer representation of a given address.
|
||||
*/
|
||||
epicsShareFunc epics::pvData::int32 ipv4AddressToInt(const osiSockAddr& addr);
|
||||
|
||||
/**
|
||||
* Parse space delimited addresss[:port] string and populate array of <code>InetSocketAddress</code>.
|
||||
* @param ret results stored hre
|
||||
@ -91,8 +69,6 @@ epicsShareFunc void getSocketAddressList(InetAddrVector& ret, const std::string
|
||||
epicsShareFunc std::string inetAddressToString(const osiSockAddr &addr,
|
||||
bool displayPort = true, bool displayHex = false);
|
||||
|
||||
epicsShareFunc int getLoopbackNIF(osiSockAddr& loAddr, std::string const & localNIF, unsigned short port);
|
||||
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
// comparators for osiSockAddr
|
||||
|
@ -113,34 +113,6 @@ void test_getSocketAddressList()
|
||||
testOk1("192.168.3.4:555" == inetAddressToString(addr));
|
||||
}
|
||||
|
||||
void test_ipv4AddressToInt()
|
||||
{
|
||||
testDiag("Test ipv4AddressToInt()");
|
||||
|
||||
InetAddrVector vec;
|
||||
getSocketAddressList(vec, "127.0.0.1 10.10.12.11:1234 192.168.3.4", 555);
|
||||
|
||||
testOk1(static_cast<size_t>(3) == vec.size());
|
||||
|
||||
testOk1((int32)0x7F000001 == ipv4AddressToInt((vec.at(0))));
|
||||
testOk1((int32)0x0A0A0C0B == ipv4AddressToInt((vec.at(1))));
|
||||
testOk1((int32)0xC0A80304 == ipv4AddressToInt((vec.at(2))));
|
||||
}
|
||||
|
||||
void test_intToIPv4Address()
|
||||
{
|
||||
testDiag("Test intToIPv4Address()");
|
||||
|
||||
osiSockAddr addr;
|
||||
intToIPv4Address(addr, 0x7F000001);
|
||||
testOk1(AF_INET == addr.ia.sin_family);
|
||||
testOk1("127.0.0.1:0" == inetAddressToString(addr));
|
||||
|
||||
intToIPv4Address(addr, 0x0A0A0C0B);
|
||||
testOk1(AF_INET == addr.ia.sin_family);
|
||||
testOk1("10.10.12.11:0" == inetAddressToString(addr));
|
||||
}
|
||||
|
||||
void test_encodeAsIPv6Address()
|
||||
{
|
||||
testDiag("Test encodeAsIPv6Address()");
|
||||
@ -153,7 +125,9 @@ void test_encodeAsIPv6Address()
|
||||
};
|
||||
|
||||
osiSockAddr addr;
|
||||
intToIPv4Address(addr, 0x0A0A0C0B);
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
addr.ia.sin_family = AF_INET;
|
||||
addr.ia.sin_addr.s_addr = htonl(0x0A0A0C0B);
|
||||
|
||||
encodeAsIPv6Address(buff.get(), &addr);
|
||||
testOk1(static_cast<size_t>(16) == buff->getPosition());
|
||||
@ -178,28 +152,6 @@ void test_isMulticastAddress()
|
||||
testOk1(isMulticastAddress(&vec.at(5)));
|
||||
}
|
||||
|
||||
void test_getLoopbackNIF()
|
||||
{
|
||||
testDiag("Test getLoopbackNIF()");
|
||||
|
||||
osiSockAddr addr;
|
||||
unsigned short port = 5555;
|
||||
|
||||
int defaultValue = getLoopbackNIF(addr, "", port);
|
||||
|
||||
testOk1(defaultValue);
|
||||
testOk1(AF_INET == addr.ia.sin_family);
|
||||
testOk1(htons(port) == addr.ia.sin_port);
|
||||
testOk1(htonl(INADDR_LOOPBACK) == addr.ia.sin_addr.s_addr);
|
||||
|
||||
defaultValue = getLoopbackNIF(addr, "10.0.0.1:7777", port);
|
||||
|
||||
testOk1(!defaultValue);
|
||||
testOk1(AF_INET == addr.ia.sin_family);
|
||||
testOk1(htons(7777) == addr.ia.sin_port);
|
||||
testOk1(htonl(0x0A000001) == addr.ia.sin_addr.s_addr);
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
// needed for ip_mreq
|
||||
#include <ws2tcpip.h>
|
||||
@ -238,7 +190,10 @@ void test_multicastLoopback()
|
||||
}
|
||||
|
||||
osiSockAddr loAddr;
|
||||
getLoopbackNIF(loAddr, "", port);
|
||||
memset(&loAddr, 0, sizeof(loAddr));
|
||||
loAddr.ia.sin_family = AF_INET;
|
||||
loAddr.ia.sin_port = ntohs(port);
|
||||
loAddr.ia.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
|
||||
|
||||
osiSockAddr mcastAddr;
|
||||
aToIPAddr("224.0.0.128", port, &mcastAddr.ia);
|
||||
@ -348,15 +303,12 @@ void test_multicastLoopback()
|
||||
|
||||
MAIN(testInetAddressUtils)
|
||||
{
|
||||
testPlan(79);
|
||||
testPlan(63);
|
||||
testDiag("Tests for InetAddress utils");
|
||||
|
||||
test_getSocketAddressList();
|
||||
test_ipv4AddressToInt();
|
||||
test_intToIPv4Address();
|
||||
test_encodeAsIPv6Address();
|
||||
test_isMulticastAddress();
|
||||
test_getLoopbackNIF();
|
||||
|
||||
test_multicastLoopback();
|
||||
|
||||
|
Reference in New Issue
Block a user