aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nat/gnunet-helper-nat-client.c21
-rw-r--r--src/nat/gnunet-helper-nat-server.c7
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 fbebdbc0fd..f30348cc46 100644
--- a/src/nat/gnunet-helper-nat-client.c
+++ b/src/nat/gnunet-helper-nat-client.c
@@ -69,6 +69,11 @@
#define NAT_TRAV_PORT 22225
/**
+ * Must match packet ID used by gnunet-helper-nat-server.c
+ */
+#define PACKET_ID 256
+
+/**
* IPv4 header.
*/
struct ip_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 f71c37fa87..733c00dc21 100644
--- a/src/nat/gnunet-helper-nat-server.c
+++ b/src/nat/gnunet-helper-nat-server.c
@@ -70,6 +70,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.
*/
#define DUMMY_IP "192.0.2.86"
@@ -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;