more code cleanup
[oweals/gnunet.git] / src / transport / gnunet-nat-server-windows.c
index 7dee1529629d84061ff02ff0e8a3195dec7c307b..ceff3fb8d9b5c2b0ffd894406a506eaa0342ebe6 100644 (file)
  */
 #define VERBOSE 0
 
+/**
+ * Must match IP given in the client.
+ */
+#define DUMMY_IP "192.0.2.86"
+
 /**
  * TTL to use for our outgoing messages.
  */
 
 #define ICMP_TIME_EXCEEDED      11      /* Time Exceeded */
 
-/**
- * Must match IP given in the client.
- */
-#define DUMMY_IP "192.0.2.86"
-
 /**
  * How often do we send our ICMP messages to receive replies?
  */
@@ -87,52 +87,52 @@ struct ip_packet
   /**
    * Version (4 bits) + Internet header length (4 bits) 
    */
-  u_char vers_ihl; 
+  uint8_t vers_ihl; 
 
   /**
    * Type of service
    */
-  u_char tos;  
+  uint8_t tos;  
 
   /**
    * Total length
    */
-  u_short pkt_len;  
+  uint16_t pkt_len;  
 
   /**
    * Identification
    */
-  u_short id;    
+  uint16_t id;    
 
   /**
    * Flags (3 bits) + Fragment offset (13 bits)
    */
-  u_short flags_frag_offset; 
+  uint16_t flags_frag_offset; 
 
   /**
    * Time to live
    */
-  u_char  ttl;   
+  uint8_t  ttl;   
 
   /**
    * Protocol       
    */
-  u_char  proto; 
+  uint8_t  proto; 
 
   /**
    * Header checksum
    */
-  u_short checksum; 
+  uint16_t checksum; 
 
   /**
    * Source address
    */
-  u_long  src_ip;  
+  uint32_t  src_ip;  
 
   /**
    * Destination address 
    */
-  u_long  dst_ip;  
+  uint32_t  dst_ip;  
 };
 
 /**
@@ -303,7 +303,6 @@ process_icmp_response ()
   struct udp_packet udp_pkt;
   size_t off;
   int have_port;
-  int have_udp;
   uint32_t port;
 
   have = read (icmpsock, buf, sizeof (buf));
@@ -350,7 +349,6 @@ process_icmp_response ()
         sizeof (sip));
   memcpy (&ip_pkt, &buf[off], sizeof (ip_pkt));
   off += sizeof (ip_pkt);
-  have_udp = (ip_pkt.proto == IPPROTO_UDP);
 
   if (have_port)
     {
@@ -369,7 +367,7 @@ process_icmp_response ()
               buf, 
               port);
     }
-  else if (have_udp)
+  else if (ip_pkt.proto == IPPROTO_UDP)
     {
       memcpy(&udp_pkt,
             &buf[off],
@@ -383,7 +381,7 @@ process_icmp_response ()
       fprintf (stdout, 
               "%s:%d\n", 
               buf, 
-              ntohs((int)udp_pkt.length));
+              ntohs((uint16_t)udp_pkt.length));
     }
   else
     {
@@ -403,6 +401,8 @@ process_icmp_response ()
 
 /**
  * Create an ICMP raw socket for reading.
+ *
+ * @return INVALID_SOCKET on error
  */
 static SOCKET
 make_icmp_socket ()
@@ -415,7 +415,7 @@ make_icmp_socket ()
       fprintf (stderr,
               "Error opening RAW socket: %s\n",
               strerror (errno));
-      return -1;
+      return INVALID_SOCKET;
     }  
   return ret;
 }
@@ -423,6 +423,8 @@ make_icmp_socket ()
 
 /**
  * Create an ICMP raw socket for writing.
+ *
+ * @return INVALID_SOCKET on error
  */
 static SOCKET
 make_raw_socket ()
@@ -498,11 +500,11 @@ main (int argc,
       fprintf (stderr, "Failed to find Winsock 2.1 or better.\n");
       return 2;
     }
-  if (-1 == (icmpsock = make_icmp_socket()))
+  if (INVALID_SOCKET == (icmpsock = make_icmp_socket()))
     {
       return 3; 
     }
-  if (-1 == (make_raw_socket()))
+  if (INVALID_SOCKET == (make_raw_socket()))
     {
       closesocket (icmpsock);
       return 3; 
@@ -513,7 +515,7 @@ main (int argc,
       FD_SET (icmpsock, &rs);
       tv.tv_sec = 0;
       tv.tv_usec = ICMP_SEND_FREQUENCY_MS * 1000; 
-      if (0 != select (icmpsock + 1, &rs, NULL, NULL, &tv))
+      if (-1 == select (icmpsock + 1, &rs, NULL, NULL, &tv))
        {
          if (errno == EINTR)
            continue;