convert -idirafter to -I
[platform/upstream/net-tools.git] / iptunnel.c
index 5dbb4ea..4943d83 100644 (file)
@@ -13,6 +13,8 @@
  *
  * Rani Assaf <rani@magic.metawire.com> 980929:        resolve addresses
  * Rani Assaf <rani@magic.metawire.com> 980930:        do not allow key for ipip/sit
+ * Bernd Eckenfels 990715: add linux/types.h (not clean but solves missing __u16
+ * Arnaldo Carvalho de Melo 20010404: use setlocale
  */
 
 #include <stdio.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <sys/ioctl.h>
-#include <linux/if.h>
-#include <linux/if_arp.h>
 #include <netinet/in.h>
 #include <netinet/ip.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
+#include <linux/types.h>
 #include <linux/if_tunnel.h>
 
+#include "config.h"
 #include "intl.h"
+#include "net-support.h"
+#include "version.h"
+#include "util.h"
 
 #undef GRE_CSUM
 #define GRE_CSUM       htons(0x8000)
 #define IPPROTO_GRE    47
 #endif
 
-#include "utils.h"
+#include "util-ank.h"
+
+char *Release = RELEASE,
+     *Version = "iptunnel 1.01",
+     *Signature = "Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>";
+
+static void version(void)
+{
+       printf("%s\n%s\n%s\n", Release, Version, Signature);
+       exit(E_VERSION);
+}
 
 static void usage(void) __attribute__((noreturn));
 
@@ -63,7 +85,8 @@ static void usage(void)
        fprintf(stderr, _("Usage: iptunnel { add | change | del | show } [ NAME ]\n"));
        fprintf(stderr, _("          [ mode { ipip | gre | sit } ] [ remote ADDR ] [ local ADDR ]\n"));
        fprintf(stderr, _("          [ [i|o]seq ] [ [i|o]key KEY ] [ [i|o]csum ]\n"));
-       fprintf(stderr, _("          [ ttl TTL ] [ tos TOS ] [ nopmtudisc ] [ dev PHYS_DEV ]\n\n"));
+       fprintf(stderr, _("          [ ttl TTL ] [ tos TOS ] [ nopmtudisc ] [ dev PHYS_DEV ]\n"));
+       fprintf(stderr, _("       iptunnel -V | --version\n\n"));
        fprintf(stderr, _("Where: NAME := STRING\n"));
        fprintf(stderr, _("       ADDR := { IP_ADDRESS | any }\n"));
        fprintf(stderr, _("       TOS  := { NUMBER | inherit }\n"));
@@ -265,7 +288,7 @@ static int parse_args(int argc, char **argv, struct ip_tunnel_parm *p)
                                p->iph.saddr = get_addr32(*argv);
                } else if (strcmp(*argv, "dev") == 0) {
                        NEXT_ARG();
-                       strncpy(medium, *argv, IFNAMSIZ-1);
+                       safe_strncpy(medium, *argv, IFNAMSIZ-1);
                } else if (strcmp(*argv, "ttl") == 0) {
                        unsigned uval;
                        NEXT_ARG();
@@ -290,7 +313,7 @@ static int parse_args(int argc, char **argv, struct ip_tunnel_parm *p)
                } else {
                        if (p->name[0])
                                usage();
-                       strncpy(p->name, *argv, IFNAMSIZ);
+                       safe_strncpy(p->name, *argv, IFNAMSIZ);
                }
                argc--; argv++;
        }
@@ -558,6 +581,12 @@ int main(int argc, char **argv)
 {
        char *basename;
 
+#if I18N
+       setlocale (LC_ALL, "");
+       bindtextdomain("net-tools", "/usr/share/locale");
+       textdomain("net-tools");
+#endif
+
        basename = strrchr(argv[0], '/');
        if (basename == NULL)
                basename = argv[0];
@@ -583,6 +612,8 @@ int main(int argc, char **argv)
                        ++show_stats;
                } else if (matches(argv[1], "-resolve") == 0) {
                        ++resolve_hosts;
+               } else if ((matches(argv[1], "-V") == 0) || (matches(argv[1], "--version") == 0)) {
+                       version();
                } else
                        usage();
                argc--; argv++;