[OPEN-ILS-DEV] transport_session.c: use of $HOSTNAME

Scott McKellar mck9 at swbell.net
Sat Mar 1 22:27:55 EST 2008


In session_connect() we have have the following fragment:

    /* the first Jabber connect stanza */
    char* our_hostname = getenv("HOSTNAME");
    size1 = 150 + strlen( server );
    char stanza1[ size1 ]; 
    snprintf( stanza1, sizeof(stanza1),
        "<long message abbreviated here> %s %s",
        username, our_hostname );

My first observation is that in calculating size1 we presumably should
have used strlen(our_hostname), not strlen(server), since server is
not included in the formatted stanza that we build.

I could fix that myself.  But what I'm writing about is the use of
the environmental variable $HOSTNAME.

Is there a reason why we don't get the host name by calling
gethostname()?

Normally the two methods will yield the same result.  The difference
is that the user can change the value of $HOSTNAME to anything he
likes, or even unset it entirely.  The resulting stanza that we
build here will then be different accordingly.  But gethostname() is
not affected by changes in $HOSTNAME, as I confirmed by a little
experimentation.

Unless we want the user to be able to change the contents of this
stanza, I suggest that we use gethostname().  Give me the go-ahead
and I'll prepare a patch to do so.

Scott McKellar
http://home.swbell.net/mck9/ct/



More information about the Open-ils-dev mailing list