Codebase list enumiax / fe5d1870-32b9-4509-929a-d5a12378f8d7/main inet_hton.c
fe5d1870-32b9-4509-929a-d5a12378f8d7/main

Tree @fe5d1870-32b9-4509-929a-d5a12378f8d7/main (Download .tar.gz)

inet_hton.c @fe5d1870-32b9-4509-929a-d5a12378f8d7/mainraw · history · blame

/*
 * inet_hton.c
 * I)ruid <[email protected]>
 *
 * Function to convert hostname (or IP address) into network byte
 * order.
 *
 */

#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>


uint32_t inet_hton( char *host ) {
	struct in_addr addr;
	struct hostent *h;

	if( (inet_aton( host, &addr )) == 0 ) {
		if( ! (h = gethostbyname( host )) ) {
			perror(host);
			return 0;
		}
		memcpy( &addr, h->h_addr_list[0], sizeof(addr) );
	}
	return addr.s_addr;
}