inetAddressUtil no more new vector
no more allocating vector.
This commit is contained in:
@@ -34,8 +34,10 @@ void addDefaultBroadcastAddress(InetAddrVector* v, unsigned short p) {
|
||||
v->push_back(pNewNode);
|
||||
}
|
||||
|
||||
InetAddrVector* getBroadcastAddresses(SOCKET sock,
|
||||
unsigned short defaultPort) {
|
||||
void getBroadcastAddresses(InetAddrVector& ret,
|
||||
SOCKET sock,
|
||||
unsigned short defaultPort) {
|
||||
ret.clear();
|
||||
ELLLIST as;
|
||||
ellInit(&as);
|
||||
osiSockAddr serverAddr;
|
||||
@@ -47,13 +49,12 @@ InetAddrVector* getBroadcastAddresses(SOCKET sock,
|
||||
osiSockAddrNode * sn = (osiSockAddrNode *)n;
|
||||
sn->addr.ia.sin_port = htons(defaultPort);
|
||||
// TODO discover possible duplicates
|
||||
v->push_back(sn->addr);
|
||||
ret.push_back(sn->addr);
|
||||
}
|
||||
ellFree(&as);
|
||||
// add fallback address
|
||||
if (!v->size())
|
||||
if (!ret.size())
|
||||
addDefaultBroadcastAddress(v, defaultPort);
|
||||
return v;
|
||||
}
|
||||
|
||||
void encodeAsIPv6Address(ByteBuffer* buffer, const osiSockAddr* address) {
|
||||
@@ -101,13 +102,10 @@ bool isMulticastAddress(const osiSockAddr* address) {
|
||||
return msB >= 224 && msB <= 239;
|
||||
}
|
||||
|
||||
osiSockAddr* intToIPv4Address(int32 addr) {
|
||||
osiSockAddr* ret = new osiSockAddr;
|
||||
ret->ia.sin_family = AF_INET;
|
||||
ret->ia.sin_addr.s_addr = htonl(addr);
|
||||
ret->ia.sin_port = 0;
|
||||
|
||||
return ret;
|
||||
void intToIPv4Address(osiSockAddr& ret, int32 addr) {
|
||||
ret.ia.sin_family = AF_INET;
|
||||
ret.ia.sin_addr.s_addr = htonl(addr);
|
||||
ret.ia.sin_port = 0;
|
||||
}
|
||||
|
||||
int32 ipv4AddressToInt(const osiSockAddr& addr) {
|
||||
@@ -148,9 +146,10 @@ int32 parseInetAddress(const string & addr) {
|
||||
return htonl(retAddr);
|
||||
}
|
||||
|
||||
InetAddrVector* getSocketAddressList(const std::string & list, int defaultPort,
|
||||
void getSocketAddressList(InetAddrVector& ret,
|
||||
const std::string & list, int defaultPort,
|
||||
const InetAddrVector* appendList) {
|
||||
InetAddrVector* iav = new InetAddrVector();
|
||||
ret.clear();
|
||||
|
||||
// skip leading spaces
|
||||
size_t len = list.length();
|
||||
@@ -164,21 +163,20 @@ InetAddrVector* getSocketAddressList(const std::string & list, int defaultPort,
|
||||
string address = list.substr(subStart, (subEnd-subStart));
|
||||
osiSockAddr addr;
|
||||
if (aToIPAddr(address.c_str(), defaultPort, &addr.ia) == 0)
|
||||
iav->push_back(addr);
|
||||
ret.push_back(addr);
|
||||
subStart = list.find_first_not_of(" \t\r\n\v", subEnd);
|
||||
}
|
||||
|
||||
if(subStart!=std::string::npos && subStart<len) {
|
||||
osiSockAddr addr;
|
||||
if (aToIPAddr(list.substr(subStart).c_str(), defaultPort, &addr.ia) == 0)
|
||||
iav->push_back(addr);
|
||||
ret.push_back(addr);
|
||||
}
|
||||
|
||||
if(appendList!=NULL) {
|
||||
for(size_t i = 0; i<appendList->size(); i++)
|
||||
iav->push_back((*appendList)[i]);
|
||||
ret.push_back((*appendList)[i]);
|
||||
}
|
||||
return iav;
|
||||
}
|
||||
|
||||
string inetAddressToString(const osiSockAddr &addr,
|
||||
|
||||
Reference in New Issue
Block a user