Some final fixes to addressUtils regarding byte-order.
This commit is contained in:
@@ -115,7 +115,7 @@ namespace epics {
|
||||
// next 16-bits are 1
|
||||
buffer->putShort(0xFFFF);
|
||||
// following IPv4 address in big-endian (network) byte order
|
||||
in_addr_t ipv4Addr = address->ia.sin_addr.s_addr;
|
||||
in_addr_t ipv4Addr = ntohl(address->ia.sin_addr.s_addr);
|
||||
buffer->putByte((int8)((ipv4Addr>>24)&0xFF));
|
||||
buffer->putByte((int8)((ipv4Addr>>16)&0xFF));
|
||||
buffer->putByte((int8)((ipv4Addr>>8)&0xFF));
|
||||
@@ -166,7 +166,7 @@ namespace epics {
|
||||
retAddr <<= 8;
|
||||
retAddr |= byte;
|
||||
|
||||
return retAddr;
|
||||
return htonl(retAddr);
|
||||
}
|
||||
|
||||
InetAddrVector* getSocketAddressList(String list, int defaultPort,
|
||||
@@ -198,7 +198,7 @@ namespace epics {
|
||||
}
|
||||
|
||||
const String inetAddressToString(const osiSockAddr *addr,
|
||||
bool displayHex) {
|
||||
bool displayPort, bool displayHex) {
|
||||
stringstream saddr;
|
||||
|
||||
int ipa = ntohl(addr->ia.sin_addr.s_addr);
|
||||
@@ -207,9 +207,9 @@ namespace epics {
|
||||
saddr<<((int)(ipa>>16)&0xFF)<<'.';
|
||||
saddr<<((int)(ipa>>8)&0xFF)<<'.';
|
||||
saddr<<((int)ipa&0xFF);
|
||||
if(addr->ia.sin_port>0) saddr<<":"<<ntohs(addr->ia.sin_port);
|
||||
if(displayHex) saddr<<" ("<<hex
|
||||
<<ntohl(addr->ia.sin_addr.s_addr)<<")";
|
||||
if(displayPort) saddr<<":"<<ntohs(addr->ia.sin_port);
|
||||
if(displayHex) saddr<<" ("<<hex<<ntohl(addr->ia.sin_addr.s_addr)
|
||||
<<")";
|
||||
|
||||
return saddr.str();
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ namespace epics {
|
||||
const InetAddrVector* appendList = NULL);
|
||||
|
||||
const String inetAddressToString(const osiSockAddr *addr,
|
||||
bool displayHex = false);
|
||||
bool displayPort = true, bool displayHex = false);
|
||||
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ int main(int argc, char *argv[]) {
|
||||
assert(addr->ia.sin_port==htons(6789));
|
||||
assert(addr->ia.sin_addr.s_addr==htonl(0xAC1037A0));
|
||||
assert(inetAddressToString(addr)=="172.16.55.160:6789");
|
||||
cout<<'\t'<<inetAddressToString(addr, true)<<endl;
|
||||
cout<<'\t'<<inetAddressToString(addr, true)<<endl;
|
||||
|
||||
addr = vec1->at(1);
|
||||
assert(addr->ia.sin_family==AF_INET);
|
||||
@@ -100,13 +100,13 @@ cout<<'\t'<<inetAddressToString(addr, true)<<endl;
|
||||
cout<<"Testing \"intToIPv4Address\""<<endl;
|
||||
addr = intToIPv4Address(0x7F000001);
|
||||
assert(addr->ia.sin_family==AF_INET);
|
||||
assert(inetAddressToString(addr)=="127.0.0.1");
|
||||
assert(inetAddressToString(addr)=="127.0.0.1:0");
|
||||
cout<<'\t'<<inetAddressToString(addr, true)<<endl;
|
||||
delete addr;
|
||||
|
||||
addr = intToIPv4Address(0x0A0A0C0B);
|
||||
assert(addr->ia.sin_family==AF_INET);
|
||||
assert(inetAddressToString(addr)=="10.10.12.11");
|
||||
assert(inetAddressToString(addr)=="10.10.12.11:0");
|
||||
cout<<'\t'<<inetAddressToString(addr, true)<<endl;
|
||||
|
||||
cout<<"\nPASSED!\n";
|
||||
|
||||
Reference in New Issue
Block a user