]> git.ipfire.org Git - thirdparty/mtr.git/commitdiff
fixed #141 compile without SCTP if not available
authorRogier Wolff <R.E.Wolff@BitWizard.nl>
Sun, 21 Aug 2016 10:28:57 +0000 (12:28 +0200)
committerRogier Wolff <R.E.Wolff@BitWizard.nl>
Sun, 21 Aug 2016 10:28:57 +0000 (12:28 +0200)
mtr.c
net.c
net.h

diff --git a/mtr.c b/mtr.c
index 201b311f04184d078f2947bbe17ec86ab547d401..914c2b4171645b237df6577bab599b0dd076f9cf 100644 (file)
--- 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 c591acc55e3e2ad042cec335806c5fd6aed36058..c94abb400775fbafd80851be2a1455d410fdd446 100644 (file)
--- 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 23183c195950ec76bf960b30c3b1a38c2c94455c..0350a4a7d317c1c5d063d80c0f0a6638bb704b25 100644 (file)
--- 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
+
+