[reSIProcate] I really do believe I found a problem in Resip
Hi,
In relation to a previous post I did last night, I finally traced it down
to the "offending" instruction...
Sometime, before I call and issue the resip Register command,
I call a routine I wrote called...getMyIPAddress
It's supposed to return my local hostname, and return an IP
address as a char * pointing to a dotted IP address.
This is the function....
char * getMyIPAddress(char *myhostname)
{
int result;
struct hostent *myHost;
struct in_addr dstAddr;
char *ip;
result = gethostname(myhostname, 100);
if (result == -1)
return NULL;
myHost = malloc(sizeof (struct hostent));
myHost = gethostbyname(myhostname); <---- I call this, it
breaks resip
memcpy((char *) &dstAddr, myHost->h_addr_list[0], myHost->h_length);
ip = inet_ntoa(dstAddr);
free(myHost);
return(ip);
}
Note the <---- above
If I comment this statement out, resip works great. But when I leave
it in, I get
a crash in DnsUtil.cxx...
Data
DnsUtil::getLocalHostName()
{
char buffer[MAXHOSTNAMELEN];
if (int e = gethostname(buffer,sizeof(buffer)) == -1)
{
if ( e != 0 )
{
int err = getErrno();
switch (err)
{
case WSANOTINITIALISED:
CritLog( << "could not find local hostname because
netwrok not initialized:" << strerror(err) );
break;
default:
CritLog( << "could not find local hostname:" <<
strerror(err) );
break;
}
throw Exception("could not find local hostname",__FILE__,__LINE__);
}
}
struct hostent* he;
if ((he = gethostbyname(buffer)) != NULL) { <---- when I get
here....
if (strchr(he->h_name, '.') != NULL) {
strncpy(buffer, he->h_name, sizeof(buffer));
}
else {
WarningLog( << "local hostname does not contain a domain part");
}
}
return Data(buffer);
}
So, long after I call MY GetMyIPAddress routine you see above, when I get
to the indicated function above, I get the following in my error logs...
resiprocate/dum/UserProfile.cxx:91 | Adding credential:
realm=213.167.79.25 user=u354
Current language: auto; currently objective-c++
*** malloc[3178]: Deallocation of a pointer not malloced: 0xa01c05f4;
This could be a double free(), or free() called with the middle of an
allocated block; Try setting environment variable MallocHelp to see
tools to help debug
*** malloc[3178]: Deallocation of a pointer not malloced: 0x809e017c;
This could be a double free(), or free() called with the middle of an
allocated block; Try setting environment variable MallocHelp to see
tools to help debug
*** malloc[3178]: Deallocation of a pointer not malloced: 0x7c050378;
This could be a double free(), or free() called with the middle of an
allocated block; Try setting environment variable MallocHelp to see
tools to help debug
when I stop the program, it always stops at the above indicated
function....
Ok, so next I put a breakpoint at that function, run it until I break
there, then
single step past the "gethostbyname" function above, I get the output
you see above.
Next, I commented out MY call to "gethostbyname" and resip works just
fine...
Can someone shed some light on this... perhaps someone could try
calling that
function before registering and see if they get the same results...
I'm already aware my "getMyIPAddress" will ONLY work on a machine with a
single network device on it. And they also mentioned it in the header file
of DnsUtil.h...
// Note that this will not work on systems with more than one ethernet
// interface. You are advised to use getInterfaces instead in those
// cases.
static Data getLocalIpAddress(const Data&
defaultInterface=Data::Empty) ;
As an updated version of this function been submitted to the project?
I can get along with using a single device for now, until I get the rest
of the SIP phone working, but is someone going to eventually address
this issue?
Now, I don't really need to use my "offending" routine above if I can
somehow get the resip stack to return my IP address. I would
assume I could call some method after calling...
clientDum->addTransport(UDP, 5060);
Is that right?
have I made an error in the way I coded the "getMyIPAddress"
above..... Does the "gethostbyname" try and free the "myhostname"
pointer (which I allocate prior to calling this function).
In the statement...
ip = inet_ntoa(dstAddr);
This returns a "char *" - Am I to assume this has been allocated by the
inet_ntoa
function above???
John