Mercurial > hg > quicktun
comparison src/common.c @ 64:fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
author | Ivo Smits <Ivo@UFO-Net.nl> |
---|---|
date | Sat, 07 Jan 2017 18:07:27 +0100 |
parents | fa4983c5f7ea |
children | c87212fe8883 |
comparison
equal
deleted
inserted
replaced
63:fa4983c5f7ea | 64:fa53d1c54886 |
---|---|
38 #include <poll.h> | 38 #include <poll.h> |
39 #include <netdb.h> | 39 #include <netdb.h> |
40 #include <stdlib.h> | 40 #include <stdlib.h> |
41 #include <arpa/inet.h> | 41 #include <arpa/inet.h> |
42 #include <net/if.h> | 42 #include <net/if.h> |
43 #include <stdbool.h> | |
43 #ifdef linux | 44 #ifdef linux |
44 #include <linux/if_tun.h> | 45 #include <linux/if_tun.h> |
45 #include <linux/if_ether.h> | 46 #include <linux/if_ether.h> |
46 #else | 47 #else |
47 #define ETH_FRAME_LEN 1514 | 48 #define ETH_FRAME_LEN 1514 |
262 if ((envval = getconf("TUN_UP_SCRIPT"))) system(envval); | 263 if ((envval = getconf("TUN_UP_SCRIPT"))) system(envval); |
263 session->fd_dev = ttfd; | 264 session->fd_dev = ttfd; |
264 return ttfd; | 265 return ttfd; |
265 } | 266 } |
266 | 267 |
267 void hex2bin(unsigned char* dest, const char* src, const int count) { | 268 bool hex2bin(unsigned char* dest, const char* src, const int count) { |
268 int i; | 269 int i; |
269 for (i = 0; i < count; i++) { | 270 for (i = 0; i < count; i++) { |
270 if (*src >= '0' && *src <= '9') *dest = *src - '0'; | 271 if (*src >= '0' && *src <= '9') *dest = *src - '0'; |
271 else if (*src >= 'a' && * src <='f') *dest = *src - 'a' + 10; | 272 else if (*src >= 'a' && * src <='f') *dest = *src - 'a' + 10; |
272 else if (*src >= 'A' && * src <='F') *dest = *src - 'A' + 10; | 273 else if (*src >= 'A' && * src <='F') *dest = *src - 'A' + 10; |
274 else return false; | |
273 src++; *dest = *dest << 4; | 275 src++; *dest = *dest << 4; |
274 if (*src >= '0' && *src <= '9') *dest += *src - '0'; | 276 if (*src >= '0' && *src <= '9') *dest += *src - '0'; |
275 else if (*src >= 'a' && *src <= 'f') *dest += *src - 'a' + 10; | 277 else if (*src >= 'a' && *src <= 'f') *dest += *src - 'a' + 10; |
276 else if (*src >= 'A' && *src <= 'F') *dest += *src - 'A' + 10; | 278 else if (*src >= 'A' && *src <= 'F') *dest += *src - 'A' + 10; |
279 else return false; | |
277 src++; dest++; | 280 src++; dest++; |
278 } | 281 } |
282 return true; | |
279 } | 283 } |
280 | 284 |
281 static int drop_privileges() { | 285 static int drop_privileges() { |
282 char* envval; | 286 char* envval; |
283 struct passwd *pw = NULL; | 287 struct passwd *pw = NULL; |