]> git.ipfire.org Git - thirdparty/mtr.git/commitdiff
cleanup: avoid duplicating stdint.h
authorSami Kerola <kerolasa@iki.fi>
Mon, 29 Aug 2016 12:05:01 +0000 (13:05 +0100)
committerSami Kerola <kerolasa@iki.fi>
Mon, 29 Aug 2016 12:20:06 +0000 (13:20 +0100)
Use exactly defined data types from stdint.h rather than defining own
similar types.

Reference: http://pubs.opengroup.org/onlinepubs/009695399/basedefs/stdint.h.html

mtr.h
net.c
net.h

diff --git a/mtr.h b/mtr.h
index 30322e3a7f6de008cc7a0df13ffc82dac65f4f33..b9d8009ae69344f74832ce6d5f671a45887ff08b 100644 (file)
--- a/mtr.h
+++ b/mtr.h
 #include <arpa/inet.h>
 
 /* Typedefs */
-
-/*  Find the proper type for 8 bits  */
-#if SIZEOF_UNSIGNED_CHAR == 1
-typedef unsigned char uint8;
-#else
-#error No 8 bit type
-#endif
-
-/*  Find the proper type for 16 bits  */
-#if SIZEOF_UNSIGNED_SHORT == 2
-typedef unsigned short uint16;
-#elif SIZEOF_UNSIGNED_INT == 2
-typedef unsigned int uint16;
-#elif SIZEOF_UNSIGNED_LONG == 2
-typedef unsigned long uint16;
-#else
-#error No 16 bit type
-#endif
-
-/*  Find the proper type for 32 bits  */
-#if SIZEOF_UNSIGNED_SHORT == 4
-typedef unsigned short uint32;
-#elif SIZEOF_UNSIGNED_INT == 4
-typedef unsigned int uint32;
-#elif SIZEOF_UNSIGNED_LONG == 4
-typedef unsigned long uint32;
-#else
-#error No 32 bit type
-#endif
-
-typedef unsigned char byte;
-typedef unsigned short word;
-typedef unsigned long dword;
-
 #ifdef ENABLE_IPV6
 typedef struct in6_addr ip_t;
 #else
diff --git a/net.c b/net.c
index 7a77af08d153b7b60bf63782510f26ad0cccbf61..a70c095e95d5ac38b831bfa616bb42c727276d57 100644 (file)
--- a/net.c
+++ b/net.c
@@ -35,6 +35,7 @@
 #endif
 #include <stdio.h>
 #include <stdlib.h>
+#include <stdint.h>
 #include <math.h>
 #include <errno.h>
 #include <string.h>
@@ -60,26 +61,26 @@ static void decodempls(int, char *, struct mplslen *, int);
     the fields have different names between, for instance, Linux and 
     Solaris  */
 struct ICMPHeader {
-  uint8 type;
-  uint8 code;
-  uint16 checksum;
-  uint16 id;
-  uint16 sequence;
+  uint8_t type;
+  uint8_t code;
+  uint16_t checksum;
+  uint16_t id;
+  uint16_t sequence;
 };
 
 /* Structure of an UDP header.  */
 struct UDPHeader {
-  uint16 srcport;
-  uint16 dstport;
-  uint16 length;
-  uint16 checksum;
+  uint16_t srcport;
+  uint16_t dstport;
+  uint16_t length;
+  uint16_t checksum;
 };
 
 /* Structure of an TCP header, as far as we need it.  */
 struct TCPHeader {
-  uint16 srcport;
-  uint16 dstport;
-  uint32 seq;
+  uint16_t srcport;
+  uint16_t dstport;
+  uint32_t seq;
 };
 
 // This ifdef is unnecessary. But it should trigger errors if I forget
