Codebase list enumiax / d61fba89-98bb-4f5c-a605-cdfaef3c8f2f/main inet_hton.c
d61fba89-98bb-4f5c-a605-cdfaef3c8f2f/main

Tree @d61fba89-98bb-4f5c-a605-cdfaef3c8f2f/main (Download .tar.gz)

inet_hton.c @d61fba89-98bb-4f5c-a605-cdfaef3c8f2f/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;
}