diff options
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; +} + |