iptunnel: fix building w/older linux headers 86/287986/1 accepted/tizen_base accepted/tizen_base_asan accepted/tizen_base_tool_dev tizen_base tizen_base_dev accepted/tizen/base/20231107.085012 accepted/tizen/base/asan/20231128.220136 accepted/tizen/base/tool/20230328.020645 accepted/tizen/base/tool/dev/20230612.022430 submit/tizen_base/20230324.201856 submit/tizen_base/20230410.073934 submit/tizen_base_dev/20230612.021243
authorMike Frysinger <vapier@gentoo.org>
Tue, 15 Nov 2016 03:48:42 +0000 (22:48 -0500)
committerMarek Pikuła <m.pikula@partner.samsung.com>
Wed, 8 Feb 2023 13:46:44 +0000 (14:46 +0100)
While linux-4.8+ headers work, older ones are missing includes.
Dropping netinet/ip.h uncovered that mess, so add linux/ip.h.

Change-Id: I6799b8b33b178a9926beee2c72d6ede6c971f85c
URL: https://bugs.gentoo.org/599542
Reported-by: Conrad Kostecki <ck@bl4ckb0x.de>
Source: https://sourceforge.net/p/net-tools/code/ci/ea3935bd7c0f36c86c40e5785326698fa3336c6a/

iptunnel.c

index 68f6bdf..b2e74d1 100644 (file)
 #include <sys/ioctl.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
-#if defined(__GLIBC__) && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1))
 #include <net/if.h>
 #include <net/if_arp.h>
-#else
-#include <linux/if.h>
-#include <linux/if_arp.h>
-#endif
+/* We only care about linux/if_tunnel.h.  Unfortunately, older Linux headers
+ * (pre linux-4.8) did not include all the proper headers leading to missing
+ * structs and types.
+ */
 #include <linux/types.h>
+#include <linux/ip.h>
 #include <linux/if_tunnel.h>
 
 #include "config.h"
@@ -377,7 +377,7 @@ static int do_add(int cmd, int argc, char **argv)
                return do_add_ioctl(cmd, "gre0", &p);
        case IPPROTO_IPV6:
                return do_add_ioctl(cmd, "sit0", &p);
-       default:        
+       default:
                fprintf(stderr, _("cannot determine tunnel mode (ipip, gre or sit)\n"));
                return -1;
        }
@@ -392,13 +392,13 @@ int do_del(int argc, char **argv)
                return -1;
 
        switch (p.iph.protocol) {
-       case IPPROTO_IPIP:      
+       case IPPROTO_IPIP:
                return do_del_ioctl(p.name[0] ? p.name : "tunl0", &p);
-       case IPPROTO_GRE:       
+       case IPPROTO_GRE:
                return do_del_ioctl(p.name[0] ? p.name : "gre0", &p);
-       case IPPROTO_IPV6:      
+       case IPPROTO_IPV6:
                return do_del_ioctl(p.name[0] ? p.name : "sit0", &p);
-       default:        
+       default:
                return do_del_ioctl(p.name, &p);
        }
        return -1;
@@ -539,7 +539,7 @@ static int do_show(int argc, char **argv)
                return -1;
 
        switch (p.iph.protocol) {
-       case IPPROTO_IPIP:      
+       case IPPROTO_IPIP:
                err = do_get_ioctl(p.name[0] ? p.name : "tunl0", &p);
                break;
        case IPPROTO_GRE:
@@ -598,7 +598,7 @@ int main(int argc, char **argv)
                basename = argv[0];
        else
                basename++;
-       
+
        while (argc > 1) {
                if (argv[1][0] != '-')
                        break;