diff options
author | Natanael Copa <natanael.copa@gmail.com> | 2009-01-29 22:18:47 +0100 |
---|---|---|
committer | Natanael Copa <natanael.copa@gmail.com> | 2009-01-29 22:18:47 +0100 |
commit | 0392773d57e3fca5efade2298d641c22202d624a (patch) | |
tree | 25d6a21b52a4d4d54aec2ccfe7f132a6af5cd688 /xlib.c | |
parent | c3e110fdff1c977ff8cf2375e48c8a26660d1f3d (diff) | |
download | pingu-0392773d57e3fca5efade2298d641c22202d624a.tar.bz2 pingu-0392773d57e3fca5efade2298d641c22202d624a.tar.xz |
pingu: make it work
Diffstat (limited to 'xlib.c')
-rw-r--r-- | xlib.c | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -1,4 +1,9 @@ +#include <arpa/inet.h> +#include <netinet/in.h> +#include <sys/socket.h> + +#include <netdb.h> #include <stdlib.h> #include <string.h> #include <unistd.h> @@ -29,3 +34,17 @@ char *xstrdup(const char *str) return s; } +int init_sockaddr(struct sockaddr_in *addr, const char *host) +{ + memset((char *) addr, 0, sizeof(struct sockaddr_in)); + addr->sin_family = AF_INET; + if (inet_aton(host, &addr->sin_addr) == 0) { + struct hostent *hp; + hp = gethostbyname(host); + if (!hp) + return -1; + memcpy(&addr->sin_addr, hp->h_addr, 4); + } + return 0; +} + |