(no commit message)
[oweals/gnunet.git] / src / transport / gnunet-nat-server.c
index dcea365f8fa2ac2dd0271b3833291ffb4decf4b9..13a54058b71f46358fc6d9977119e5ff28db232f 100644 (file)
@@ -60,7 +60,7 @@
 /**
  * Must match IP given in the client.
  */
-#define DUMMY_IP "1.2.3.4"
+#define DUMMY_IP "192.0.2.86"
 
 #define VERBOSE 0
 
@@ -91,6 +91,14 @@ struct icmp_packet
   uint32_t reserved;
 };
 
+struct udp_packet
+{
+  uint16_t src_port;
+
+  uint16_t dst_port;
+
+  uint32_t length;
+};
 
 static int icmpsock;
 
@@ -192,8 +200,10 @@ process_icmp_response ()
   struct in_addr sip;
   struct ip_packet ip_pkt;
   struct icmp_packet icmp_pkt;
+  struct udp_packet udp_pkt;
   size_t off;
   int have_port;
+  int have_udp;
   uint32_t port;
   
   have = read (icmpsock, buf, sizeof (buf));
@@ -205,6 +215,7 @@ process_icmp_response ()
       return; 
     }
   have_port = 0;
+
   if (have == sizeof (struct ip_packet) *2 + sizeof (struct icmp_packet) * 2 + sizeof(uint32_t))
     {
       have_port = 1;
@@ -223,7 +234,7 @@ process_icmp_response ()
   off += sizeof (ip_pkt);
   memcpy (&icmp_pkt, &buf[off], sizeof (icmp_pkt));
   off += sizeof (icmp_pkt);
-  if ( (ip_pkt.proto != IPPROTO_ICMP) ||
+  if ( ((ip_pkt.proto != IPPROTO_ICMP) && (ip_pkt.proto != IPPROTO_UDP)) ||
        (icmp_pkt.type != ICMP_TIME_EXCEEDED) || 
        (icmp_pkt.code != 0) )
     {
@@ -233,6 +244,16 @@ process_icmp_response ()
   memcpy(&sip, 
         &ip_pkt.src_ip, 
         sizeof (sip));
+
+  memcpy (&ip_pkt, &buf[off], sizeof (ip_pkt));
+  off += sizeof (ip_pkt);
+
+  have_udp = 0;
+  if (ip_pkt.proto == IPPROTO_UDP)
+    {
+      have_udp = 1;
+    }
+
   if (have_port)
     {
       memcpy(&port, &buf[sizeof (struct ip_packet) *2 + sizeof (struct icmp_packet) * 2], sizeof(uint32_t));
@@ -244,6 +265,16 @@ process_icmp_response ()
                          buf,
                          sizeof (buf)), port);
     }
+  else if (have_udp)
+    {
+      memcpy(&udp_pkt, &buf[off], sizeof(udp_pkt));
+      fprintf (stdout,
+               "%s:%d\n",
+               inet_ntop (AF_INET,
+                          &sip,
+                          buf,
+                          sizeof (buf)), ntohl(udp_pkt.length));
+    }
   else
     {
       fprintf (stdout,