r3140 - trunk/libmnetutil/source
erik at minisip.org
erik at minisip.org
Mon Jan 22 18:25:45 CET 2007
Author: erik
Date: 2007-01-22 18:25:44 +0100 (Mon, 22 Jan 2007)
New Revision: 3140
Modified:
trunk/libmnetutil/source/IP4Address.cxx
trunk/libmnetutil/source/IP6Address.cxx
Log:
* Undo commit 3139.
In a weak moment I confused thread-safe with reentrant or something
like that. We copy the data out of the result of gethostbyname
directly and therefore it does not matter that they are
not re-entrant.
Modified: trunk/libmnetutil/source/IP4Address.cxx
===================================================================
--- trunk/libmnetutil/source/IP4Address.cxx 2007-01-22 16:06:22 UTC (rev 3139)
+++ trunk/libmnetutil/source/IP4Address.cxx 2007-01-22 17:25:44 UTC (rev 3140)
@@ -89,7 +89,6 @@
setAddressFamily(AF_INET);
setProtocolFamily(PF_INET);
struct in_addr ip_data;
- char *auxbuf=NULL;
if (inet_aton(addr.c_str(),&ip_data)){
numIp = ntoh32(ip_data.s_addr);
}else{
@@ -97,35 +96,7 @@
//unsigned char *ip;
#ifndef WIN32
-//Non-reentrant version:
-// struct hostent *hp= gethostbyname2(ipaddr.c_str(), AF_INET);
-
- struct hostent *hp;
- struct hostent hbuf;
- size_t buflen=1024;
-
- auxbuf = (char*)malloc(1024);
-
- int herr;
- int res;
- while ((res=gethostbyname2_r(ipaddr.c_str(),
- AF_INET,
- &hbuf,
- auxbuf,
- buflen,
- &hp,
- &herr
- ))==ERANGE){
- buflen*=2;
- auxbuf=(char*)realloc(auxbuf,buflen);
- }
-
- if (res!=0 || hp==NULL){
- free(auxbuf);
- throw ResolvError( herr );
- }
-
-
+ struct hostent *hp= gethostbyname2(ipaddr.c_str(), AF_INET);
#else
struct hostent *hp= gethostbyname(ipaddr.c_str());
// struct hostent *hp= gethostbyaddr(ipaddr.c_str(), 4, AF_INET);
@@ -153,9 +124,6 @@
sockaddress->sin_family=AF_INET;
sockaddress->sin_addr.s_addr = hton32(numIp);
sockaddress->sin_port=0;
-
- if (auxbuf)
- free(auxbuf);
}
IP4Address::IP4Address(const IP4Address& other){
Modified: trunk/libmnetutil/source/IP6Address.cxx
===================================================================
--- trunk/libmnetutil/source/IP6Address.cxx 2007-01-22 16:06:22 UTC (rev 3139)
+++ trunk/libmnetutil/source/IP6Address.cxx 2007-01-22 17:25:44 UTC (rev 3140)
@@ -114,32 +114,7 @@
setAddressFamily(AF_INET6);
setProtocolFamily(PF_INET6);
#ifndef WIN32
-// hostent *hp= gethostbyname2(addr.c_str(), AF_INET6);
- struct hostent *hp;
- struct hostent hbuf;
- size_t buflen=1024;
-
- char *auxbuf = (char*)malloc(1024);
-
- int herr;
- int res;
- while ((res=gethostbyname2_r(addr.c_str(),
- AF_INET,
- &hbuf,
- auxbuf,
- buflen,
- &hp,
- &herr
- ))==ERANGE){
- buflen*=2;
- auxbuf=(char*)realloc(auxbuf,buflen);
- }
-
- if (res!=0 || hp==NULL){
- free(auxbuf);
- throw ResolvError( herr );
- }
-
+ hostent *hp= gethostbyname2(addr.c_str(), AF_INET6);
#else
hostent *hp= gethostbyname(addr.c_str());
#endif
@@ -162,10 +137,6 @@
memcpy(&sockaddress->sin6_addr,hp->h_addr, hp->h_length);
ipaddr = buildAddressString((struct sockaddr*)sockaddress, sizeof(struct sockaddr_in6));
-
-#ifndef WIN32
- free(auxbuf);
-#endif
}
IP6Address::IP6Address(struct sockaddr_in6 * addr){
More information about the Minisip-devel
mailing list