[bedevtalk] Socket netwwork in Bone

fredrik fredrik.moden at telia.com
Thu Mar 9 13:18:11 BRT 2006


Ok Have tested this but gethostname does not work ether :(


//Fredrik
> -----Original Message-----
> From: bedevtalk-bounces at bug-br.org.br [mailto:bedevtalk-bounces at bug-
> br.org.br] On Behalf Of Philippe Houdoin
> Sent: den 9 mars 2006 11:36
> To: bedevtalk at bug-br.org.br
> Subject: Re: [bedevtalk] Socket netwwork in Bone
> 
> Quoting Fredrik Modéen:
> 
> > /*A typical use of gethostname() is to follow the call with
> > gethostbyname() in order to retrieve the address of the local host*/
> >
> > This does not work, Is there some other way to get my adress as a long?
> >
> > this are also not working as gethostaddr are not found in socket.h and
> > INADDR_ANY are 0.
> > "
> > if ((host_addr = (ulong)gethostaddr()) == -1)
> > {
> > host_addr = INADDR_ANY;
> > }
> > "
> >
> > (http://yellowtab.com/develop/dev_docs/html_public/NetworkSockets.html)
> 
> That's because gethostaddr() is not provided by the API but a _fictionnal_
> function in their sample code context.
> Here a possible implementation taken from an older BeBook:
> 
> #include <netdb.h>
> 
> /* To fill a need, we invent the gethostaddr() function. */
> long gethostaddr(void)
> {
>   struct hostent *host_ent;
>   char host_name[MAXHOSTNAMELEN];
> 
>   if (gethostname(host_name, MAXHOSTNAMELEN) == 0) {
>     return -1;
>   }
> 
>   if ((host_ent = gethostbyname(host_name)) == NULL) {
>     return -1;
>   }
> 
>   return *(long *)host_ent.h_addr;
> }
> 
> Regards,
> 
> - Philippe
> _______________________________________________
> bedevtalk mailing list
> bedevtalk at bug-br.org.br
> http://www.bug-br.org.br/mailman/listinfo/bedevtalk





More information about the bedevtalk mailing list