[PATCH:xscope 06/14] Ensure ScopeHost global is initialized when built with USE_XTRANS

Jeremy Huddleston jeremyhu at apple.com
Sun Sep 25 00:07:47 PDT 2011


On Sep 24, 2011, at 21:22, Alan Coopersmith wrote:

> It's gethostname, no "by", to get the name of the current host.

You're using gethostbyname here:

>> +    struct hostent *hp = gethostbyname(MyHostName);

> IPv6 support is provided for xscope by the xtrans code, and I
> believe fully works already (I haven't actually tested in a while).

The gethostbyname(MyHostName) will fail for POSIX conforming gethostbyname(3) if gethostname(3) returns a hostname which NXDOMAINs the A lookup.  This will happen if the system has no IPv4 stack (thus no IPv4 loopback to resolve to) and has a POSIX conforming gethostbyname(3) (ie not glibc or its unfortunate relatives).

> 
> 	-alan-
> 
> On 09/24/11 12:43 PM, Jeremy Huddleston wrote:
>> Can we use this opportunity to use getaddrinfo(3) rather than gethostbyname(3) as it is the preferred API and will make xscope IPv6 compatible.
>> 
>> On Sep 24, 2011, at 08:48, Alan Coopersmith wrote:
>> 
>>> Signed-off-by: Alan Coopersmith<alan.coopersmith at oracle.com>
>>> ---
>>> common.c |   15 +++++++--------
>>> 1 files changed, 7 insertions(+), 8 deletions(-)
>>> 
>>> diff --git a/common.c b/common.c
>>> index 42220cd..3779b13 100644
>>> --- a/common.c
>>> +++ b/common.c
>>> @@ -200,9 +200,15 @@ SetUpConnectionSocket(
>>>   struct linger linger;
>>> #endif /* SO_DONTLINGER */
>>> #endif
>>> +  char    MyHostName[256];
>>> 
>>>   enterprocedure("SetUpConnectionSocket");
>>> 
>>> +  (void) gethostname(MyHostName, sizeof(MyHostName));
>>> +  ScopeHost = strdup(MyHostName);
>>> +  if (ScopeHost == NULL)
>>> +    panic("Can't allocate memory for hostname");
>>> +
>>> #ifdef USE_XTRANS
>>>   ScopePort = iport - ServerBasePort;
>>>   sprintf (port, "%d", ScopePort);
>>> @@ -258,14 +264,7 @@ SetUpConnectionSocket(
>>>    */
>>>   {
>>>     /* define the host part of the address */
>>> -    char    MyHostName[256];
>>> -    struct hostent *hp;
>>> -
>>> -    (void) gethostname(MyHostName, sizeof(MyHostName));
>>> -    ScopeHost = strdup(MyHostName);
>>> -    if (ScopeHost == NULL)
>>> -      panic("Can't allocate memory for hostname");
>>> -    hp = gethostbyname(MyHostName);
>>> +    struct hostent *hp = gethostbyname(MyHostName);
>>>     if (hp == NULL)
>>>       panic("No address for our host");
>>>     bcopy((char *)hp->h_addr, (char*)&sin.sin_addr, hp->h_length);
>>> --
>>> 1.7.3.2
>>> 
>>> _______________________________________________
>>> xorg-devel at lists.x.org: X.Org development
>>> Archives: http://lists.x.org/archives/xorg-devel
>>> Info: http://lists.x.org/mailman/listinfo/xorg-devel
>>> 
>> 
> 
> 
> -- 
> 	-Alan Coopersmith-        alan.coopersmith at oracle.com
> 	 Oracle Solaris Platform Engineering: X Window System
> 
> _______________________________________________
> xorg-devel at lists.x.org: X.Org development
> Archives: http://lists.x.org/archives/xorg-devel
> Info: http://lists.x.org/mailman/listinfo/xorg-devel
> 



More information about the xorg-devel mailing list