From: Rogier Wolff Date: Sun, 21 Aug 2016 10:28:57 +0000 (+0200) Subject: fixed #141 compile without SCTP if not available X-Git-Tag: v0.88~31 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=480fcd3c33bee378c8fead164059dad287b20dc7;p=thirdparty%2Fmtr.git fixed #141 compile without SCTP if not available --- diff --git a/mtr.c b/mtr.c index 201b311..914c2b4 100644 --- a/mtr.c +++ b/mtr.c @@ -524,6 +524,7 @@ void parse_arg (int argc, char **argv) mtrtype = IPPROTO_TCP; break; case 'S': +#ifdef HAS_SCTP if (mtrtype != IPPROTO_ICMP) { fprintf(stderr, "-u , -T and -S are mutually exclusive.\n"); exit(EXIT_FAILURE); @@ -532,6 +533,11 @@ void parse_arg (int argc, char **argv) remoteport = 80; } mtrtype = IPPROTO_SCTP; +#else + fprintf (stderr, "No SCTP support found at compiletime\n"); + exit (EXIT_FAILURE); +#endif + break; case 'b': show_ips = 1; break; diff --git a/net.c b/net.c index c591acc..c94abb4 100644 --- a/net.c +++ b/net.c @@ -70,12 +70,17 @@ struct TCPHeader { uint32 seq; }; +// This ifdef is unnecessary. But it should trigger errors if I forget +// an ifdef HAS_SCTP further down. (Success! I forgot one and the compiler +// told me the line number!) +#ifdef HAS_SCTP /* Structure of an SCTP header */ struct SCTPHeader { uint16 srcport; uint16 dstport; uint32 veri_tag; }; +#endif /* Structure of an IPv4 UDP pseudoheader. */ struct UDPv4PHeader { @@ -438,6 +443,7 @@ void net_send_tcp(int index) connect(s, (struct sockaddr *) &remote, len); } +#ifdef HAS_SCTP /* Attempt to connect to a SCTP port with a TTL */ void net_send_sctp(int index) { @@ -556,6 +562,7 @@ void net_send_sctp(int index) connect(s, (struct sockaddr *) &remote, len); } +#endif /* Attempt to find the host at a particular number of hops away */ void net_send_query(int index) @@ -565,10 +572,12 @@ void net_send_query(int index) return; } +#ifdef HAS_SCTP if (mtrtype == IPPROTO_SCTP) { net_send_sctp(index); return; } +#endif /*ok char packet[sizeof(struct IPHeader) + sizeof(struct ICMPHeader)];*/ char packet[MAXPACKET]; @@ -885,7 +894,9 @@ void net_process_return(void) struct ICMPHeader *header = NULL; struct UDPHeader *udpheader = NULL; struct TCPHeader *tcpheader = NULL; +#ifdef HAS_SCTP struct SCTPHeader *sctpheader = NULL; +#endif struct timeval now; ip_t * fromaddress = NULL; int echoreplytype = 0, timeexceededtype = 0, unreachabletype = 0; @@ -1065,7 +1076,8 @@ void net_process_return(void) seq_num = ntohs(tcpheader->srcport); } break; - + +#ifdef HAS_SCTP case IPPROTO_SCTP: if (header->type == timeexceededtype || header->type == unreachabletype) { switch ( af ) { @@ -1102,6 +1114,7 @@ void net_process_return(void) seq_num = ntohs(sctpheader->srcport); } break; +#endif } if (seq_num) net_process_ping (seq_num, mpls, (void *) fromaddress, now); diff --git a/net.h b/net.h index 23183c1..0350a4a 100644 --- a/net.h +++ b/net.h @@ -134,3 +134,9 @@ struct mplslen { }; void decodempls(int, char *, struct mplslen *, int); + +#ifdef IPPROTO_SCTP + #define HAS_SCTP +#endif + +