diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-12-16 11:19:15 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-12-16 11:19:15 +0000 |
commit | 1ff3c89a1a0eb49baee9c80b2a1043aefd2bf201 (patch) | |
tree | 4ed8ce56f9a9561bf4b32e16cefe5ac90ddfd8c5 /src/nat/gnunet-helper-nat-client.c | |
parent | ac109f65ead8ae7aa01a99b100bebfac39d25ffa (diff) | |
download | gnunet-1ff3c89a1a0eb49baee9c80b2a1043aefd2bf201.tar.gz gnunet-1ff3c89a1a0eb49baee9c80b2a1043aefd2bf201.zip |
additional stylistic changes to gnunet-helper-nat-client anticipating next round of suggestions from Jacob Applebaum
Diffstat (limited to 'src/nat/gnunet-helper-nat-client.c')
-rw-r--r-- | src/nat/gnunet-helper-nat-client.c | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/src/nat/gnunet-helper-nat-client.c b/src/nat/gnunet-helper-nat-client.c index fbebdbc0f..f30348cc4 100644 --- a/src/nat/gnunet-helper-nat-client.c +++ b/src/nat/gnunet-helper-nat-client.c | |||
@@ -69,6 +69,11 @@ | |||
69 | #define NAT_TRAV_PORT 22225 | 69 | #define NAT_TRAV_PORT 22225 |
70 | 70 | ||
71 | /** | 71 | /** |
72 | * Must match packet ID used by gnunet-helper-nat-server.c | ||
73 | */ | ||
74 | #define PACKET_ID 256 | ||
75 | |||
76 | /** | ||
72 | * IPv4 header. | 77 | * IPv4 header. |
73 | */ | 78 | */ |
74 | struct ip_header | 79 | struct ip_header |
@@ -228,7 +233,7 @@ send_icmp_udp (const struct in_addr *my_ip, const struct in_addr *other) | |||
228 | ip_pkt.vers_ihl = 0x45; | 233 | ip_pkt.vers_ihl = 0x45; |
229 | ip_pkt.tos = 0; | 234 | ip_pkt.tos = 0; |
230 | ip_pkt.pkt_len = htons (sizeof (packet)); | 235 | ip_pkt.pkt_len = htons (sizeof (packet)); |
231 | ip_pkt.id = htons (256); | 236 | ip_pkt.id = htons (PACKET_ID); |
232 | ip_pkt.flags_frag_offset = 0; | 237 | ip_pkt.flags_frag_offset = 0; |
233 | ip_pkt.ttl = 128; | 238 | ip_pkt.ttl = 128; |
234 | ip_pkt.proto = IPPROTO_ICMP; | 239 | ip_pkt.proto = IPPROTO_ICMP; |
@@ -325,7 +330,7 @@ send_icmp (const struct in_addr *my_ip, const struct in_addr *other) | |||
325 | ip_pkt.vers_ihl = 0x45; | 330 | ip_pkt.vers_ihl = 0x45; |
326 | ip_pkt.tos = 0; | 331 | ip_pkt.tos = 0; |
327 | ip_pkt.pkt_len = htons (sizeof (packet)); | 332 | ip_pkt.pkt_len = htons (sizeof (packet)); |
328 | ip_pkt.id = htons (256); | 333 | ip_pkt.id = htons (PACKET_ID); |
329 | ip_pkt.flags_frag_offset = 0; | 334 | ip_pkt.flags_frag_offset = 0; |
330 | ip_pkt.ttl = IPDEFTTL; | 335 | ip_pkt.ttl = IPDEFTTL; |
331 | ip_pkt.proto = IPPROTO_ICMP; | 336 | ip_pkt.proto = IPPROTO_ICMP; |
@@ -350,7 +355,7 @@ send_icmp (const struct in_addr *my_ip, const struct in_addr *other) | |||
350 | ip_pkt.tos = 0; | 355 | ip_pkt.tos = 0; |
351 | ip_pkt.pkt_len = | 356 | ip_pkt.pkt_len = |
352 | htons (sizeof (struct ip_header) + sizeof (struct icmp_echo_header)); | 357 | htons (sizeof (struct ip_header) + sizeof (struct icmp_echo_header)); |
353 | ip_pkt.id = htons (256); | 358 | ip_pkt.id = htons (PACKET_ID); |
354 | ip_pkt.flags_frag_offset = 0; | 359 | ip_pkt.flags_frag_offset = 0; |
355 | ip_pkt.ttl = 1; /* real TTL would be 1 on a time exceeded packet */ | 360 | ip_pkt.ttl = 1; /* real TTL would be 1 on a time exceeded packet */ |
356 | ip_pkt.proto = IPPROTO_ICMP; | 361 | ip_pkt.proto = IPPROTO_ICMP; |
@@ -470,11 +475,19 @@ main (int argc, char *const *argv) | |||
470 | if (-1 == (rawsock = make_raw_socket ())) | 475 | if (-1 == (rawsock = make_raw_socket ())) |
471 | return 2; | 476 | return 2; |
472 | uid = getuid (); | 477 | uid = getuid (); |
478 | #ifdef HAVE_SETRESUID | ||
473 | if (0 != setresuid (uid, uid, uid)) | 479 | if (0 != setresuid (uid, uid, uid)) |
474 | { | 480 | { |
475 | fprintf (stderr, "Failed to setresuid: %s\n", strerror (errno)); | 481 | fprintf (stderr, "Failed to setresuid: %s\n", strerror (errno)); |
476 | /* not critical, continue anyway */ | 482 | return 3; |
477 | } | 483 | } |
484 | #else | ||
485 | if (0 != (setuid (uid) | seteuid (uid))) | ||
486 | { | ||
487 | fprintf (stderr, "Failed to setuid: %s\n", strerror (errno)); | ||
488 | return 6; | ||
489 | } | ||
490 | #endif | ||
478 | send_icmp (&external, &target); | 491 | send_icmp (&external, &target); |
479 | send_icmp_udp (&external, &target); | 492 | send_icmp_udp (&external, &target); |
480 | close (rawsock); | 493 | close (rawsock); |