synk

synchronize files between hosts
Log | Files | Refs | README | LICENSE

commit b90c17add7b3b57172237a1eea69253d90f2407c
parent 82cf376888b0a53cfc1928a739a951bd0fbf30b1
Author: Willy <willyatmailoodotorg>
Date:   Fri Sep  2 18:57:30 +0200

Add function to quickly resolve hostnames to in_addr

Diffstat:
synk.c | 20++++++++++++++++++++
1 file changed, 20 insertions(+), 0 deletions(-)
diff --git a/synk.c b/synk.c @@ -4,6 +4,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <netdb.h> #include <unistd.h> #include <arpa/inet.h> #include <sys/queue.h> @@ -64,6 +65,7 @@ int serverloop(in_addr_t, in_port_t); char *echo(char * []); char **concat(int, ...); +struct in_addr *resolve(char *); struct peer_t *addpeer(struct peers_t *, in_addr_t, in_port_t); long gettimestamp(const char *path); @@ -150,6 +152,24 @@ concat(int n, ...) } /* + * Put an hostname, get an in_addr! + * This is intended to be consumed directly, as gethostbyname() might + * return a pointer to a static buffer + */ +struct in_addr * +resolve(char *hostname) +{ + struct hostent *he; + + if (!(he = gethostbyname(hostname))) { + herror(hostname); + return NULL; + } + + return ((struct in_addr **)he->h_addr_list)[0]; +} + +/* * Returns the UNIX timestamp for the given file, or -1 in case stat(2) * is in error. */