drop getBroadcastAddresses()
in favor of discoverInterfaces(). if we have to do NIC discovery ourselves, then at least avoid mixing our results with the similar, but not identical results of osiSockDiscoverBroadcastAddresses() from Base.
This commit is contained in:
@ -26,38 +26,6 @@ using namespace epics::pvData;
|
||||
namespace epics {
|
||||
namespace pvAccess {
|
||||
|
||||
void addDefaultBroadcastAddress(InetAddrVector* v, unsigned short p) {
|
||||
osiSockAddr pNewNode;
|
||||
memset(&pNewNode, 0, sizeof(pNewNode));
|
||||
pNewNode.ia.sin_family = AF_INET;
|
||||
// TODO this does not work in case of no active interfaces, should return 127.0.0.1 then
|
||||
pNewNode.ia.sin_addr.s_addr = htonl(INADDR_BROADCAST);
|
||||
pNewNode.ia.sin_port = htons(p);
|
||||
v->push_back(pNewNode);
|
||||
}
|
||||
|
||||
void getBroadcastAddresses(InetAddrVector& ret,
|
||||
SOCKET sock,
|
||||
unsigned short defaultPort) {
|
||||
ret.clear();
|
||||
ELLLIST as;
|
||||
ellInit(&as);
|
||||
osiSockAddr serverAddr;
|
||||
memset(&serverAddr, 0, sizeof(osiSockAddr));
|
||||
osiSockDiscoverBroadcastAddresses(&as, sock, &serverAddr);
|
||||
for(ELLNODE * n = ellFirst(&as); n != NULL; n = ellNext(n))
|
||||
{
|
||||
osiSockAddrNode * sn = (osiSockAddrNode *)n;
|
||||
sn->addr.ia.sin_port = htons(defaultPort);
|
||||
// TODO discover possible duplicates
|
||||
ret.push_back(sn->addr);
|
||||
}
|
||||
ellFree(&as);
|
||||
// add fallback address
|
||||
if (!ret.size())
|
||||
addDefaultBroadcastAddress(&ret, defaultPort);
|
||||
}
|
||||
|
||||
void encodeAsIPv6Address(ByteBuffer* buffer, const osiSockAddr* address) {
|
||||
// IPv4 compatible IPv6 address
|
||||
// first 80-bit are 0
|
||||
|
@ -23,14 +23,6 @@ namespace pvAccess {
|
||||
|
||||
typedef std::vector<osiSockAddr> InetAddrVector;
|
||||
|
||||
/**
|
||||
* Populate a vector containing all the IPv4 broadcast addresses on this machine.
|
||||
* IPv6 doesn't have a local broadcast address.
|
||||
* Conversion of the defaultPort to network byte order performed by
|
||||
* the function.
|
||||
*/
|
||||
epicsShareFunc void getBroadcastAddresses(InetAddrVector& ret, SOCKET sock, unsigned short defaultPort);
|
||||
|
||||
struct ifaceNode {
|
||||
osiSockAddr addr, //!< Our address
|
||||
peer, //!< point to point peer
|
||||
|
@ -178,27 +178,6 @@ void test_isMulticastAddress()
|
||||
testOk1(isMulticastAddress(&vec.at(5)));
|
||||
}
|
||||
|
||||
void test_getBroadcastAddresses()
|
||||
{
|
||||
testDiag("Test getBroadcastAddresses()");
|
||||
|
||||
osiSockAttach();
|
||||
|
||||
SOCKET socket = epicsSocketCreate(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
InetAddrVector broadcasts;
|
||||
getBroadcastAddresses(broadcasts, socket, 6678);
|
||||
// at least one is expected, in case of no network connection a fallback address is returned
|
||||
testOk1(static_cast<size_t>(0) < broadcasts.size());
|
||||
//testDiag("getBroadcastAddresses() returned %zu entry/-ies.", broadcasts->size());
|
||||
epicsSocketDestroy(socket);
|
||||
|
||||
// debug
|
||||
for(size_t i = 0; i<broadcasts.size(); i++) {
|
||||
testDiag("%s", inetAddressToString(broadcasts[i]).c_str());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void test_getLoopbackNIF()
|
||||
{
|
||||
testDiag("Test getLoopbackNIF()");
|
||||
@ -369,7 +348,7 @@ void test_multicastLoopback()
|
||||
|
||||
MAIN(testInetAddressUtils)
|
||||
{
|
||||
testPlan(80);
|
||||
testPlan(79);
|
||||
testDiag("Tests for InetAddress utils");
|
||||
|
||||
test_getSocketAddressList();
|
||||
@ -377,7 +356,6 @@ MAIN(testInetAddressUtils)
|
||||
test_intToIPv4Address();
|
||||
test_encodeAsIPv6Address();
|
||||
test_isMulticastAddress();
|
||||
test_getBroadcastAddresses();
|
||||
test_getLoopbackNIF();
|
||||
|
||||
test_multicastLoopback();
|
||||
|
Reference in New Issue
Block a user