From 1ff3c89a1a0eb49baee9c80b2a1043aefd2bf201 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Fri, 16 Dec 2011 11:19:15 +0000 Subject: [PATCH] additional stylistic changes to gnunet-helper-nat-client anticipating next round of suggestions from Jacob Applebaum --- src/nat/gnunet-helper-nat-client.c | 21 +++++++++++++++++---- src/nat/gnunet-helper-nat-server.c | 7 ++++++- 2 files changed, 23 insertions(+), 5 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 @@ -68,6 +68,11 @@ #define NAT_TRAV_PORT 22225 +/** + * Must match packet ID used by gnunet-helper-nat-server.c + */ +#define PACKET_ID 256 + /** * IPv4 header. */ @@ -228,7 +233,7 @@ send_icmp_udp (const struct in_addr *my_ip, const struct in_addr *other) ip_pkt.vers_ihl = 0x45; ip_pkt.tos = 0; ip_pkt.pkt_len = htons (sizeof (packet)); - ip_pkt.id = htons (256); + ip_pkt.id = htons (PACKET_ID); ip_pkt.flags_frag_offset = 0; ip_pkt.ttl = 128; ip_pkt.proto = IPPROTO_ICMP; @@ -325,7 +330,7 @@ send_icmp (const struct in_addr *my_ip, const struct in_addr *other) ip_pkt.vers_ihl = 0x45; ip_pkt.tos = 0; ip_pkt.pkt_len = htons (sizeof (packet)); - ip_pkt.id = htons (256); + ip_pkt.id = htons (PACKET_ID); ip_pkt.flags_frag_offset = 0; ip_pkt.ttl = IPDEFTTL; ip_pkt.proto = IPPROTO_ICMP; @@ -350,7 +355,7 @@ send_icmp (const struct in_addr *my_ip, const struct in_addr *other) ip_pkt.tos = 0; ip_pkt.pkt_len = htons (sizeof (struct ip_header) + sizeof (struct icmp_echo_header)); - ip_pkt.id = htons (256); + ip_pkt.id = htons (PACKET_ID); ip_pkt.flags_frag_offset = 0; ip_pkt.ttl = 1; /* real TTL would be 1 on a time exceeded packet */ ip_pkt.proto = IPPROTO_ICMP; @@ -470,11 +475,19 @@ main (int argc, char *const *argv) if (-1 == (rawsock = make_raw_socket ())) return 2; uid = getuid (); +#ifdef HAVE_SETRESUID if (0 != setresuid (uid, uid, uid)) { fprintf (stderr, "Failed to setresuid: %s\n", strerror (errno)); - /* not critical, continue anyway */ + return 3; } +#else + if (0 != (setuid (uid) | seteuid (uid))) + { + fprintf (stderr, "Failed to setuid: %s\n", strerror (errno)); + return 6; + } +#endif send_icmp (&external, &target); send_icmp_udp (&external, &target); close (rawsock); diff --git a/src/nat/gnunet-helper-nat-server.c b/src/nat/gnunet-helper-nat-server.c index f71c37fa8..733c00dc2 100644 --- a/src/nat/gnunet-helper-nat-server.c +++ b/src/nat/gnunet-helper-nat-server.c @@ -69,6 +69,11 @@ */ #define VERBOSE 0 +/** + * Must match packet ID used by gnunet-helper-nat-client.c + */ +#define PACKET_ID 256 + /** * Must match IP given in the client. */ @@ -245,7 +250,7 @@ send_icmp_echo (const struct in_addr *my_ip) ip_pkt.vers_ihl = 0x45; ip_pkt.tos = 0; ip_pkt.pkt_len = htons (sizeof (packet)); - ip_pkt.id = htons (256); + ip_pkt.id = htons (PACKET_ID); ip_pkt.flags_frag_offset = 0; ip_pkt.ttl = IPDEFTTL; ip_pkt.proto = IPPROTO_ICMP; -- 2.25.1