Taken from the original at http://www.ecst.csuchico.edu/~beej/guide/net/ ... see end of writeup for Copyright statement.
gethostname()--Who am I?
Even easier than getpeername() is the function gethostname(). It returns the name
of the computer that your program is running on. The name can then be used by gethostbyname(), below, to determine the IP address
of your local machine.
What could be more fun? I could think of a few things, but they don't pertain to socket programming. Anyway, here's the breakdown:
int gethostname(char *hostname, size_t size);
The arguments are simple: hostname is a pointer to an array of chars that will contain the hostname upon the function's return, and size is the length in bytes of the hostname array.
The function returns 0 on successful completion, and -1 on error, setting errno as usual.
Prev | Up | Next
Copyright © 1995, 1996 by Brian "Beej" Hall. This guide may be reprinted in any medium provided that its content is not altered, it is presented in its entirety, and this copyright notice remains intact. Contact firstname.lastname@example.org for more information.