Codebase list enumiax / 40fa2e26-aa5b-4e44-9c26-e6fd622b9359/main inet_hton.c
40fa2e26-aa5b-4e44-9c26-e6fd622b9359/main

Tree @40fa2e26-aa5b-4e44-9c26-e6fd622b9359/main (Download .tar.gz)

inet_hton.c @40fa2e26-aa5b-4e44-9c26-e6fd622b9359/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;
}