From: Sami Kerola Date: Mon, 29 Aug 2016 12:05:01 +0000 (+0100) Subject: cleanup: avoid duplicating stdint.h X-Git-Tag: v0.88~26^2~24 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a2b73fc29b0477d8daf5f56b0f4e7d416acff662;p=thirdparty%2Fmtr.git cleanup: avoid duplicating stdint.h 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 --- diff --git a/mtr.h b/mtr.h index 30322e3..b9d8009 100644 --- a/mtr.h +++ b/mtr.h @@ -25,40 +25,6 @@ #include /* 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 7a77af0..a70c095 100644 --- a/net.c +++ b/net.c @@ -35,6 +35,7 @@ #endif #include #include +#include #include #include #include @@ -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 59712a2..44814fe 100644 --- a/net.h +++ b/net.h @@ -26,6 +26,8 @@ #include #endif +#include + #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? */ };