[bedevtalk] Socket netwwork in Bone
Philippe Houdoin
philippe.houdoin at free.fr
Thu Mar 9 07:36:06 BRT 2006
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
More information about the bedevtalk
mailing list