comparison 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
comparison
equal deleted inserted replaced
51:d83d6bb647a2 52:3115f8af98bb
98 98
99 int errorexit(const char* text) { 99 int errorexit(const char* text) {
100 fprintf(stderr, "%s\n", text); 100 fprintf(stderr, "%s\n", text);
101 return -1; 101 return -1;
102 } 102 }
103 int errorexit2(const char* text, const char* error) {
104 fprintf(stderr, "%s: %s\n", text, error);
105 return -1;
106 }
103 int errorexitp(const char* text) { 107 int errorexitp(const char* text) {
104 perror(text); 108 perror(text);
105 return -1; 109 return -1;
106 } 110 }
107 111
154 static int init_udp(struct qtsession* session) { 158 static int init_udp(struct qtsession* session) {
155 char* envval; 159 char* envval;
156 fprintf(stderr, "Initializing UDP socket...\n"); 160 fprintf(stderr, "Initializing UDP socket...\n");
157 struct addrinfo *ai_local = NULL, *ai_remote = NULL; 161 struct addrinfo *ai_local = NULL, *ai_remote = NULL;
158 unsigned short af = 0; 162 unsigned short af = 0;
163 int ret;
159 if (envval = getconf("LOCAL_ADDRESS")) { 164 if (envval = getconf("LOCAL_ADDRESS")) {
160 if (getaddrinfo(envval, NULL, NULL, &ai_local)) return errorexitp("getaddrinfo(LOCAL_ADDRESS)"); 165 if (ret = getaddrinfo(envval, NULL, NULL, &ai_local)) return errorexit2("getaddrinfo(LOCAL_ADDRESS)", gai_strerror(ret));
161 if (!ai_local) return errorexit("LOCAL_ADDRESS lookup failed"); 166 if (!ai_local) return errorexit("LOCAL_ADDRESS lookup failed");
162 if (ai_local->ai_addrlen > sizeof(sockaddr_any)) return errorexit("Resolved LOCAL_ADDRESS is too big"); 167 if (ai_local->ai_addrlen > sizeof(sockaddr_any)) return errorexit("Resolved LOCAL_ADDRESS is too big");
163 af = ai_local->ai_family; 168 af = ai_local->ai_family;
164 } 169 }
165 if (envval = getconf("REMOTE_ADDRESS")) { 170 if (envval = getconf("REMOTE_ADDRESS")) {
166 if (getaddrinfo(envval, NULL, NULL, &ai_remote)) return errorexitp("getaddrinfo(REMOTE_ADDRESS)"); 171 if (ret = getaddrinfo(envval, NULL, NULL, &ai_remote)) return errorexit2("getaddrinfo(REMOTE_ADDRESS)", gai_strerror(ret));
167 if (!ai_remote) return errorexit("REMOTE_ADDRESS lookup failed"); 172 if (!ai_remote) return errorexit("REMOTE_ADDRESS lookup failed");
168 if (ai_remote->ai_addrlen > sizeof(sockaddr_any)) return errorexit("Resolved REMOTE_ADDRESS is too big"); 173 if (ai_remote->ai_addrlen > sizeof(sockaddr_any)) return errorexit("Resolved REMOTE_ADDRESS is too big");
169 if (af && af != ai_remote->ai_family) return errorexit("Address families do not match"); 174 if (af && af != ai_remote->ai_family) return errorexit("Address families do not match");
170 af = ai_remote->ai_family; 175 af = ai_remote->ai_family;
171 } 176 }
377 else if (ipver == 6) pihdr = 0x0000 | (0xdd86 << 16); 382 else if (ipver == 6) pihdr = 0x0000 | (0xdd86 << 16);
378 #else 383 #else
379 if (ipver == 4) pihdr = htonl(AF_INET); 384 if (ipver == 4) pihdr = htonl(AF_INET);
380 else if (ipver == 6) pihdr = htonl(AF_INET6); 385 else if (ipver == 6) pihdr = htonl(AF_INET6);
381 #endif 386 #endif
382 *(int*)(buffer_raw + p->offset_raw) = ipver; 387 *(int*)(buffer_raw + p->offset_raw) = pihdr;
383 } 388 }
384 if (len > 0) write(ttfd, buffer_raw + p->offset_raw, len + pi_length); 389 if (len > 0) write(ttfd, buffer_raw + p->offset_raw, len + pi_length);
385 } 390 }
386 } 391 }
387 } 392 }