diff src/common.c @ 52:3115f8af98bb V2.2.2

Added support for libsodium, fixed bug in USE_PI compatibility mode, improved timestamp checking in nacltai protocol
author Ivo Smits <Ivo@UCIS.nl>
date Sun, 27 Oct 2013 23:10:43 +0100
parents b4de2326e9f7
children 4ff8003d0973
line wrap: on
line diff
--- a/src/common.c	Mon Jun 03 01:01:22 2013 +0200
+++ b/src/common.c	Sun Oct 27 23:10:43 2013 +0100
@@ -100,6 +100,10 @@
 	fprintf(stderr, "%s\n", text);
 	return -1;
 }
+int errorexit2(const char* text, const char* error) {
+	fprintf(stderr, "%s: %s\n", text, error);
+	return -1;
+}
 int errorexitp(const char* text) {
 	perror(text);
 	return -1;
@@ -156,14 +160,15 @@
 	fprintf(stderr, "Initializing UDP socket...\n");
 	struct addrinfo *ai_local = NULL, *ai_remote = NULL;
 	unsigned short af = 0;
+	int ret;
 	if (envval = getconf("LOCAL_ADDRESS")) {
-		if (getaddrinfo(envval, NULL, NULL, &ai_local)) return errorexitp("getaddrinfo(LOCAL_ADDRESS)");
+		if (ret = getaddrinfo(envval, NULL, NULL, &ai_local)) return errorexit2("getaddrinfo(LOCAL_ADDRESS)", gai_strerror(ret));
 		if (!ai_local) return errorexit("LOCAL_ADDRESS lookup failed");
 		if (ai_local->ai_addrlen > sizeof(sockaddr_any)) return errorexit("Resolved LOCAL_ADDRESS is too big");
 		af = ai_local->ai_family;
 	}
 	if (envval = getconf("REMOTE_ADDRESS")) {
-		if (getaddrinfo(envval, NULL, NULL, &ai_remote)) return errorexitp("getaddrinfo(REMOTE_ADDRESS)");
+		if (ret = getaddrinfo(envval, NULL, NULL, &ai_remote)) return errorexit2("getaddrinfo(REMOTE_ADDRESS)", gai_strerror(ret));
 		if (!ai_remote) return errorexit("REMOTE_ADDRESS lookup failed");
 		if (ai_remote->ai_addrlen > sizeof(sockaddr_any)) return errorexit("Resolved REMOTE_ADDRESS is too big");
 		if (af && af != ai_remote->ai_family) return errorexit("Address families do not match");
@@ -379,7 +384,7 @@
 					if (ipver == 4) pihdr = htonl(AF_INET);
 					else if (ipver == 6) pihdr = htonl(AF_INET6);
 #endif
-					*(int*)(buffer_raw + p->offset_raw) = ipver;
+					*(int*)(buffer_raw + p->offset_raw) = pihdr;
 				}
 				if (len > 0) write(ttfd, buffer_raw + p->offset_raw, len + pi_length);
 			}