aboutsummaryrefslogtreecommitdiffstats
path: root/xlib.c
diff options
context:
space:
mode:
authorNatanael Copa <natanael.copa@gmail.com>2009-01-29 22:18:47 +0100
committerNatanael Copa <natanael.copa@gmail.com>2009-01-29 22:18:47 +0100
commit0392773d57e3fca5efade2298d641c22202d624a (patch)
tree25d6a21b52a4d4d54aec2ccfe7f132a6af5cd688 /xlib.c
parentc3e110fdff1c977ff8cf2375e48c8a26660d1f3d (diff)
downloadpingu-0392773d57e3fca5efade2298d641c22202d624a.tar.bz2
pingu-0392773d57e3fca5efade2298d641c22202d624a.tar.xz
pingu: make it work
Diffstat (limited to 'xlib.c')
-rw-r--r--xlib.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/xlib.c b/xlib.c
index d8392c1..e48ec39 100644
--- a/xlib.c
+++ b/xlib.c
@@ -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;
+}
+