Sender: nate AT cartsys DOT com Message-ID: <35CA4951.D1931D5A@cartsys.com> Date: Thu, 06 Aug 1998 17:24:49 -0700 From: Nate Eldredge MIME-Version: 1.0 To: Michiel Uitdehaag CC: djgpp AT delorie DOT com Subject: Re: libsocket resit demo References: <35C9D278 DOT E1889095 AT imn DOT nl> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Precedence: bulk Michiel Uitdehaag wrote: > > Hi, > > I installed the Libsocket TCP library yesterday (from the > http://www.geocities.com/SiliconValley/Lab/3216/lsck.htm libsocket > pages) and noticed the resit demo crashing every time. > So, being the newbie I am and investigating the c code, I found this: > (resit.c) > > int main (int argc, char *argv[]) > { > struct hostent *hpke; > char *x; > > ... (snip) > > printf ("Aliases: "); > while ( *(hpke->h_aliases ) ) { > printf ("%s ", *hpke->h_aliases ); <-----------Here > hpke->h_aliases ++; > } > > ... > > as hpke is already a pointer, *hpke would dereference it, and force the > program to use the value at (*hpke) as a pointer to h_aliases, or am I > gravely mistaking here? > Shouldn't the correct code be: > > printf ("Aliases: "); > while ( *(hpke->h_aliases ) ) { > printf ("%s ", hpke->h_aliases ); > hpke->h_aliases ++; > } Nope. If the definition of `struct hostent' is the same as on Unix, it looks like: struct hostent { char *h_name; /* official name of host */ char **h_aliases; /* alias list */ int h_addrtype; /* host address type */ int h_length; /* length of address */ char **h_addr_list; /* list of addresses */ }; So the h.aliases member is what is often called a vector; an array of pointers to strings, terminated by NULL. A diagram: h.aliases --> h.aliases[0] --> "First alias" h.aliases[1] --> "Second alias" ... NULL And since `->' binds more tightly than `*', that code will indeed walk through the array of aliases, printing each one. Thus, the bug is somewhere else. -- Nate Eldredge nate AT cartsys DOT com