@@ -88,33 +89,33 @@ struct TCPHeader {
 #ifdef HAS_SCTP 
 /* Structure of an SCTP header */
 struct SCTPHeader {
-  uint16 srcport;
-  uint16 dstport;
-  uint32 veri_tag;
+  uint16_t srcport;
+  uint16_t dstport;
+  uint32_t veri_tag;
 };
 #endif
 
 /* Structure of an IPv4 UDP pseudoheader.  */
 struct UDPv4PHeader {
-  uint32 saddr;
-  uint32 daddr;
-  uint8 zero;
-  uint8 protocol;
-  uint16 len;
+  uint32_t saddr;
+  uint32_t daddr;
+  uint8_t zero;
+  uint8_t protocol;
+  uint16_t len;
 };
 
 /*  Structure of an IP header.  */
 struct IPHeader {
-  uint8 version;
-  uint8 tos;
-  uint16 len;
-  uint16 id;
-  uint16 frag;
-  uint8 ttl;
-  uint8 protocol;
-  uint16 check;
-  uint32 saddr;
-  uint32 daddr;
+  uint8_t version;
+  uint8_t tos;
+  uint16_t len;
+  uint16_t id;
+  uint16_t frag;
+  uint8_t ttl;
+  uint8_t protocol;
+  uint16_t check;
+  uint32_t saddr;
+  uint32_t daddr;
 };
   
 
@@ -228,9 +229,9 @@ extern int calc_deltatime (float waittime)
 
 static int checksum(void *data, int sz) 
 {
-  uint16 *ch;
-  uint32 sum;
-  uint16 odd;
+  uint16_t *ch;
+  uint32_t sum;
+  uint16_t odd;
 
   sum = 0;
   ch = data;
@@ -569,7 +570,7 @@ static void net_send_query(struct mtr_ctl *ctl, int index)
   struct ICMPHeader *icmp = NULL;
   struct UDPHeader *udp = NULL;
   struct UDPv4PHeader *udpp = NULL;
-  uint16 checksum_result;
+  uint16_t checksum_result;
 
   /*ok  int packetsize = sizeof(struct IPHeader) + sizeof(struct ICMPHeader) + datasize;*/
   int rv;
@@ -656,7 +657,7 @@ static void net_send_query(struct mtr_ctl *ctl, int index)
     udp = (struct UDPHeader *)(packet + iphsize);
     udp->checksum  = 0;
     if (!ctl->localport) {
-      ctl->localport = (uint16)getpid();
+      ctl->localport = (uint16_t)getpid();
       if (ctl->localport < MinPort)
         ctl->localport += MinPort;
     }
@@ -931,7 +932,7 @@ extern void net_process_return(struct mtr_ctl *ctl)
   switch ( ctl->mtrtype ) {
   case IPPROTO_ICMP:
     if (header->type == echoreplytype) {
-      if(header->id != (uint16)getpid())
+      if(header->id != (uint16_t)getpid())
         return;
 
       seq_num = header->sequence;
@@ -968,7 +969,7 @@ extern void net_process_return(struct mtr_ctl *ctl)
 #endif
       }
   
-      if (header->id != (uint16)getpid())
+      if (header->id != (uint16_t)getpid())
         return;
   
       seq_num = header->sequence;
@@ -1008,7 +1009,7 @@ extern void net_process_return(struct mtr_ctl *ctl)
         break;
 #endif
       }
-      if (ntohs(udpheader->srcport) != (uint16)ctl->localport)
+      if (ntohs(udpheader->srcport) != (uint16_t)ctl->localport)
         return;
 
       if (ctl->remoteport && ctl->remoteport == ntohs(udpheader->dstport)) {
diff --git a/net.h b/net.h
index 59712a2c26f566c9094302a9fa9532fae53babe6..44814fe5838af534c764c1b7bf776593956d512b 100644 (file)
--- a/net.h
+++ b/net.h
@@ -26,6 +26,8 @@
 #include <netinet/icmp6.h>
 #endif
 
+#include <stdint.h>
+
 #include "mtr.h"
 
 extern int net_preopen(void);
@@ -116,8 +118,8 @@ extern struct fields data_fields[MAXFLD];
 /* MPLS label object */
 struct mplslen {
   unsigned long label[MAXLABELS]; /* label value */
-  uint8 exp[MAXLABELS]; /* experimental bits */
-  uint8 ttl[MAXLABELS]; /* MPLS TTL */
+  uint8_t exp[MAXLABELS]; /* experimental bits */
+  uint8_t ttl[MAXLABELS]; /* MPLS TTL */
   char s[MAXLABELS]; /* bottom of stack */
   char labels; /* how many labels did we get? */
 };