|
| iMatix home page | << | < | > | >> |
SFLVersion 2.11 |
#include "sflsock.h" qbyte * get_hostaddrs (void)
Returns a table of all host IP addresses. The table ends in a zero address. Each address is a 4-byte value in host format. Returns NULL if there was an error. If sockets are not supported, returns a table with the loopback address (127.0.0.1) and a null address. The caller must free the table using mem_free() when finished using it.
{
#if (defined (DOES_SOCKETS))
int
addr_count; /* How many addresses do we have */
qbyte
*addr_table; /* Where we store the addresses */
struct hostent
*phe; /* Host information entry */
if ((phe = gethostbyname (get hostname ())) == NULL)
return (NULL);
/* Count the addresses */
for (addr_count = 0; phe-> h_addr_list [addr_count]; addr_count++);
/* Allocate a table; socket addresses are 4 bytes */
addr_table = mem_alloc (4 * (addr_count + 1));
/* Store the addresses */
for (addr_count = 0; phe-> h_addr_list [addr_count]; addr_count++)
addr_table [addr_count]
= *(qbyte *) (phe-> h_addr_list [addr_count]);
addr_table [addr_count] = 0;
return (addr_table);
#else
qbyte
*addr_table; /* Where we store the addresses */
addr_table = mem_alloc (8); /* Addresses are 4 bytes */
addr_table [0] = htonl (SOCKET_LOOPBACK);
addr_table [1] = 0;
return (addr_table);
#endif
}
| | << | < | > | >> |
|