Commit 13842991 authored by Martina Ferrari's avatar Martina Ferrari

Merge tag 'upstream/1.60+git20180626.aebd88ef' into debian/sid

parents a5ac6e83 aebd88ef
......@@ -24,7 +24,7 @@ TODO for net-tools
[ ] Config file only works with bash not ash.
[ ] Token ring is almost totally untested.
[ ] additional tools for IPX, AX.25 etc be bundled [ipxripd004, ipx_* tools
from caldera, axattach] into existing bins
from caldera, kissattach] into existing bins
[ ] "SIOCAX25OPTRT" [Joerg (DL1BKE)]. 1.3.75
[ ] dummy NOARP?! (2. default route for preveting hostunreachables on linedrop)
[ ] ppp_dev_stat called for each dev in ifconfig, why? (1.3.17)
......
......@@ -93,7 +93,7 @@ const struct hwtype *hw;/* current hardware type */
int sockfd = 0; /* active socket descriptor */
int hw_set = 0; /* flag if hw-type was set (-H) */
char device[16] = ""; /* current device */
static void usage(void);
static void usage(int);
/* Delete an entry from the ARP cache. */
static int arp_del(char **args)
......@@ -168,14 +168,14 @@ static int arp_del(char **args)
}
if (!strcmp(*args, "dev")) {
if (*++args == NULL)
usage();
usage(E_OPTERR);
safe_strncpy(device, *args, sizeof(device));
args++;
continue;
}
if (!strcmp(*args, "netmask")) {
if (*++args == NULL)
usage();
usage(E_OPTERR);
if (strcmp(*args, "255.255.255.255") != 0) {
safe_strncpy(host, *args, (sizeof host));
if (ap->input(0, host, &ss) < 0) {
......@@ -189,7 +189,7 @@ static int arp_del(char **args)
args++;
continue;
}
usage();
usage(E_OPTERR);
}
// if neighter priv nor pub is given, work on both
......@@ -345,14 +345,14 @@ static int arp_set(char **args)
}
if (!strcmp(*args, "dev")) {
if (*++args == NULL)
usage();
usage(E_OPTERR);
safe_strncpy(device, *args, sizeof(device));
args++;
continue;
}
if (!strcmp(*args, "netmask")) {
if (*++args == NULL)
usage();
usage(E_OPTERR);
if (strcmp(*args, "255.255.255.255") != 0) {
safe_strncpy(host, *args, (sizeof host));
if (ap->input(0, host, &ss) < 0) {
......@@ -366,7 +366,7 @@ static int arp_set(char **args)
args++;
continue;
}
usage();
usage(E_OPTERR);
}
/* Fill in the remainder of the request. */
......@@ -565,6 +565,15 @@ static int arp_show(char *name)
ip, &type, &flags, hwa, mask, dev);
if (num < 4)
break;
if (num == 5) {
/*
* This happens for incomplete ARP entries for which there is
* no hardware address in the line.
*/
num = sscanf(line, "%s 0x%x 0x%x %99s %99s\n",
ip, &type, &flags, mask, dev);
hwa[0] = 0;
}
entries++;
/* if the user specified hw-type differs, skip it */
......@@ -614,33 +623,34 @@ static int arp_show(char *name)
static void version(void)
{
fprintf(stderr, "%s\n%s\n", Release, Features);
printf("%s\n%s\n", Release, Features);
exit(E_VERSION);
}
static void usage(void)
static void usage(int rc)
{
fprintf(stderr, _("Usage:\n arp [-vn] [<HW>] [-i <if>] [-a] [<hostname>] <-Display ARP cache\n"));
fprintf(stderr, _(" arp [-v] [-i <if>] -d <host> [pub] <-Delete ARP entry\n"));
fprintf(stderr, _(" arp [-vnD] [<HW>] [-i <if>] -f [<filename>] <-Add entry from file\n"));
fprintf(stderr, _(" arp [-v] [<HW>] [-i <if>] -s <host> <hwaddr> [temp] <-Add entry\n"));
fprintf(stderr, _(" arp [-v] [<HW>] [-i <if>] -Ds <host> <if> [netmask <nm>] pub <-''-\n\n"));
fprintf(stderr, _(" -a display (all) hosts in alternative (BSD) style\n"));
fprintf(stderr, _(" -e display (all) hosts in default (Linux) style\n"));
fprintf(stderr, _(" -s, --set set a new ARP entry\n"));
fprintf(stderr, _(" -d, --delete delete a specified entry\n"));
fprintf(stderr, _(" -v, --verbose be verbose\n"));
fprintf(stderr, _(" -n, --numeric don't resolve names\n"));
fprintf(stderr, _(" -i, --device specify network interface (e.g. eth0)\n"));
fprintf(stderr, _(" -D, --use-device read <hwaddr> from given device\n"));
fprintf(stderr, _(" -A, -p, --protocol specify protocol family\n"));
fprintf(stderr, _(" -f, --file read new entries from file or from /etc/ethers\n\n"));
fprintf(stderr, _(" <HW>=Use '-H <hw>' to specify hardware address type. Default: %s\n"), DFLT_HW);
fprintf(stderr, _(" List of possible hardware types (which support ARP):\n"));
FILE *fp = rc ? stderr : stdout;
fprintf(fp, _("Usage:\n arp [-vn] [<HW>] [-i <if>] [-a] [<hostname>] <-Display ARP cache\n"));
fprintf(fp, _(" arp [-v] [-i <if>] -d <host> [pub] <-Delete ARP entry\n"));
fprintf(fp, _(" arp [-vnD] [<HW>] [-i <if>] -f [<filename>] <-Add entry from file\n"));
fprintf(fp, _(" arp [-v] [<HW>] [-i <if>] -s <host> <hwaddr> [temp] <-Add entry\n"));
fprintf(fp, _(" arp [-v] [<HW>] [-i <if>] -Ds <host> <if> [netmask <nm>] pub <-''-\n\n"));
fprintf(fp, _(" -a display (all) hosts in alternative (BSD) style\n"));
fprintf(fp, _(" -e display (all) hosts in default (Linux) style\n"));
fprintf(fp, _(" -s, --set set a new ARP entry\n"));
fprintf(fp, _(" -d, --delete delete a specified entry\n"));
fprintf(fp, _(" -v, --verbose be verbose\n"));
fprintf(fp, _(" -n, --numeric don't resolve names\n"));
fprintf(fp, _(" -i, --device specify network interface (e.g. eth0)\n"));
fprintf(fp, _(" -D, --use-device read <hwaddr> from given device\n"));
fprintf(fp, _(" -A, -p, --protocol specify protocol family\n"));
fprintf(fp, _(" -f, --file read new entries from file or from /etc/ethers\n\n"));
fprintf(fp, _(" <HW>=Use '-H <hw>' to specify hardware address type. Default: %s\n"), DFLT_HW);
fprintf(fp, _(" List of possible hardware types (which support ARP):\n"));
print_hwlist(1); /* 1 = ARPable */
exit(E_USAGE);
exit(rc);
}
int main(int argc, char **argv)
......@@ -742,10 +752,11 @@ int main(int argc, char **argv)
case 'V':
version();
case '?':
case 'h':
usage(E_USAGE);
case '?':
default:
usage();
usage(E_OPTERR);
}
if (ap->af != AF_INET) {
......@@ -794,7 +805,7 @@ int main(int argc, char **argv)
break;
default:
usage();
usage(E_OPTERR);
}
exit(what);
......
......@@ -63,7 +63,6 @@ static int opt_v;
static void sethname(char *);
static void setdname(char *);
static void showhname(char *, int);
static void usage(void);
static void version(void);
static void setfilename(char *, int);
......@@ -254,39 +253,40 @@ static void setfilename(char *name, int what)
static void version(void)
{
fprintf(stderr, "%s\n", Release);
printf("%s\n", Release);
exit(E_VERSION);
}
static void usage(void)
static void usage(int rc)
{
fprintf(stderr, _("Usage: hostname [-v] {hostname|-F file} set hostname (from file)\n"));
fprintf(stderr, _(" domainname [-v] {nisdomain|-F file} set NIS domainname (from file)\n"));
FILE *fp = rc ? stderr : stdout;
fprintf(fp, _("Usage: hostname [-v] {hostname|-F file} set hostname (from file)\n"));
fprintf(fp, _(" domainname [-v] {nisdomain|-F file} set NIS domainname (from file)\n"));
#if HAVE_AFDECnet
fprintf(stderr, _(" nodename [-v] {nodename|-F file} set DECnet node name (from file)\n"));
fprintf(fp, _(" nodename [-v] {nodename|-F file} set DECnet node name (from file)\n"));
#endif
fprintf(stderr, _(" hostname [-v] [-d|-f|-s|-a|-i|-y|-n] display formatted name\n"));
fprintf(stderr, _(" hostname [-v] display hostname\n\n"));
fprintf(stderr, _(" hostname -V|--version|-h|--help print info and exit\n\n"));
fprintf(stderr, _(" dnsdomainname=hostname -d, {yp,nis,}domainname=hostname -y\n\n"));
fprintf(stderr, _(" -s, --short short host name\n"));
fprintf(stderr, _(" -a, --alias alias names\n"));
fprintf(stderr, _(" -i, --ip-address addresses for the hostname\n"));
fprintf(stderr, _(" -f, --fqdn, --long long host name (FQDN)\n"));
fprintf(stderr, _(" -d, --domain DNS domain name\n"));
fprintf(stderr, _(" -y, --yp, --nis NIS/YP domainname\n"));
fprintf(fp, _(" hostname [-v] [-d|-f|-s|-a|-i|-y|-n] display formatted name\n"));
fprintf(fp, _(" hostname [-v] display hostname\n\n"));
fprintf(fp, _(" hostname -V|--version|-h|--help print info and exit\n\n"));
fprintf(fp, _(" dnsdomainname=hostname -d, {yp,nis,}domainname=hostname -y\n\n"));
fprintf(fp, _(" -s, --short short host name\n"));
fprintf(fp, _(" -a, --alias alias names\n"));
fprintf(fp, _(" -i, --ip-address addresses for the hostname\n"));
fprintf(fp, _(" -f, --fqdn, --long long host name (FQDN)\n"));
fprintf(fp, _(" -d, --domain DNS domain name\n"));
fprintf(fp, _(" -y, --yp, --nis NIS/YP domainname\n"));
#if HAVE_AFDECnet
fprintf(stderr, _(" -n, --node DECnet node name\n"));
fprintf(fp, _(" -n, --node DECnet node name\n"));
#endif /* HAVE_AFDECnet */
fprintf(stderr, _(" -F, --file read hostname or NIS domainname from given file\n\n"));
fprintf(stderr, _(
fprintf(fp, _(" -F, --file read hostname or NIS domainname from given file\n\n"));
fprintf(fp, _(
" This command can read or set the hostname or the NIS domainname. You can\n"
" also read the DNS domain or the FQDN (fully qualified domain name).\n"
" Unless you are using bind or NIS for host lookups you can change the\n"
" FQDN (Fully Qualified Domain Name) and the DNS domain name (which is\n"
" part of the FQDN) in the /etc/hosts file.\n"));
exit(E_USAGE);
exit(rc);
}
......@@ -366,10 +366,12 @@ int main(int argc, char **argv)
case 'V':
version();
break; // not reached
case '?':
case 'h':
usage(E_USAGE);
break; // not reached
case '?':
default:
usage();
usage(E_OPTERR);
break; // not reached
};
......
......@@ -198,42 +198,43 @@ static int test_flag(char *ifname, short flags)
return (ifr.ifr_flags & flags);
}
static void usage(void)
static void usage(int rc)
{
fprintf(stderr, _("Usage:\n ifconfig [-a] [-v] [-s] <interface> [[<AF>] <address>]\n"));
FILE *fp = rc ? stderr : stdout;
fprintf(fp, _("Usage:\n ifconfig [-a] [-v] [-s] <interface> [[<AF>] <address>]\n"));
#if HAVE_AFINET
fprintf(stderr, _(" [add <address>[/<prefixlen>]]\n"));
fprintf(stderr, _(" [del <address>[/<prefixlen>]]\n"));
fprintf(stderr, _(" [[-]broadcast [<address>]] [[-]pointopoint [<address>]]\n"));
fprintf(stderr, _(" [netmask <address>] [dstaddr <address>] [tunnel <address>]\n"));
fprintf(fp, _(" [add <address>[/<prefixlen>]]\n"));
fprintf(fp, _(" [del <address>[/<prefixlen>]]\n"));
fprintf(fp, _(" [[-]broadcast [<address>]] [[-]pointopoint [<address>]]\n"));
fprintf(fp, _(" [netmask <address>] [dstaddr <address>] [tunnel <address>]\n"));
#endif
#ifdef SIOCSKEEPALIVE
fprintf(stderr, _(" [outfill <NN>] [keepalive <NN>]\n"));
fprintf(fp, _(" [outfill <NN>] [keepalive <NN>]\n"));
#endif
fprintf(stderr, _(" [hw <HW> <address>] [mtu <NN>]\n"));
fprintf(stderr, _(" [[-]trailers] [[-]arp] [[-]allmulti]\n"));
fprintf(stderr, _(" [multicast] [[-]promisc]\n"));
fprintf(stderr, _(" [mem_start <NN>] [io_addr <NN>] [irq <NN>] [media <type>]\n"));
fprintf(fp, _(" [hw <HW> <address>] [mtu <NN>]\n"));
fprintf(fp, _(" [[-]trailers] [[-]arp] [[-]allmulti]\n"));
fprintf(fp, _(" [multicast] [[-]promisc]\n"));
fprintf(fp, _(" [mem_start <NN>] [io_addr <NN>] [irq <NN>] [media <type>]\n"));
#ifdef HAVE_TXQUEUELEN
fprintf(stderr, _(" [txqueuelen <NN>]\n"));
fprintf(fp, _(" [txqueuelen <NN>]\n"));
#endif
#ifdef HAVE_DYNAMIC
fprintf(stderr, _(" [[-]dynamic]\n"));
fprintf(fp, _(" [[-]dynamic]\n"));
#endif
fprintf(stderr, _(" [up|down] ...\n\n"));
fprintf(fp, _(" [up|down] ...\n\n"));
fprintf(stderr, _(" <HW>=Hardware Type.\n"));
fprintf(stderr, _(" List of possible hardware types:\n"));
fprintf(fp, _(" <HW>=Hardware Type.\n"));
fprintf(fp, _(" List of possible hardware types:\n"));
print_hwlist(0); /* 1 = ARPable */
fprintf(stderr, _(" <AF>=Address family. Default: %s\n"), DFLT_AF);
fprintf(stderr, _(" List of possible address families:\n"));
fprintf(fp, _(" <AF>=Address family. Default: %s\n"), DFLT_AF);
fprintf(fp, _(" List of possible address families:\n"));
print_aflist(0); /* 1 = routeable */
exit(E_USAGE);
exit(rc);
}
static void version(void)
{
fprintf(stderr, "%s\n", Release);
printf("%s\n", Release);
exit(E_VERSION);
}
......@@ -299,7 +300,7 @@ int main(int argc, char **argv)
else if (!strcmp(*argv, "-?") || !strcmp(*argv, "-h") ||
!strcmp(*argv, "-help") || !strcmp(*argv, "--help"))
usage();
usage(E_USAGE);
else {
fprintf(stderr, _("ifconfig: option `%s' not recognised.\n"),
......@@ -359,7 +360,7 @@ int main(int argc, char **argv)
#ifdef IFF_PORTSEL
if (!strcmp(*spp, "media") || !strcmp(*spp, "port")) {
if (*++spp == NULL)
usage();
usage(E_OPTERR);
if (!strcasecmp(*spp, "auto")) {
goterr |= set_flag(ifr.ifr_name, IFF_AUTOMEDIA);
} else {
......@@ -471,7 +472,7 @@ int main(int argc, char **argv)
if (!strcmp(*spp, "mtu")) {
if (*++spp == NULL)
usage();
usage(E_OPTERR);
ifr.ifr_mtu = atoi(*spp);
if (ioctl(skfd, SIOCSIFMTU, &ifr) < 0) {
fprintf(stderr, "SIOCSIFMTU: %s\n", strerror(errno));
......@@ -483,7 +484,7 @@ int main(int argc, char **argv)
#ifdef SIOCSKEEPALIVE
if (!strcmp(*spp, "keepalive")) {
if (*++spp == NULL)
usage();
usage(E_OPTERR);
ifr.ifr_data = (caddr_t) (uintptr_t) atoi(*spp);
if (ioctl(skfd, SIOCSKEEPALIVE, &ifr) < 0) {
fprintf(stderr, "SIOCSKEEPALIVE: %s\n", strerror(errno));
......@@ -497,7 +498,7 @@ int main(int argc, char **argv)
#ifdef SIOCSOUTFILL
if (!strcmp(*spp, "outfill")) {
if (*++spp == NULL)
usage();
usage(E_OPTERR);
ifr.ifr_data = (caddr_t) (uintptr_t) atoi(*spp);
if (ioctl(skfd, SIOCSOUTFILL, &ifr) < 0) {
fprintf(stderr, "SIOCSOUTFILL: %s\n", strerror(errno));
......@@ -540,7 +541,7 @@ int main(int argc, char **argv)
}
if (!strcmp(*spp, "dstaddr")) {
if (*++spp == NULL)
usage();
usage(E_OPTERR);
safe_strncpy(host, *spp, (sizeof host));
if (ap->input(0, host, &_sa) < 0) {
if (ap->herror)
......@@ -562,7 +563,7 @@ int main(int argc, char **argv)
}
if (!strcmp(*spp, "netmask")) {
if (*++spp == NULL || didnetmask)
usage();
usage(E_OPTERR);
safe_strncpy(host, *spp, (sizeof host));
if (ap->input(0, host, &_sa) < 0) {
if (ap->herror)
......@@ -581,7 +582,7 @@ int main(int argc, char **argv)
#ifdef HAVE_TXQUEUELEN
if (!strcmp(*spp, "txqueuelen")) {
if (*++spp == NULL)
usage();
usage(E_OPTERR);
ifr.ifr_qlen = strtoul(*spp, NULL, 0);
if (ioctl(skfd, SIOCSIFTXQLEN, &ifr) < 0) {
fprintf(stderr, "SIOCSIFTXQLEN: %s\n", strerror(errno));
......@@ -594,7 +595,7 @@ int main(int argc, char **argv)
if (!strcmp(*spp, "mem_start")) {
if (*++spp == NULL)
usage();
usage(E_OPTERR);
if (ioctl(skfd, SIOCGIFMAP, &ifr) < 0) {
fprintf(stderr, "mem_start: SIOCGIFMAP: %s\n", strerror(errno));
spp++;
......@@ -611,7 +612,7 @@ int main(int argc, char **argv)
}
if (!strcmp(*spp, "io_addr")) {
if (*++spp == NULL)
usage();
usage(E_OPTERR);
if (ioctl(skfd, SIOCGIFMAP, &ifr) < 0) {
fprintf(stderr, "io_addr: SIOCGIFMAP: %s\n", strerror(errno));
spp++;
......@@ -628,7 +629,7 @@ int main(int argc, char **argv)
}
if (!strcmp(*spp, "irq")) {
if (*++spp == NULL)
usage();
usage(E_OPTERR);
if (ioctl(skfd, SIOCGIFMAP, &ifr) < 0) {
fprintf(stderr, "irq: SIOCGIFMAP: %s\n", strerror(errno));
goterr = 1;
......@@ -677,9 +678,9 @@ int main(int argc, char **argv)
if (!strcmp(*spp, "hw")) {
if (*++spp == NULL)
usage();
usage(E_OPTERR);
if ((hw = get_hwtype(*spp)) == NULL)
usage();
usage(E_OPTERR);
if (hw->input == NULL) {
fprintf(stderr, _("hw address type `%s' has no handler to set address. failed.\n"), *spp);
spp+=2;
......@@ -687,7 +688,7 @@ int main(int argc, char **argv)
continue;
}
if (*++spp == NULL)
usage();
usage(E_OPTERR);
safe_strncpy(host, *spp, (sizeof host));
if (hw->input(host, &_sa) < 0) {
fprintf(stderr, _("%s: invalid %s address.\n"), host, hw->name);
......@@ -711,14 +712,14 @@ int main(int argc, char **argv)
#if HAVE_AFINET || HAVE_AFINET6
if (!strcmp(*spp, "add")) {
if (*++spp == NULL)
usage();
usage(E_OPTERR);
#if HAVE_AFINET6
if (strchr(*spp, ':')) {
/* INET6 */
if ((cp = strchr(*spp, '/'))) {
prefix_len = atol(cp + 1);
if ((prefix_len < 0) || (prefix_len > 128))
usage();
usage(E_OPTERR);
*cp = 0;
} else {
prefix_len = 128;
......@@ -801,7 +802,7 @@ int main(int argc, char **argv)
#if HAVE_AFINET || HAVE_AFINET6
if (!strcmp(*spp, "del")) {
if (*++spp == NULL)
usage();
usage(E_OPTERR);
#ifdef SIOCDIFADDR
#if HAVE_AFINET6
......@@ -809,7 +810,7 @@ int main(int argc, char **argv)
if ((cp = strchr(*spp, '/'))) {
prefix_len = atol(cp + 1);
if ((prefix_len < 0) || (prefix_len > 128))
usage();
usage(E_OPTERR);
*cp = 0;
} else {
prefix_len = 128;
......@@ -896,11 +897,11 @@ int main(int argc, char **argv)
#if HAVE_AFINET6
if (!strcmp(*spp, "tunnel")) {
if (*++spp == NULL)
usage();
usage(E_OPTERR);
if ((cp = strchr(*spp, '/'))) {
prefix_len = atol(cp + 1);
if ((prefix_len < 0) || (prefix_len > 128))
usage();
usage(E_OPTERR);
*cp = 0;
} else {
prefix_len = 128;
......@@ -948,11 +949,11 @@ int main(int argc, char **argv)
if (ap->getmask) {
switch (ap->getmask(host, &_samask, NULL)) {
case -1:
usage();
usage(E_OPTERR);
break;
case 1:
if (didnetmask)
usage();
usage(E_OPTERR);
// remeber to set the netmask from samask later
neednetmask = 1;
......
......@@ -23,7 +23,7 @@ extern int resolve_hosts;
#define NEXT_ARG() \
argv++; \
if (--argc <= 0) \
usage();
usage(E_OPTERR);
typedef struct
{
......
......@@ -49,14 +49,14 @@ static void version(void)
exit(E_VERSION);
}
static void usage(void) __attribute__((noreturn));
static void usage(void)
__attribute__((noreturn))
static void usage(int rc)
{
fprintf(stderr, _("Usage: ipmaddr [ add | del ] MULTIADDR dev STRING\n"));
fprintf(stderr, _(" ipmaddr show [ dev STRING ] [ ipv4 | ipv6 | link | all ]\n"));
fprintf(stderr, _(" ipmaddr -V | -version\n"));
exit(E_USAGE);
FILE *fp = rc ? stderr : stdout;
fprintf(fp, _("Usage: ipmaddr [ add | del ] MULTIADDR dev STRING\n"));
fprintf(fp, _(" ipmaddr show [ dev STRING ] [ ipv4 | ipv6 | link | all ]\n"));
fprintf(fp, _(" ipmaddr -V | -version\n"));
exit(rc);
}
static void print_lla(FILE *fp, int len, unsigned char *addr)
......@@ -290,7 +290,7 @@ static int multiaddr_list(int argc, char **argv)
NEXT_ARG();
l = strlen(*argv);
if (l <= 0 || l >= sizeof(filter_dev))
usage();
usage(E_OPTERR);
strncpy(filter_dev, *argv, sizeof (filter_dev));
} else if (strcmp(*argv, "all") == 0) {
filter_family = AF_UNSPEC;
......@@ -303,7 +303,7 @@ static int multiaddr_list(int argc, char **argv)
} else {
l = strlen(*argv);
if (l <= 0 || l >= sizeof(filter_dev))
usage();
usage(E_OPTERR);
strncpy(filter_dev, *argv, sizeof (filter_dev));
}
argv++; argc--;
......@@ -335,18 +335,18 @@ int multiaddr_modify(int cmd, int argc, char **argv)
if (strcmp(*argv, "dev") == 0) {
NEXT_ARG();
if (ifr.ifr_name[0])
usage();
usage(E_OPTERR);
strncpy(ifr.ifr_name, *argv, IFNAMSIZ);
} else {
if (ifr.ifr_hwaddr.sa_data[0])
usage();
usage(E_OPTERR);
if (parse_lla(*argv, ifr.ifr_hwaddr.sa_data) < 0)
usage();
usage(E_OPTERR);
}
argc--; argv++;
}
if (ifr.ifr_name[0] == 0)
usage();
usage(E_OPTERR);
fd = socket(AF_INET, SOCK_DGRAM, 0);
if (fd < 0) {
......@@ -374,7 +374,7 @@ int do_multiaddr(int argc, char **argv)
if (matches(*argv, "list") == 0 || matches(*argv, "show") == 0
|| matches(*argv, "lst") == 0)
return multiaddr_list(argc-1, argv+1);
usage();
usage(E_OPTERR);
}
int preferred_family = AF_UNSPEC;
......@@ -404,13 +404,13 @@ int main(int argc, char **argv)
argc--;
argv++;
if (argc <= 1)
usage();
usage(E_OPTERR);
if (strcmp(argv[1], "inet") == 0)
preferred_family = AF_INET;
else if (strcmp(argv[1], "inet6") == 0)
preferred_family = AF_INET6;
else
usage();
usage(E_OPTERR);
} else if (matches(argv[1], "-stats") == 0 ||
matches(argv[1], "-statistics") == 0) {
++show_stats;
......@@ -418,8 +418,10 @@ int main(int argc, char **argv)
++resolve_hosts;
} else if ((matches(argv[1], "-V") == 0) || matches(argv[1], "--version") == 0) {
version();
} else if ((matches(argv[1], "-h") == 0) || matches(argv[1], "--help") == 0) {
usage(E_USAGE);
} else
usage();
usage(E_OPTERR);
argc--; argv++;
}
......
......@@ -75,21 +75,21 @@ static void version(void)
exit(E_VERSION);
}
static void usage(void) __attribute__((noreturn));
static void usage(void)
__attribute__((noreturn))
static void usage(int rc)
{
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"));
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"));
fprintf(stderr, _(" TTL := { 1..255 | inherit }\n"));
fprintf(stderr, _(" KEY := { DOTTED_QUAD | NUMBER }\n"));
exit(E_USAGE);
FILE *fp = rc ? stderr : stdout;
fprintf(fp, _("Usage: iptunnel { add | change | del | show } [ NAME ]\n"));
fprintf(fp, _(" [ mode { ipip | gre | sit } ] [ remote ADDR ] [ local ADDR ]\n"));
fprintf(fp, _(" [ [i|o]seq ] [ [i|o]key KEY ] [ [i|o]csum ]\n"));
fprintf(fp, _(" [ ttl TTL ] [ tos TOS ] [ nopmtudisc ] [ dev PHYS_DEV ]\n"));
fprintf(fp, _(" iptunnel -V | --version\n\n"));
fprintf(fp, _("Where: NAME := STRING\n"));
fprintf(fp, _(" ADDR := { IP_ADDRESS | any }\n"));
fprintf(fp, _(" TOS := { NUMBER | inherit }\n"));
fprintf(fp, _(" TTL := { 1..255 | inherit }\n"));
fprintf(fp, _(" KEY := { DOTTED_QUAD | NUMBER }\n"));
exit(rc);
}
static int do_ioctl_get_ifindex(char *dev)
......@@ -216,18 +216,18 @@ static int parse_args(int argc, char **argv, struct ip_tunnel_parm *p)
NEXT_ARG();
if (strcmp(*argv, "ipip") == 0) {
if (p->iph.protocol)
usage();
usage(E_OPTERR);
p->iph.protocol = IPPROTO_IPIP;
} else if (strcmp(*argv, "gre") == 0) {
if (p->iph.protocol)
usage();
usage(E_OPTERR);
p->iph.protocol = IPPROTO_GRE;
} else if (strcmp(*argv, "sit") == 0) {
if (p->iph.protocol)
usage();
usage(E_OPTERR);
p->iph.protocol = IPPROTO_IPV6;
} else
usage();
usage(E_OPTERR);
} else if (strcmp(*argv, "key") == 0) {
unsigned uval;
NEXT_ARG();
......@@ -237,7 +237,7 @@ static int parse_args(int argc, char **argv, struct ip_tunnel_parm *p)
p->i_key = p->o_key = get_addr32(*argv);
else {
if (scan_number(*argv, &uval)<0)
usage();
usage(E_OPTERR);
p->i_key = p->o_key = htonl(uval);
}
} else if (strcmp(*argv, "ikey") == 0) {
......@@ -248,7 +248,7 @@ static int parse_args(int argc, char **argv, struct ip_tunnel_parm *p)
p->o_key = get_addr32(*argv);
else {
if (scan_number(*argv, &uval)<0)
usage();
usage(E_OPTERR);
p->i_key = htonl(uval);
}
} else if (strcmp(*argv, "okey") == 0) {
......@@ -259,7 +259,7 @@ static int parse_args(int argc, char **argv, struct ip_tunnel_parm *p)
p->o_key = get_addr32(*argv);
else {
if (scan_number(*argv, &uval)<0)
usage();
usage(E_OPTERR);
p->o_key = htonl(uval);
}
} else if (strcmp(*argv, "seq") == 0) {
......@@ -294,9 +294,9 @@ static int parse_args(int argc, char **argv, struct ip_tunnel_parm *p)
NEXT_ARG();
if (strcmp(*argv, "inherit") != 0) {
if (scan_number(*argv, &uval)<0)
usage();
usage(E_OPTERR);
if (uval > 255)
usage();
usage(E_OPTERR);
p->iph.ttl = uval;
}
} else if (strcmp(*argv, "tos") == 0) {
......@@ -304,15 +304,15 @@ static int parse_args(int argc, char **argv, struct ip_tunnel_parm *p)
NEXT_ARG();
if (strcmp(*argv, "inherit") != 0) {
if (scan_number(*argv, &uval)<0)
usage();
usage(E_OPTERR);
if (uval > 255)
usage();
usage(E_OPTERR);
p->iph.tos = uval;
} else
p->iph.tos = 1;
} else {
if (p->name[0])
usage();
usage(E_OPTERR);
safe_strncpy(p->name, *argv, IFNAMSIZ);
}
argc--; argv++;
......@@ -573,7 +573,7 @@ int do_iptunnel(int argc, char **argv)
} else
return do_show(0, NULL);
usage();
usage(E_OPTERR);
}
......@@ -604,13 +604,13 @@ int main(int argc, char **argv)
argc--;
argv++;
if (argc <= 1)
usage();
usage(E_OPTERR);
if (strcmp(argv[1], "inet") == 0)
preferred_family = AF_INET;
else if (strcmp(argv[1], "inet6") == 0)
preferred_family = AF_INET6;
else
usage();
usage(E_OPTERR);
} else if (matches(argv[1], "-stats") == 0 ||
matches(argv[1], "-statistics") == 0) {
++show_stats;
......@@ -618,8 +618,10 @@ int main(int argc, char **argv)
++resolve_hosts;