< Previous by Date Date Index Next by Date >
< Previous in Thread Thread Index Next in Thread >

RE: [reSIProcate] Memory Leaks


These two functions perform different tasks.  The output from the first
is passed to the 2nd.

The gethostname() function returns the standard host name for the
current machine.  I'm pretty sure this hostname does not contain any
domain, ie. just machine name.
The gethostbyname function retrieves host information corresponding to a
host name from a host database.  The host information structure contains
the FQDN version of the hostname.

I don't think there are any bugs with this.

Scott


> -----Original Message-----
> From: resiprocate-devel-bounces@xxxxxxxxxxxxxxxxxxx
[mailto:resiprocate-
> devel-bounces@xxxxxxxxxxxxxxxxxxx] On Behalf Of Bayart, Frederik
> Sent: Friday, February 03, 2006 5:52 AM
> To: resiprocate-devel@xxxxxxxxxxxxxxxxxxx
> Subject: RE: [reSIProcate] Memory Leaks
> 
> Hi,
> 
> I was looking at a fragment of the source code of DnsUtil which you
find
> below. The getLocalHostName is looking 2x for the hostname, 1x by
calling
> gethostname and 1x by calling gethostbyname. In the past, it was only
> gethostname. To me, it seems that someone wanted to replace the call
to
> gethostname  by gethostbyname but forgot remove the first call. Can
> someone have a look at it ?
> 
> Frederik
> 
> 
> DnsUtil::getLocalHostName()
> {
>    char buffer[MAXHOSTNAMELEN];
>    buffer[0] = '\0';
>    if (int e = gethostname(buffer,sizeof(buffer)) == -1)
>    {
>       if ( e != 0 )
>       {
>          int err = getErrno();
>          switch (err)
>          {
> // !RjS! This makes no sense for non-windows. The
> //       current hack (see the #define in .hxx) needs
> //       to be reworked.
>             case WSANOTINITIALISED:
>                CritLog( << "could not find local hostname because
network
> 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)) != 0)
>    {
>       if (strchr(he->h_name, '.') != 0)
>       {
>          strncpy(buffer, he->h_name, sizeof(buffer));
>       }
>       else
>       {
>          WarningLog( << "local hostname does not contain a domain
part");
>       }
>    }
> 
>    return Data(buffer);
> }
> _______________________________________________
> resiprocate-devel mailing list
> resiprocate-devel@xxxxxxxxxxxxxxxxxxx
> https://list.sipfoundry.org/mailman/listinfo/resiprocate-devel