Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1 | /* |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 2 | * stolen from net-tools-1.59 and stripped down for busybox by |
Eric Andersen | cb81e64 | 2003-07-14 21:21:08 +0000 | [diff] [blame] | 3 | * Erik Andersen <andersen@codepoet.org> |
Eric Andersen | bdfd0d7 | 2001-10-24 05:00:29 +0000 | [diff] [blame] | 4 | * |
| 5 | * Heavily modified by Manuel Novoa III Mar 12, 2001 |
| 6 | * |
| 7 | * Pruned unused code using KEEP_UNUSED define. |
| 8 | * Added print_bytes_scaled function to reduce code size. |
| 9 | * Added some (potentially) missing defines. |
| 10 | * Improved display support for -a and for a named interface. |
| 11 | * |
| 12 | * ----------------------------------------------------------- |
| 13 | * |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 14 | * ifconfig This file contains an implementation of the command |
| 15 | * that either displays or sets the characteristics of |
| 16 | * one or more of the system's networking interfaces. |
| 17 | * |
Eric Andersen | 6fea732 | 2004-08-26 21:45:21 +0000 | [diff] [blame] | 18 | * Version: $Id: interface.c,v 1.25 2004/08/26 21:45:21 andersen Exp $ |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 19 | * |
| 20 | * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> |
| 21 | * and others. Copyright 1993 MicroWalt Corporation |
| 22 | * |
| 23 | * This program is free software; you can redistribute it |
| 24 | * and/or modify it under the terms of the GNU General |
| 25 | * Public License as published by the Free Software |
| 26 | * Foundation; either version 2 of the License, or (at |
| 27 | * your option) any later version. |
| 28 | * |
| 29 | * Patched to support 'add' and 'del' keywords for INET(4) addresses |
| 30 | * by Mrs. Brisby <mrs.brisby@nimh.org> |
| 31 | * |
| 32 | * {1.34} - 19980630 - Arnaldo Carvalho de Melo <acme@conectiva.com.br> |
| 33 | * - gettext instead of catgets for i18n |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 34 | * 10/1998 - Andi Kleen. Use interface list primitives. |
| 35 | * 20001008 - Bernd Eckenfels, Patch from RH for setting mtu |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 36 | * (default AF was wrong) |
Manuel Novoa III | 68ea1d0 | 2001-03-12 09:57:59 +0000 | [diff] [blame] | 37 | */ |
| 38 | |
| 39 | /* #define KEEP_UNUSED */ |
| 40 | |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 41 | /* |
| 42 | * |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 43 | * Protocol Families. |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 44 | * |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 45 | */ |
| 46 | #define HAVE_AFINET 1 |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 47 | #undef HAVE_AFIPX |
| 48 | #undef HAVE_AFATALK |
| 49 | #undef HAVE_AFNETROM |
| 50 | #undef HAVE_AFX25 |
| 51 | #undef HAVE_AFECONET |
Eric Andersen | 8b113f9 | 2001-06-01 21:47:15 +0000 | [diff] [blame] | 52 | #undef HAVE_AFASH |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 53 | |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 54 | /* |
| 55 | * |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 56 | * Device Hardware types. |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 57 | * |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 58 | */ |
| 59 | #define HAVE_HWETHER 1 |
| 60 | #define HAVE_HWPPP 1 |
| 61 | #undef HAVE_HWSLIP |
| 62 | |
| 63 | |
Eric Andersen | cd8c436 | 2001-11-10 11:22:46 +0000 | [diff] [blame] | 64 | #include "inet_common.h" |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 65 | #include <stdio.h> |
| 66 | #include <errno.h> |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 67 | #include <stdlib.h> |
| 68 | #include <string.h> |
| 69 | #include <unistd.h> |
Eric Andersen | cd8c436 | 2001-11-10 11:22:46 +0000 | [diff] [blame] | 70 | #include <fcntl.h> |
| 71 | #include <ctype.h> |
| 72 | #include <sys/ioctl.h> |
Eric Andersen | 85e5e72 | 2003-07-22 08:56:55 +0000 | [diff] [blame] | 73 | #include <sys/types.h> |
Eric Andersen | cd8c436 | 2001-11-10 11:22:46 +0000 | [diff] [blame] | 74 | #include <net/if.h> |
| 75 | #include <net/if_arp.h> |
Glenn L McGrath | 6b8c550 | 2001-05-05 03:19:12 +0000 | [diff] [blame] | 76 | #include "libbb.h" |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 77 | |
Glenn L McGrath | b54a748 | 2003-08-29 11:34:08 +0000 | [diff] [blame] | 78 | #ifdef CONFIG_FEATURE_IPV6 |
| 79 | # define HAVE_AFINET6 1 |
| 80 | #else |
| 81 | # undef HAVE_AFINET6 |
| 82 | #endif |
| 83 | |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 84 | #define _(x) x |
| 85 | #define _PATH_PROCNET_DEV "/proc/net/dev" |
Eric Andersen | 51b8bd6 | 2002-07-03 11:46:38 +0000 | [diff] [blame] | 86 | #define _PATH_PROCNET_IFINET6 "/proc/net/if_inet6" |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 87 | #define new(p) ((p) = xcalloc(1,sizeof(*(p)))) |
Eric Andersen | 8b113f9 | 2001-06-01 21:47:15 +0000 | [diff] [blame] | 88 | #define KRELEASE(maj,min,patch) ((maj) * 65536 + (min)*256 + (patch)) |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 89 | |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 90 | #ifdef HAVE_HWSLIP |
Eric Andersen | ab4e19a | 2003-01-14 08:54:08 +0000 | [diff] [blame] | 91 | #include <net/if_slip.h> |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 92 | #endif |
| 93 | |
| 94 | #if HAVE_AFINET6 |
| 95 | |
| 96 | #ifndef _LINUX_IN6_H |
| 97 | /* |
| 98 | * This is in linux/include/net/ipv6.h. |
| 99 | */ |
| 100 | |
| 101 | struct in6_ifreq { |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 102 | struct in6_addr ifr6_addr; |
Glenn L McGrath | b54a748 | 2003-08-29 11:34:08 +0000 | [diff] [blame] | 103 | uint32_t ifr6_prefixlen; |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 104 | unsigned int ifr6_ifindex; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 105 | }; |
| 106 | |
| 107 | #endif |
| 108 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 109 | #endif /* HAVE_AFINET6 */ |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 110 | |
| 111 | #if HAVE_AFIPX |
Eric Andersen | b6b519b | 2001-04-09 23:52:18 +0000 | [diff] [blame] | 112 | #if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1) |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 113 | #include <netipx/ipx.h> |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 114 | #endif |
| 115 | #endif |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 116 | |
Manuel Novoa III | 68ea1d0 | 2001-03-12 09:57:59 +0000 | [diff] [blame] | 117 | /* Defines for glibc2.0 users. */ |
| 118 | #ifndef SIOCSIFTXQLEN |
| 119 | #define SIOCSIFTXQLEN 0x8943 |
| 120 | #define SIOCGIFTXQLEN 0x8942 |
| 121 | #endif |
| 122 | |
| 123 | /* ifr_qlen is ifru_ivalue, but it isn't present in 2.0 kernel headers */ |
| 124 | #ifndef ifr_qlen |
| 125 | #define ifr_qlen ifr_ifru.ifru_mtu |
| 126 | #endif |
| 127 | |
| 128 | #ifndef HAVE_TXQUEUELEN |
| 129 | #define HAVE_TXQUEUELEN 1 |
| 130 | #endif |
| 131 | |
| 132 | #ifndef IFF_DYNAMIC |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 133 | #define IFF_DYNAMIC 0x8000 /* dialup device with changing addresses */ |
Manuel Novoa III | 68ea1d0 | 2001-03-12 09:57:59 +0000 | [diff] [blame] | 134 | #endif |
| 135 | |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 136 | /* This structure defines protocol families and their handlers. */ |
| 137 | struct aftype { |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 138 | const char *name; |
| 139 | const char *title; |
| 140 | int af; |
| 141 | int alen; |
| 142 | char *(*print) (unsigned char *); |
| 143 | char *(*sprint) (struct sockaddr *, int numeric); |
| 144 | int (*input) (int type, char *bufp, struct sockaddr *); |
| 145 | void (*herror) (char *text); |
| 146 | int (*rprint) (int options); |
| 147 | int (*rinput) (int typ, int ext, char **argv); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 148 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 149 | /* may modify src */ |
| 150 | int (*getmask) (char *src, struct sockaddr * mask, char *name); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 151 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 152 | int fd; |
| 153 | char *flag_file; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 154 | }; |
| 155 | |
Manuel Novoa III | 68ea1d0 | 2001-03-12 09:57:59 +0000 | [diff] [blame] | 156 | #ifdef KEEP_UNUSED |
| 157 | |
| 158 | static int flag_unx; |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 159 | |
Eric Andersen | 8b113f9 | 2001-06-01 21:47:15 +0000 | [diff] [blame] | 160 | #ifdef HAVE_AFIPX |
Manuel Novoa III | 68ea1d0 | 2001-03-12 09:57:59 +0000 | [diff] [blame] | 161 | static int flag_ipx; |
Eric Andersen | 8b113f9 | 2001-06-01 21:47:15 +0000 | [diff] [blame] | 162 | #endif |
| 163 | #ifdef HAVE_AFX25 |
Manuel Novoa III | 68ea1d0 | 2001-03-12 09:57:59 +0000 | [diff] [blame] | 164 | static int flag_ax25; |
Eric Andersen | 8b113f9 | 2001-06-01 21:47:15 +0000 | [diff] [blame] | 165 | #endif |
| 166 | #ifdef HAVE_AFATALK |
Manuel Novoa III | 68ea1d0 | 2001-03-12 09:57:59 +0000 | [diff] [blame] | 167 | static int flag_ddp; |
Eric Andersen | 8b113f9 | 2001-06-01 21:47:15 +0000 | [diff] [blame] | 168 | #endif |
| 169 | #ifdef HAVE_AFNETROM |
Manuel Novoa III | 68ea1d0 | 2001-03-12 09:57:59 +0000 | [diff] [blame] | 170 | static int flag_netrom; |
Eric Andersen | 8b113f9 | 2001-06-01 21:47:15 +0000 | [diff] [blame] | 171 | #endif |
Manuel Novoa III | 68ea1d0 | 2001-03-12 09:57:59 +0000 | [diff] [blame] | 172 | static int flag_inet; |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 173 | |
Eric Andersen | 8b113f9 | 2001-06-01 21:47:15 +0000 | [diff] [blame] | 174 | #ifdef HAVE_AFINET6 |
Manuel Novoa III | 68ea1d0 | 2001-03-12 09:57:59 +0000 | [diff] [blame] | 175 | static int flag_inet6; |
Eric Andersen | 8b113f9 | 2001-06-01 21:47:15 +0000 | [diff] [blame] | 176 | #endif |
| 177 | #ifdef HAVE_AFECONET |
Manuel Novoa III | 68ea1d0 | 2001-03-12 09:57:59 +0000 | [diff] [blame] | 178 | static int flag_econet; |
Eric Andersen | 8b113f9 | 2001-06-01 21:47:15 +0000 | [diff] [blame] | 179 | #endif |
| 180 | #ifdef HAVE_AFX25 |
Manuel Novoa III | 68ea1d0 | 2001-03-12 09:57:59 +0000 | [diff] [blame] | 181 | static int flag_x25 = 0; |
Eric Andersen | 8b113f9 | 2001-06-01 21:47:15 +0000 | [diff] [blame] | 182 | #endif |
| 183 | #ifdef HAVE_AFASH |
Manuel Novoa III | 68ea1d0 | 2001-03-12 09:57:59 +0000 | [diff] [blame] | 184 | static int flag_ash; |
Eric Andersen | 8b113f9 | 2001-06-01 21:47:15 +0000 | [diff] [blame] | 185 | #endif |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 186 | |
| 187 | |
Manuel Novoa III | 68ea1d0 | 2001-03-12 09:57:59 +0000 | [diff] [blame] | 188 | static struct aftrans_t { |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 189 | char *alias; |
| 190 | char *name; |
| 191 | int *flag; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 192 | } aftrans[] = { |
| 193 | |
Eric Andersen | 8b113f9 | 2001-06-01 21:47:15 +0000 | [diff] [blame] | 194 | #ifdef HAVE_AFX25 |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 195 | { |
| 196 | "ax25", "ax25", &flag_ax25}, |
Eric Andersen | 8b113f9 | 2001-06-01 21:47:15 +0000 | [diff] [blame] | 197 | #endif |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 198 | { |
| 199 | "ip", "inet", &flag_inet}, |
Eric Andersen | 8b113f9 | 2001-06-01 21:47:15 +0000 | [diff] [blame] | 200 | #ifdef HAVE_AFINET6 |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 201 | { |
| 202 | "ip6", "inet6", &flag_inet6}, |
Eric Andersen | 8b113f9 | 2001-06-01 21:47:15 +0000 | [diff] [blame] | 203 | #endif |
| 204 | #ifdef HAVE_AFIPX |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 205 | { |
| 206 | "ipx", "ipx", &flag_ipx}, |
Eric Andersen | 8b113f9 | 2001-06-01 21:47:15 +0000 | [diff] [blame] | 207 | #endif |
| 208 | #ifdef HAVE_AFATALK |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 209 | { |
| 210 | "appletalk", "ddp", &flag_ddp}, |
Eric Andersen | 8b113f9 | 2001-06-01 21:47:15 +0000 | [diff] [blame] | 211 | #endif |
| 212 | #ifdef HAVE_AFNETROM |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 213 | { |
| 214 | "netrom", "netrom", &flag_netrom}, |
Eric Andersen | 8b113f9 | 2001-06-01 21:47:15 +0000 | [diff] [blame] | 215 | #endif |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 216 | { |
| 217 | "inet", "inet", &flag_inet}, |
Eric Andersen | 8b113f9 | 2001-06-01 21:47:15 +0000 | [diff] [blame] | 218 | #ifdef HAVE_AFINET6 |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 219 | { |
| 220 | "inet6", "inet6", &flag_inet6}, |
Eric Andersen | 8b113f9 | 2001-06-01 21:47:15 +0000 | [diff] [blame] | 221 | #endif |
| 222 | #ifdef HAVE_AFATALK |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 223 | { |
| 224 | "ddp", "ddp", &flag_ddp}, |
Eric Andersen | 8b113f9 | 2001-06-01 21:47:15 +0000 | [diff] [blame] | 225 | #endif |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 226 | { |
| 227 | "unix", "unix", &flag_unx}, { |
| 228 | "tcpip", "inet", &flag_inet}, |
Eric Andersen | 8b113f9 | 2001-06-01 21:47:15 +0000 | [diff] [blame] | 229 | #ifdef HAVE_AFECONET |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 230 | { |
| 231 | "econet", "ec", &flag_econet}, |
Eric Andersen | 8b113f9 | 2001-06-01 21:47:15 +0000 | [diff] [blame] | 232 | #endif |
| 233 | #ifdef HAVE_AFX25 |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 234 | { |
| 235 | "x25", "x25", &flag_x25}, |
Eric Andersen | 8b113f9 | 2001-06-01 21:47:15 +0000 | [diff] [blame] | 236 | #endif |
| 237 | #ifdef HAVE_AFASH |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 238 | { |
| 239 | "ash", "ash", &flag_ash}, |
Eric Andersen | 8b113f9 | 2001-06-01 21:47:15 +0000 | [diff] [blame] | 240 | #endif |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 241 | { |
| 242 | 0, 0, 0} |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 243 | }; |
| 244 | |
Manuel Novoa III | 68ea1d0 | 2001-03-12 09:57:59 +0000 | [diff] [blame] | 245 | static char afname[256] = ""; |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 246 | #endif /* KEEP_UNUSED */ |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 247 | |
| 248 | #if HAVE_AFUNIX |
| 249 | |
| 250 | /* Display a UNIX domain address. */ |
| 251 | static char *UNIX_print(unsigned char *ptr) |
| 252 | { |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 253 | return (ptr); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | |
| 257 | /* Display a UNIX domain address. */ |
| 258 | static char *UNIX_sprint(struct sockaddr *sap, int numeric) |
| 259 | { |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 260 | static char buf[64]; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 261 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 262 | if (sap->sa_family == 0xFFFF || sap->sa_family == 0) |
| 263 | return safe_strncpy(buf, _("[NONE SET]"), sizeof(buf)); |
| 264 | return (UNIX_print(sap->sa_data)); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 268 | static struct aftype unix_aftype = { |
| 269 | "unix", "UNIX Domain", AF_UNIX, 0, |
| 270 | UNIX_print, UNIX_sprint, NULL, NULL, |
| 271 | NULL, NULL, NULL, |
| 272 | -1, |
| 273 | "/proc/net/unix" |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 274 | }; |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 275 | #endif /* HAVE_AFUNIX */ |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 276 | |
| 277 | #if HAVE_AFINET |
| 278 | |
Manuel Novoa III | 68ea1d0 | 2001-03-12 09:57:59 +0000 | [diff] [blame] | 279 | #ifdef KEEP_UNUSED |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 280 | static void INET_reserror(char *text) |
| 281 | { |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 282 | herror(text); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 283 | } |
| 284 | |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 285 | /* Display an Internet socket address. */ |
| 286 | static char *INET_print(unsigned char *ptr) |
| 287 | { |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 288 | return (inet_ntoa((*(struct in_addr *) ptr))); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 289 | } |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 290 | #endif /* KEEP_UNUSED */ |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 291 | |
| 292 | /* Display an Internet socket address. */ |
| 293 | static char *INET_sprint(struct sockaddr *sap, int numeric) |
| 294 | { |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 295 | static char buff[128]; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 296 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 297 | if (sap->sa_family == 0xFFFF || sap->sa_family == 0) |
| 298 | return safe_strncpy(buff, _("[NONE SET]"), sizeof(buff)); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 299 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 300 | if (INET_rresolve(buff, sizeof(buff), (struct sockaddr_in *) sap, |
| 301 | numeric, 0xffffff00) != 0) |
| 302 | return (NULL); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 303 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 304 | return (buff); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 305 | } |
| 306 | |
Manuel Novoa III | 68ea1d0 | 2001-03-12 09:57:59 +0000 | [diff] [blame] | 307 | #ifdef KEEP_UNUSED |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 308 | static char *INET_sprintmask(struct sockaddr *sap, int numeric, |
| 309 | unsigned int netmask) |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 310 | { |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 311 | static char buff[128]; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 312 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 313 | if (sap->sa_family == 0xFFFF || sap->sa_family == 0) |
| 314 | return safe_strncpy(buff, _("[NONE SET]"), sizeof(buff)); |
| 315 | if (INET_rresolve(buff, sizeof(buff), (struct sockaddr_in *) sap, |
| 316 | numeric, netmask) != 0) |
| 317 | return (NULL); |
| 318 | return (buff); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 319 | } |
| 320 | |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 321 | static int INET_getsock(char *bufp, struct sockaddr *sap) |
| 322 | { |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 323 | char *sp = bufp, *bp; |
| 324 | unsigned int i; |
| 325 | unsigned val; |
| 326 | struct sockaddr_in *sin; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 327 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 328 | sin = (struct sockaddr_in *) sap; |
| 329 | sin->sin_family = AF_INET; |
| 330 | sin->sin_port = 0; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 331 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 332 | val = 0; |
| 333 | bp = (char *) &val; |
| 334 | for (i = 0; i < sizeof(sin->sin_addr.s_addr); i++) { |
| 335 | *sp = toupper(*sp); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 336 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 337 | if ((*sp >= 'A') && (*sp <= 'F')) |
| 338 | bp[i] |= (int) (*sp - 'A') + 10; |
| 339 | else if ((*sp >= '0') && (*sp <= '9')) |
| 340 | bp[i] |= (int) (*sp - '0'); |
| 341 | else |
| 342 | return (-1); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 343 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 344 | bp[i] <<= 4; |
| 345 | sp++; |
| 346 | *sp = toupper(*sp); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 347 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 348 | if ((*sp >= 'A') && (*sp <= 'F')) |
| 349 | bp[i] |= (int) (*sp - 'A') + 10; |
| 350 | else if ((*sp >= '0') && (*sp <= '9')) |
| 351 | bp[i] |= (int) (*sp - '0'); |
| 352 | else |
| 353 | return (-1); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 354 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 355 | sp++; |
| 356 | } |
| 357 | sin->sin_addr.s_addr = htonl(val); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 358 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 359 | return (sp - bufp); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | static int INET_input(int type, char *bufp, struct sockaddr *sap) |
| 363 | { |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 364 | switch (type) { |
| 365 | case 1: |
| 366 | return (INET_getsock(bufp, sap)); |
| 367 | case 256: |
| 368 | return (INET_resolve(bufp, (struct sockaddr_in *) sap, 1)); |
| 369 | default: |
| 370 | return (INET_resolve(bufp, (struct sockaddr_in *) sap, 0)); |
| 371 | } |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | static int INET_getnetmask(char *adr, struct sockaddr *m, char *name) |
| 375 | { |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 376 | struct sockaddr_in *mask = (struct sockaddr_in *) m; |
| 377 | char *slash, *end; |
| 378 | int prefix; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 379 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 380 | if ((slash = strchr(adr, '/')) == NULL) |
| 381 | return 0; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 382 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 383 | *slash++ = '\0'; |
| 384 | prefix = strtoul(slash, &end, 0); |
| 385 | if (*end != '\0') |
| 386 | return -1; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 387 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 388 | if (name) { |
| 389 | sprintf(name, "/%d", prefix); |
| 390 | } |
| 391 | mask->sin_family = AF_INET; |
| 392 | mask->sin_addr.s_addr = htonl(~(0xffffffffU >> prefix)); |
| 393 | return 1; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 394 | } |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 395 | #endif /* KEEP_UNUSED */ |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 396 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 397 | static struct aftype inet_aftype = { |
| 398 | "inet", "DARPA Internet", AF_INET, sizeof(unsigned long), |
| 399 | NULL /* UNUSED INET_print */ , INET_sprint, |
| 400 | NULL /* UNUSED INET_input */ , NULL /* UNUSED INET_reserror */ , |
| 401 | NULL /*INET_rprint */ , NULL /*INET_rinput */ , |
| 402 | NULL /* UNUSED INET_getnetmask */ , |
| 403 | -1, |
| 404 | NULL |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 405 | }; |
| 406 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 407 | #endif /* HAVE_AFINET */ |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 408 | |
Eric Andersen | 51b8bd6 | 2002-07-03 11:46:38 +0000 | [diff] [blame] | 409 | #if HAVE_AFINET6 |
| 410 | |
| 411 | #ifdef KEEP_UNUSED |
| 412 | static void INET6_reserror(char *text) |
| 413 | { |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 414 | herror(text); |
Eric Andersen | 51b8bd6 | 2002-07-03 11:46:38 +0000 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | /* Display an Internet socket address. */ |
| 418 | static char *INET6_print(unsigned char *ptr) |
| 419 | { |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 420 | static char name[80]; |
Eric Andersen | 51b8bd6 | 2002-07-03 11:46:38 +0000 | [diff] [blame] | 421 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 422 | inet_ntop(AF_INET6, (struct in6_addr *) ptr, name, 80); |
| 423 | return name; |
Eric Andersen | 51b8bd6 | 2002-07-03 11:46:38 +0000 | [diff] [blame] | 424 | } |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 425 | #endif /* KEEP_UNUSED */ |
Eric Andersen | 51b8bd6 | 2002-07-03 11:46:38 +0000 | [diff] [blame] | 426 | |
| 427 | /* Display an Internet socket address. */ |
| 428 | /* dirty! struct sockaddr usually doesn't suffer for inet6 addresses, fst. */ |
| 429 | static char *INET6_sprint(struct sockaddr *sap, int numeric) |
| 430 | { |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 431 | static char buff[128]; |
Eric Andersen | 51b8bd6 | 2002-07-03 11:46:38 +0000 | [diff] [blame] | 432 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 433 | if (sap->sa_family == 0xFFFF || sap->sa_family == 0) |
| 434 | return safe_strncpy(buff, _("[NONE SET]"), sizeof(buff)); |
| 435 | if (INET6_rresolve |
| 436 | (buff, sizeof(buff), (struct sockaddr_in6 *) sap, numeric) != 0) |
| 437 | return safe_strncpy(buff, _("[UNKNOWN]"), sizeof(buff)); |
| 438 | return (buff); |
Eric Andersen | 51b8bd6 | 2002-07-03 11:46:38 +0000 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | #ifdef KEEP_UNUSED |
| 442 | static int INET6_getsock(char *bufp, struct sockaddr *sap) |
| 443 | { |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 444 | struct sockaddr_in6 *sin6; |
Eric Andersen | 51b8bd6 | 2002-07-03 11:46:38 +0000 | [diff] [blame] | 445 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 446 | sin6 = (struct sockaddr_in6 *) sap; |
| 447 | sin6->sin6_family = AF_INET6; |
| 448 | sin6->sin6_port = 0; |
Eric Andersen | 51b8bd6 | 2002-07-03 11:46:38 +0000 | [diff] [blame] | 449 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 450 | if (inet_pton(AF_INET6, bufp, sin6->sin6_addr.s6_addr) <= 0) |
| 451 | return (-1); |
Eric Andersen | 51b8bd6 | 2002-07-03 11:46:38 +0000 | [diff] [blame] | 452 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 453 | return 16; /* ?;) */ |
Eric Andersen | 51b8bd6 | 2002-07-03 11:46:38 +0000 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | static int INET6_input(int type, char *bufp, struct sockaddr *sap) |
| 457 | { |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 458 | switch (type) { |
| 459 | case 1: |
| 460 | return (INET6_getsock(bufp, sap)); |
| 461 | default: |
| 462 | return (INET6_resolve(bufp, (struct sockaddr_in6 *) sap)); |
| 463 | } |
Eric Andersen | 51b8bd6 | 2002-07-03 11:46:38 +0000 | [diff] [blame] | 464 | } |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 465 | #endif /* KEEP_UNUSED */ |
Eric Andersen | 51b8bd6 | 2002-07-03 11:46:38 +0000 | [diff] [blame] | 466 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 467 | static struct aftype inet6_aftype = { |
| 468 | "inet6", "IPv6", AF_INET6, sizeof(struct in6_addr), |
| 469 | NULL /* UNUSED INET6_print */ , INET6_sprint, |
| 470 | NULL /* UNUSED INET6_input */ , NULL /* UNUSED INET6_reserror */ , |
| 471 | NULL /*INET6_rprint */ , NULL /*INET6_rinput */ , |
| 472 | NULL /* UNUSED INET6_getnetmask */ , |
| 473 | -1, |
| 474 | NULL |
Eric Andersen | 51b8bd6 | 2002-07-03 11:46:38 +0000 | [diff] [blame] | 475 | }; |
| 476 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 477 | #endif /* HAVE_AFINET6 */ |
Eric Andersen | 51b8bd6 | 2002-07-03 11:46:38 +0000 | [diff] [blame] | 478 | |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 479 | /* Display an UNSPEC address. */ |
| 480 | static char *UNSPEC_print(unsigned char *ptr) |
| 481 | { |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 482 | static char buff[sizeof(struct sockaddr) * 3 + 1]; |
| 483 | char *pos; |
| 484 | unsigned int i; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 485 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 486 | pos = buff; |
| 487 | for (i = 0; i < sizeof(struct sockaddr); i++) { |
| 488 | /* careful -- not every libc's sprintf returns # bytes written */ |
| 489 | sprintf(pos, "%02X-", (*ptr++ & 0377)); |
| 490 | pos += 3; |
| 491 | } |
| 492 | /* Erase trailing "-". Works as long as sizeof(struct sockaddr) != 0 */ |
| 493 | *--pos = '\0'; |
| 494 | return (buff); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | /* Display an UNSPEC socket address. */ |
| 498 | static char *UNSPEC_sprint(struct sockaddr *sap, int numeric) |
| 499 | { |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 500 | static char buf[64]; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 501 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 502 | if (sap->sa_family == 0xFFFF || sap->sa_family == 0) |
| 503 | return safe_strncpy(buf, _("[NONE SET]"), sizeof(buf)); |
| 504 | return (UNSPEC_print(sap->sa_data)); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 505 | } |
| 506 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 507 | static struct aftype unspec_aftype = { |
| 508 | "unspec", "UNSPEC", AF_UNSPEC, 0, |
| 509 | UNSPEC_print, UNSPEC_sprint, NULL, NULL, |
| 510 | NULL, |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 511 | }; |
| 512 | |
"Vladimir N. Oleynik" | 0fa9ded | 2005-10-20 09:48:28 +0000 | [diff] [blame] | 513 | static struct aftype * const aftypes[] = { |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 514 | #if HAVE_AFUNIX |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 515 | &unix_aftype, |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 516 | #endif |
| 517 | #if HAVE_AFINET |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 518 | &inet_aftype, |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 519 | #endif |
| 520 | #if HAVE_AFINET6 |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 521 | &inet6_aftype, |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 522 | #endif |
| 523 | #if HAVE_AFAX25 |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 524 | &ax25_aftype, |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 525 | #endif |
| 526 | #if HAVE_AFNETROM |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 527 | &netrom_aftype, |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 528 | #endif |
| 529 | #if HAVE_AFROSE |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 530 | &rose_aftype, |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 531 | #endif |
| 532 | #if HAVE_AFIPX |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 533 | &ipx_aftype, |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 534 | #endif |
| 535 | #if HAVE_AFATALK |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 536 | &ddp_aftype, |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 537 | #endif |
| 538 | #if HAVE_AFECONET |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 539 | &ec_aftype, |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 540 | #endif |
| 541 | #if HAVE_AFASH |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 542 | &ash_aftype, |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 543 | #endif |
| 544 | #if HAVE_AFX25 |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 545 | &x25_aftype, |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 546 | #endif |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 547 | &unspec_aftype, |
| 548 | NULL |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 549 | }; |
| 550 | |
Manuel Novoa III | 68ea1d0 | 2001-03-12 09:57:59 +0000 | [diff] [blame] | 551 | #ifdef KEEP_UNUSED |
| 552 | static short sVafinit = 0; |
| 553 | |
| 554 | static void afinit() |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 555 | { |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 556 | unspec_aftype.title = _("UNSPEC"); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 557 | #if HAVE_AFUNIX |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 558 | unix_aftype.title = _("UNIX Domain"); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 559 | #endif |
| 560 | #if HAVE_AFINET |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 561 | inet_aftype.title = _("DARPA Internet"); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 562 | #endif |
| 563 | #if HAVE_AFINET6 |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 564 | inet6_aftype.title = _("IPv6"); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 565 | #endif |
| 566 | #if HAVE_AFAX25 |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 567 | ax25_aftype.title = _("AMPR AX.25"); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 568 | #endif |
| 569 | #if HAVE_AFNETROM |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 570 | netrom_aftype.title = _("AMPR NET/ROM"); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 571 | #endif |
| 572 | #if HAVE_AFIPX |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 573 | ipx_aftype.title = _("Novell IPX"); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 574 | #endif |
| 575 | #if HAVE_AFATALK |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 576 | ddp_aftype.title = _("Appletalk DDP"); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 577 | #endif |
| 578 | #if HAVE_AFECONET |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 579 | ec_aftype.title = _("Econet"); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 580 | #endif |
| 581 | #if HAVE_AFX25 |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 582 | x25_aftype.title = _("CCITT X.25"); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 583 | #endif |
| 584 | #if HAVE_AFROSE |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 585 | rose_aftype.title = _("AMPR ROSE"); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 586 | #endif |
| 587 | #if HAVE_AFASH |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 588 | ash_aftype.title = _("Ash"); |
| 589 | #endif |
| 590 | sVafinit = 1; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 591 | } |
| 592 | |
Manuel Novoa III | 68ea1d0 | 2001-03-12 09:57:59 +0000 | [diff] [blame] | 593 | static int aftrans_opt(const char *arg) |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 594 | { |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 595 | struct aftrans_t *paft; |
| 596 | char *tmp1, *tmp2; |
| 597 | char buf[256]; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 598 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 599 | safe_strncpy(buf, arg, sizeof(buf)); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 600 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 601 | tmp1 = buf; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 602 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 603 | while (tmp1) { |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 604 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 605 | tmp2 = strchr(tmp1, ','); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 606 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 607 | if (tmp2) |
| 608 | *(tmp2++) = '\0'; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 609 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 610 | paft = aftrans; |
| 611 | for (paft = aftrans; paft->alias; paft++) { |
| 612 | if (strcmp(tmp1, paft->alias)) |
| 613 | continue; |
| 614 | if (strlen(paft->name) + strlen(afname) + 1 >= sizeof(afname)) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 615 | bb_error_msg(_("Too many address family arguments.")); |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 616 | return (0); |
| 617 | } |
| 618 | if (paft->flag) |
| 619 | (*paft->flag)++; |
| 620 | if (afname[0]) |
| 621 | strcat(afname, ","); |
| 622 | strcat(afname, paft->name); |
| 623 | break; |
| 624 | } |
| 625 | if (!paft->alias) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 626 | bb_error_msg(_("Unknown address family `%s'."), tmp1); |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 627 | return (1); |
| 628 | } |
| 629 | tmp1 = tmp2; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 630 | } |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 631 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 632 | return (0); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | /* set the default AF list from the program name or a constant value */ |
Manuel Novoa III | 68ea1d0 | 2001-03-12 09:57:59 +0000 | [diff] [blame] | 636 | static void aftrans_def(char *tool, char *argv0, char *dflt) |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 637 | { |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 638 | char *tmp; |
| 639 | char *buf; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 640 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 641 | strcpy(afname, dflt); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 642 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 643 | if (!(tmp = strrchr(argv0, '/'))) |
| 644 | tmp = argv0; /* no slash?! */ |
| 645 | else |
| 646 | tmp++; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 647 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 648 | if (!(buf = strdup(tmp))) |
| 649 | return; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 650 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 651 | if (strlen(tool) >= strlen(tmp)) { |
| 652 | free(buf); |
| 653 | return; |
| 654 | } |
| 655 | tmp = buf + (strlen(tmp) - strlen(tool)); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 656 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 657 | if (strcmp(tmp, tool) != 0) { |
| 658 | free(buf); |
| 659 | return; |
| 660 | } |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 661 | *tmp = '\0'; |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 662 | if ((tmp = strchr(buf, '_'))) |
| 663 | *tmp = '\0'; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 664 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 665 | afname[0] = '\0'; |
| 666 | if (aftrans_opt(buf)) |
| 667 | strcpy(afname, buf); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 668 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 669 | free(buf); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 670 | } |
| 671 | |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 672 | /* Check our protocol family table for this family. */ |
Manuel Novoa III | 68ea1d0 | 2001-03-12 09:57:59 +0000 | [diff] [blame] | 673 | static struct aftype *get_aftype(const char *name) |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 674 | { |
"Vladimir N. Oleynik" | 0fa9ded | 2005-10-20 09:48:28 +0000 | [diff] [blame] | 675 | struct aftype * const *afp; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 676 | |
Manuel Novoa III | 68ea1d0 | 2001-03-12 09:57:59 +0000 | [diff] [blame] | 677 | #ifdef KEEP_UNUSED |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 678 | if (!sVafinit) |
| 679 | afinit(); |
| 680 | #endif /* KEEP_UNUSED */ |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 681 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 682 | afp = aftypes; |
| 683 | while (*afp != NULL) { |
| 684 | if (!strcmp((*afp)->name, name)) |
| 685 | return (*afp); |
| 686 | afp++; |
| 687 | } |
| 688 | if (strchr(name, ',')) |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 689 | bb_error_msg(_("Please don't supply more than one address family.")); |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 690 | return (NULL); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 691 | } |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 692 | #endif /* KEEP_UNUSED */ |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 693 | |
| 694 | /* Check our protocol family table for this family. */ |
Manuel Novoa III | 68ea1d0 | 2001-03-12 09:57:59 +0000 | [diff] [blame] | 695 | static struct aftype *get_afntype(int af) |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 696 | { |
"Vladimir N. Oleynik" | 0fa9ded | 2005-10-20 09:48:28 +0000 | [diff] [blame] | 697 | struct aftype * const *afp; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 698 | |
Manuel Novoa III | 68ea1d0 | 2001-03-12 09:57:59 +0000 | [diff] [blame] | 699 | #ifdef KEEP_UNUSED |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 700 | if (!sVafinit) |
| 701 | afinit(); |
| 702 | #endif /* KEEP_UNUSED */ |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 703 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 704 | afp = aftypes; |
| 705 | while (*afp != NULL) { |
| 706 | if ((*afp)->af == af) |
| 707 | return (*afp); |
| 708 | afp++; |
| 709 | } |
| 710 | return (NULL); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | /* Check our protocol family table for this family and return its socket */ |
Manuel Novoa III | 68ea1d0 | 2001-03-12 09:57:59 +0000 | [diff] [blame] | 714 | static int get_socket_for_af(int af) |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 715 | { |
"Vladimir N. Oleynik" | 0fa9ded | 2005-10-20 09:48:28 +0000 | [diff] [blame] | 716 | struct aftype * const *afp; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 717 | |
Manuel Novoa III | 68ea1d0 | 2001-03-12 09:57:59 +0000 | [diff] [blame] | 718 | #ifdef KEEP_UNUSED |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 719 | if (!sVafinit) |
| 720 | afinit(); |
| 721 | #endif /* KEEP_UNUSED */ |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 722 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 723 | afp = aftypes; |
| 724 | while (*afp != NULL) { |
| 725 | if ((*afp)->af == af) |
| 726 | return (*afp)->fd; |
| 727 | afp++; |
| 728 | } |
| 729 | return -1; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 730 | } |
| 731 | |
Manuel Novoa III | 68ea1d0 | 2001-03-12 09:57:59 +0000 | [diff] [blame] | 732 | #ifdef KEEP_UNUSED |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 733 | /* type: 0=all, 1=getroute */ |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 734 | static void print_aflist(int type) |
| 735 | { |
| 736 | int count = 0; |
| 737 | char *txt; |
"Vladimir N. Oleynik" | 0fa9ded | 2005-10-20 09:48:28 +0000 | [diff] [blame] | 738 | struct aftype * const *afp; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 739 | |
Manuel Novoa III | 68ea1d0 | 2001-03-12 09:57:59 +0000 | [diff] [blame] | 740 | #ifdef KEEP_UNUSED |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 741 | if (!sVafinit) |
| 742 | afinit(); |
| 743 | #endif /* KEEP_UNUSED */ |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 744 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 745 | afp = aftypes; |
| 746 | while (*afp != NULL) { |
| 747 | if ((type == 1 && ((*afp)->rprint == NULL)) || ((*afp)->af == 0)) { |
| 748 | afp++; |
| 749 | continue; |
| 750 | } |
| 751 | if ((count % 3) == 0) |
| 752 | fprintf(stderr, count ? "\n " : " "); |
| 753 | txt = (*afp)->name; |
| 754 | if (!txt) |
| 755 | txt = ".."; |
| 756 | fprintf(stderr, "%s (%s) ", txt, _((*afp)->title)); |
| 757 | count++; |
| 758 | afp++; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 759 | } |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 760 | fprintf(stderr, "\n"); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 761 | } |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 762 | #endif /* KEEP_UNUSED */ |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 763 | |
| 764 | struct user_net_device_stats { |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 765 | unsigned long long rx_packets; /* total packets received */ |
| 766 | unsigned long long tx_packets; /* total packets transmitted */ |
| 767 | unsigned long long rx_bytes; /* total bytes received */ |
| 768 | unsigned long long tx_bytes; /* total bytes transmitted */ |
| 769 | unsigned long rx_errors; /* bad packets received */ |
| 770 | unsigned long tx_errors; /* packet transmit problems */ |
| 771 | unsigned long rx_dropped; /* no space in linux buffers */ |
| 772 | unsigned long tx_dropped; /* no space available in linux */ |
| 773 | unsigned long rx_multicast; /* multicast packets received */ |
| 774 | unsigned long rx_compressed; |
| 775 | unsigned long tx_compressed; |
| 776 | unsigned long collisions; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 777 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 778 | /* detailed rx_errors: */ |
| 779 | unsigned long rx_length_errors; |
| 780 | unsigned long rx_over_errors; /* receiver ring buff overflow */ |
| 781 | unsigned long rx_crc_errors; /* recved pkt with crc error */ |
| 782 | unsigned long rx_frame_errors; /* recv'd frame alignment error */ |
| 783 | unsigned long rx_fifo_errors; /* recv'r fifo overrun */ |
| 784 | unsigned long rx_missed_errors; /* receiver missed packet */ |
| 785 | /* detailed tx_errors */ |
| 786 | unsigned long tx_aborted_errors; |
| 787 | unsigned long tx_carrier_errors; |
| 788 | unsigned long tx_fifo_errors; |
| 789 | unsigned long tx_heartbeat_errors; |
| 790 | unsigned long tx_window_errors; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 791 | }; |
| 792 | |
| 793 | struct interface { |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 794 | struct interface *next, *prev; |
| 795 | char name[IFNAMSIZ]; /* interface name */ |
| 796 | short type; /* if type */ |
| 797 | short flags; /* various flags */ |
| 798 | int metric; /* routing metric */ |
| 799 | int mtu; /* MTU value */ |
| 800 | int tx_queue_len; /* transmit queue length */ |
| 801 | struct ifmap map; /* hardware setup */ |
| 802 | struct sockaddr addr; /* IP address */ |
| 803 | struct sockaddr dstaddr; /* P-P IP address */ |
| 804 | struct sockaddr broadaddr; /* IP broadcast address */ |
| 805 | struct sockaddr netmask; /* IP network mask */ |
| 806 | struct sockaddr ipxaddr_bb; /* IPX network address */ |
| 807 | struct sockaddr ipxaddr_sn; /* IPX network address */ |
| 808 | struct sockaddr ipxaddr_e3; /* IPX network address */ |
| 809 | struct sockaddr ipxaddr_e2; /* IPX network address */ |
| 810 | struct sockaddr ddpaddr; /* Appletalk DDP address */ |
| 811 | struct sockaddr ecaddr; /* Econet address */ |
| 812 | int has_ip; |
| 813 | int has_ipx_bb; |
| 814 | int has_ipx_sn; |
| 815 | int has_ipx_e3; |
| 816 | int has_ipx_e2; |
| 817 | int has_ax25; |
| 818 | int has_ddp; |
| 819 | int has_econet; |
| 820 | char hwaddr[32]; /* HW address */ |
| 821 | int statistics_valid; |
| 822 | struct user_net_device_stats stats; /* statistics */ |
| 823 | int keepalive; /* keepalive value for SLIP */ |
| 824 | int outfill; /* outfill value for SLIP */ |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 825 | }; |
| 826 | |
| 827 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 828 | int interface_opt_a = 0; /* show all interfaces */ |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 829 | |
Manuel Novoa III | 68ea1d0 | 2001-03-12 09:57:59 +0000 | [diff] [blame] | 830 | #ifdef KEEP_UNUSED |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 831 | static int opt_i = 0; /* show the statistics */ |
| 832 | static int opt_v = 0; /* debugging output flag */ |
Manuel Novoa III | 68ea1d0 | 2001-03-12 09:57:59 +0000 | [diff] [blame] | 833 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 834 | static int addr_family = 0; /* currently selected AF */ |
| 835 | #endif /* KEEP_UNUSED */ |
Manuel Novoa III | 68ea1d0 | 2001-03-12 09:57:59 +0000 | [diff] [blame] | 836 | |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 837 | static struct interface *int_list, *int_last; |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 838 | static int skfd = -1; /* generic raw socket desc. */ |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 839 | |
| 840 | |
Manuel Novoa III | 68ea1d0 | 2001-03-12 09:57:59 +0000 | [diff] [blame] | 841 | static int sockets_open(int family) |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 842 | { |
"Vladimir N. Oleynik" | 0fa9ded | 2005-10-20 09:48:28 +0000 | [diff] [blame] | 843 | struct aftype * const *aft; |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 844 | int sfd = -1; |
| 845 | static int force = -1; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 846 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 847 | if (force < 0) { |
| 848 | force = 0; |
| 849 | if (get_kernel_revision() < KRELEASE(2, 1, 0)) |
| 850 | force = 1; |
| 851 | if (access("/proc/net", R_OK)) |
| 852 | force = 1; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 853 | } |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 854 | for (aft = aftypes; *aft; aft++) { |
| 855 | struct aftype *af = *aft; |
| 856 | int type = SOCK_DGRAM; |
| 857 | |
| 858 | if (af->af == AF_UNSPEC) |
| 859 | continue; |
| 860 | if (family && family != af->af) |
| 861 | continue; |
| 862 | if (af->fd != -1) { |
| 863 | sfd = af->fd; |
| 864 | continue; |
| 865 | } |
| 866 | /* Check some /proc file first to not stress kmod */ |
| 867 | if (!family && !force && af->flag_file) { |
| 868 | if (access(af->flag_file, R_OK)) |
| 869 | continue; |
| 870 | } |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 871 | #if HAVE_AFNETROM |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 872 | if (af->af == AF_NETROM) |
| 873 | type = SOCK_SEQPACKET; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 874 | #endif |
| 875 | #if HAVE_AFX25 |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 876 | if (af->af == AF_X25) |
| 877 | type = SOCK_SEQPACKET; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 878 | #endif |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 879 | af->fd = socket(af->af, type, 0); |
| 880 | if (af->fd >= 0) |
| 881 | sfd = af->fd; |
| 882 | } |
Glenn L McGrath | 642f289 | 2002-11-28 10:20:45 +0000 | [diff] [blame] | 883 | if (sfd < 0) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 884 | bb_error_msg(_("No usable address families found.")); |
Glenn L McGrath | 642f289 | 2002-11-28 10:20:45 +0000 | [diff] [blame] | 885 | } |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 886 | return sfd; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 887 | } |
| 888 | |
Rob Landley | 9398304 | 2005-05-03 21:30:26 +0000 | [diff] [blame] | 889 | #ifdef CONFIG_FEATURE_CLEAN_UP |
| 890 | static void sockets_close(void) |
| 891 | { |
"Vladimir N. Oleynik" | 0fa9ded | 2005-10-20 09:48:28 +0000 | [diff] [blame] | 892 | struct aftype * const *aft; |
Rob Landley | 9398304 | 2005-05-03 21:30:26 +0000 | [diff] [blame] | 893 | for (aft = aftypes; *aft != NULL; aft++) { |
| 894 | struct aftype *af = *aft; |
| 895 | if( af->fd != -1 ) { |
| 896 | close(af->fd); |
| 897 | af->fd = -1; |
| 898 | } |
| 899 | } |
| 900 | } |
| 901 | #endif |
| 902 | |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 903 | /* like strcmp(), but knows about numbers */ |
Glenn L McGrath | 2e99d43 | 2004-07-23 01:49:46 +0000 | [diff] [blame] | 904 | static int nstrcmp(const char *a, const char *b) |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 905 | { |
Glenn L McGrath | 2e99d43 | 2004-07-23 01:49:46 +0000 | [diff] [blame] | 906 | const char *a_ptr = a; |
| 907 | const char *b_ptr = b; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 908 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 909 | while (*a == *b) { |
Glenn L McGrath | 2e99d43 | 2004-07-23 01:49:46 +0000 | [diff] [blame] | 910 | if (*a == '\0') { |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 911 | return 0; |
Glenn L McGrath | 2e99d43 | 2004-07-23 01:49:46 +0000 | [diff] [blame] | 912 | } |
| 913 | if (!isdigit(*a) && isdigit(*(a+1))) { |
| 914 | a_ptr = a+1; |
| 915 | b_ptr = b+1; |
| 916 | } |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 917 | a++; |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 918 | b++; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 919 | } |
Glenn L McGrath | 2e99d43 | 2004-07-23 01:49:46 +0000 | [diff] [blame] | 920 | |
| 921 | if (isdigit(*a) && isdigit(*b)) { |
| 922 | return atoi(a_ptr) > atoi(b_ptr) ? 1 : -1; |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 923 | } |
| 924 | return *a - *b; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 925 | } |
| 926 | |
| 927 | static struct interface *add_interface(char *name) |
| 928 | { |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 929 | struct interface *ife, **nextp, *new; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 930 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 931 | for (ife = int_last; ife; ife = ife->prev) { |
| 932 | int n = nstrcmp(ife->name, name); |
| 933 | |
| 934 | if (n == 0) |
| 935 | return ife; |
| 936 | if (n < 0) |
| 937 | break; |
| 938 | } |
| 939 | new(new); |
| 940 | safe_strncpy(new->name, name, IFNAMSIZ); |
| 941 | nextp = ife ? &ife->next : &int_list; |
| 942 | new->prev = ife; |
| 943 | new->next = *nextp; |
| 944 | if (new->next) |
| 945 | new->next->prev = new; |
| 946 | else |
| 947 | int_last = new; |
| 948 | *nextp = new; |
| 949 | return new; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 950 | } |
| 951 | |
| 952 | |
| 953 | static int if_readconf(void) |
| 954 | { |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 955 | int numreqs = 30; |
| 956 | struct ifconf ifc; |
| 957 | struct ifreq *ifr; |
| 958 | int n, err = -1; |
| 959 | int skfd2; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 960 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 961 | /* SIOCGIFCONF currently seems to only work properly on AF_INET sockets |
| 962 | (as of 2.1.128) */ |
| 963 | skfd2 = get_socket_for_af(AF_INET); |
| 964 | if (skfd2 < 0) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 965 | bb_perror_msg(("warning: no inet socket available")); |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 966 | /* Try to soldier on with whatever socket we can get hold of. */ |
| 967 | skfd2 = sockets_open(0); |
| 968 | if (skfd2 < 0) |
| 969 | return -1; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 970 | } |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 971 | |
| 972 | ifc.ifc_buf = NULL; |
| 973 | for (;;) { |
| 974 | ifc.ifc_len = sizeof(struct ifreq) * numreqs; |
| 975 | ifc.ifc_buf = xrealloc(ifc.ifc_buf, ifc.ifc_len); |
| 976 | |
| 977 | if (ioctl(skfd2, SIOCGIFCONF, &ifc) < 0) { |
| 978 | perror("SIOCGIFCONF"); |
| 979 | goto out; |
| 980 | } |
| 981 | if (ifc.ifc_len == sizeof(struct ifreq) * numreqs) { |
| 982 | /* assume it overflowed and try again */ |
| 983 | numreqs += 10; |
| 984 | continue; |
| 985 | } |
| 986 | break; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 987 | } |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 988 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 989 | ifr = ifc.ifc_req; |
| 990 | for (n = 0; n < ifc.ifc_len; n += sizeof(struct ifreq)) { |
| 991 | add_interface(ifr->ifr_name); |
| 992 | ifr++; |
| 993 | } |
| 994 | err = 0; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 995 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 996 | out: |
| 997 | free(ifc.ifc_buf); |
| 998 | return err; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 999 | } |
| 1000 | |
Eric Andersen | 14f5c8d | 2005-04-16 19:39:00 +0000 | [diff] [blame] | 1001 | static char *get_name(char *name, char *p) |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1002 | { |
Eric Andersen | 9940e08 | 2004-08-12 16:52:00 +0000 | [diff] [blame] | 1003 | /* Extract <name>[:<alias>] from nul-terminated p where p matches |
| 1004 | <name>[:<alias>]: after leading whitespace. |
| 1005 | If match is not made, set name empty and return unchanged p */ |
| 1006 | int namestart=0, nameend=0, aliasend; |
| 1007 | while (isspace(p[namestart])) |
| 1008 | namestart++; |
| 1009 | nameend=namestart; |
| 1010 | while (p[nameend] && p[nameend]!=':' && !isspace(p[nameend])) |
| 1011 | nameend++; |
| 1012 | if (p[nameend]==':') { |
| 1013 | aliasend=nameend+1; |
| 1014 | while (p[aliasend] && isdigit(p[aliasend])) |
| 1015 | aliasend++; |
| 1016 | if (p[aliasend]==':') { |
| 1017 | nameend=aliasend; |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1018 | } |
Eric Andersen | 9940e08 | 2004-08-12 16:52:00 +0000 | [diff] [blame] | 1019 | if ((nameend-namestart)<IFNAMSIZ) { |
| 1020 | memcpy(name,&p[namestart],nameend-namestart); |
| 1021 | name[nameend-namestart]='\0'; |
| 1022 | p=&p[nameend]; |
| 1023 | } else { |
| 1024 | /* Interface name too large */ |
| 1025 | name[0]='\0'; |
| 1026 | } |
| 1027 | } else { |
| 1028 | /* first ':' not found - return empty */ |
| 1029 | name[0]='\0'; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1030 | } |
Eric Andersen | 6fea732 | 2004-08-26 21:45:21 +0000 | [diff] [blame] | 1031 | return p + 1; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1032 | } |
| 1033 | |
Manuel Novoa III | b1d5b74 | 2003-08-02 00:04:18 +0000 | [diff] [blame] | 1034 | /* If scanf supports size qualifiers for %n conversions, then we can |
| 1035 | * use a modified fmt that simply stores the position in the fields |
| 1036 | * having no associated fields in the proc string. Of course, we need |
| 1037 | * to zero them again when we're done. But that is smaller than the |
| 1038 | * old approach of multiple scanf occurrences with large numbers of |
| 1039 | * args. */ |
| 1040 | |
Bernhard Reutner-Fischer | a901b40 | 2006-01-19 14:51:17 +0000 | [diff] [blame] | 1041 | /* static const char * const ss_fmt[] = { */ |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 1042 | /* "%Ln%Lu%lu%lu%lu%lu%ln%ln%Ln%Lu%lu%lu%lu%lu%lu", */ |
| 1043 | /* "%Lu%Lu%lu%lu%lu%lu%ln%ln%Lu%Lu%lu%lu%lu%lu%lu", */ |
| 1044 | /* "%Lu%Lu%lu%lu%lu%lu%lu%lu%Lu%Lu%lu%lu%lu%lu%lu%lu" */ |
Manuel Novoa III | b1d5b74 | 2003-08-02 00:04:18 +0000 | [diff] [blame] | 1045 | /* }; */ |
| 1046 | |
| 1047 | /* Lie about the size of the int pointed to for %n. */ |
| 1048 | #if INT_MAX == LONG_MAX |
"Vladimir N. Oleynik" | 0fa9ded | 2005-10-20 09:48:28 +0000 | [diff] [blame] | 1049 | static const char * const ss_fmt[] = { |
Manuel Novoa III | b1d5b74 | 2003-08-02 00:04:18 +0000 | [diff] [blame] | 1050 | "%n%Lu%u%u%u%u%n%n%n%Lu%u%u%u%u%u", |
| 1051 | "%Lu%Lu%u%u%u%u%n%n%Lu%Lu%u%u%u%u%u", |
| 1052 | "%Lu%Lu%u%u%u%u%u%u%Lu%Lu%u%u%u%u%u%u" |
| 1053 | }; |
| 1054 | #else |
"Vladimir N. Oleynik" | 0fa9ded | 2005-10-20 09:48:28 +0000 | [diff] [blame] | 1055 | static const char * const ss_fmt[] = { |
Manuel Novoa III | b1d5b74 | 2003-08-02 00:04:18 +0000 | [diff] [blame] | 1056 | "%n%Lu%lu%lu%lu%lu%n%n%n%Lu%lu%lu%lu%lu%lu", |
| 1057 | "%Lu%Lu%lu%lu%lu%lu%n%n%Lu%Lu%lu%lu%lu%lu%lu", |
| 1058 | "%Lu%Lu%lu%lu%lu%lu%lu%lu%Lu%Lu%lu%lu%lu%lu%lu%lu" |
| 1059 | }; |
| 1060 | |
| 1061 | #endif |
| 1062 | |
| 1063 | static void get_dev_fields(char *bp, struct interface *ife, int procnetdev_vsn) |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1064 | { |
Manuel Novoa III | b1d5b74 | 2003-08-02 00:04:18 +0000 | [diff] [blame] | 1065 | memset(&ife->stats, 0, sizeof(struct user_net_device_stats)); |
| 1066 | |
| 1067 | sscanf(bp, ss_fmt[procnetdev_vsn], |
| 1068 | &ife->stats.rx_bytes, /* missing for 0 */ |
| 1069 | &ife->stats.rx_packets, |
| 1070 | &ife->stats.rx_errors, |
| 1071 | &ife->stats.rx_dropped, |
| 1072 | &ife->stats.rx_fifo_errors, |
| 1073 | &ife->stats.rx_frame_errors, |
| 1074 | &ife->stats.rx_compressed, /* missing for <= 1 */ |
| 1075 | &ife->stats.rx_multicast, /* missing for <= 1 */ |
| 1076 | &ife->stats.tx_bytes, /* missing for 0 */ |
| 1077 | &ife->stats.tx_packets, |
| 1078 | &ife->stats.tx_errors, |
| 1079 | &ife->stats.tx_dropped, |
| 1080 | &ife->stats.tx_fifo_errors, |
| 1081 | &ife->stats.collisions, |
| 1082 | &ife->stats.tx_carrier_errors, |
| 1083 | &ife->stats.tx_compressed /* missing for <= 1 */ |
| 1084 | ); |
| 1085 | |
| 1086 | if (procnetdev_vsn <= 1) { |
| 1087 | if (procnetdev_vsn == 0) { |
| 1088 | ife->stats.rx_bytes = 0; |
| 1089 | ife->stats.tx_bytes = 0; |
| 1090 | } |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1091 | ife->stats.rx_multicast = 0; |
Manuel Novoa III | b1d5b74 | 2003-08-02 00:04:18 +0000 | [diff] [blame] | 1092 | ife->stats.rx_compressed = 0; |
| 1093 | ife->stats.tx_compressed = 0; |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1094 | } |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1095 | } |
| 1096 | |
Manuel Novoa III | 68ea1d0 | 2001-03-12 09:57:59 +0000 | [diff] [blame] | 1097 | static inline int procnetdev_version(char *buf) |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1098 | { |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1099 | if (strstr(buf, "compressed")) |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1100 | return 2; |
Manuel Novoa III | b1d5b74 | 2003-08-02 00:04:18 +0000 | [diff] [blame] | 1101 | if (strstr(buf, "bytes")) |
| 1102 | return 1; |
| 1103 | return 0; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1104 | } |
| 1105 | |
| 1106 | static int if_readlist_proc(char *target) |
| 1107 | { |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1108 | static int proc_read; |
| 1109 | FILE *fh; |
| 1110 | char buf[512]; |
| 1111 | struct interface *ife; |
Manuel Novoa III | b1d5b74 | 2003-08-02 00:04:18 +0000 | [diff] [blame] | 1112 | int err, procnetdev_vsn; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1113 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1114 | if (proc_read) |
| 1115 | return 0; |
| 1116 | if (!target) |
| 1117 | proc_read = 1; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1118 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1119 | fh = fopen(_PATH_PROCNET_DEV, "r"); |
| 1120 | if (!fh) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 1121 | bb_perror_msg(_("Warning: cannot open %s. Limited output."), _PATH_PROCNET_DEV); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1122 | return if_readconf(); |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1123 | } |
| 1124 | fgets(buf, sizeof buf, fh); /* eat line */ |
| 1125 | fgets(buf, sizeof buf, fh); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1126 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1127 | procnetdev_vsn = procnetdev_version(buf); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1128 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1129 | err = 0; |
| 1130 | while (fgets(buf, sizeof buf, fh)) { |
Eric Andersen | f96675b | 2003-07-28 06:37:04 +0000 | [diff] [blame] | 1131 | char *s, name[128]; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1132 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1133 | s = get_name(name, buf); |
| 1134 | ife = add_interface(name); |
Manuel Novoa III | b1d5b74 | 2003-08-02 00:04:18 +0000 | [diff] [blame] | 1135 | get_dev_fields(s, ife, procnetdev_vsn); |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1136 | ife->statistics_valid = 1; |
| 1137 | if (target && !strcmp(target, name)) |
| 1138 | break; |
| 1139 | } |
| 1140 | if (ferror(fh)) { |
| 1141 | perror(_PATH_PROCNET_DEV); |
| 1142 | err = -1; |
| 1143 | proc_read = 0; |
| 1144 | } |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1145 | fclose(fh); |
| 1146 | return err; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1147 | } |
| 1148 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1149 | static int if_readlist(void) |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1150 | { |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1151 | int err = if_readlist_proc(NULL); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1152 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1153 | if (!err) |
| 1154 | err = if_readconf(); |
| 1155 | return err; |
| 1156 | } |
| 1157 | |
| 1158 | static int for_all_interfaces(int (*doit) (struct interface *, void *), |
| 1159 | void *cookie) |
| 1160 | { |
| 1161 | struct interface *ife; |
| 1162 | |
| 1163 | if (!int_list && (if_readlist() < 0)) |
| 1164 | return -1; |
| 1165 | for (ife = int_list; ife; ife = ife->next) { |
| 1166 | int err = doit(ife, cookie); |
| 1167 | |
| 1168 | if (err) |
| 1169 | return err; |
| 1170 | } |
| 1171 | return 0; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1172 | } |
| 1173 | |
| 1174 | /* Support for fetching an IPX address */ |
| 1175 | |
| 1176 | #if HAVE_AFIPX |
| 1177 | static int ipx_getaddr(int sock, int ft, struct ifreq *ifr) |
| 1178 | { |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1179 | ((struct sockaddr_ipx *) &ifr->ifr_addr)->sipx_type = ft; |
| 1180 | return ioctl(sock, SIOCGIFADDR, ifr); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1181 | } |
| 1182 | #endif |
| 1183 | |
| 1184 | |
| 1185 | /* Fetch the interface configuration from the kernel. */ |
Manuel Novoa III | 68ea1d0 | 2001-03-12 09:57:59 +0000 | [diff] [blame] | 1186 | static int if_fetch(struct interface *ife) |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1187 | { |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1188 | struct ifreq ifr; |
| 1189 | int fd; |
| 1190 | char *ifname = ife->name; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1191 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1192 | strcpy(ifr.ifr_name, ifname); |
| 1193 | if (ioctl(skfd, SIOCGIFFLAGS, &ifr) < 0) |
| 1194 | return (-1); |
| 1195 | ife->flags = ifr.ifr_flags; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1196 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1197 | strcpy(ifr.ifr_name, ifname); |
| 1198 | if (ioctl(skfd, SIOCGIFHWADDR, &ifr) < 0) |
| 1199 | memset(ife->hwaddr, 0, 32); |
| 1200 | else |
| 1201 | memcpy(ife->hwaddr, ifr.ifr_hwaddr.sa_data, 8); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1202 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1203 | ife->type = ifr.ifr_hwaddr.sa_family; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1204 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1205 | strcpy(ifr.ifr_name, ifname); |
| 1206 | if (ioctl(skfd, SIOCGIFMETRIC, &ifr) < 0) |
| 1207 | ife->metric = 0; |
| 1208 | else |
| 1209 | ife->metric = ifr.ifr_metric; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1210 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1211 | strcpy(ifr.ifr_name, ifname); |
| 1212 | if (ioctl(skfd, SIOCGIFMTU, &ifr) < 0) |
| 1213 | ife->mtu = 0; |
| 1214 | else |
| 1215 | ife->mtu = ifr.ifr_mtu; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1216 | |
| 1217 | #ifdef HAVE_HWSLIP |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1218 | if (ife->type == ARPHRD_SLIP || ife->type == ARPHRD_CSLIP || |
| 1219 | ife->type == ARPHRD_SLIP6 || ife->type == ARPHRD_CSLIP6 || |
| 1220 | ife->type == ARPHRD_ADAPT) { |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1221 | #ifdef SIOCGOUTFILL |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1222 | strcpy(ifr.ifr_name, ifname); |
| 1223 | if (ioctl(skfd, SIOCGOUTFILL, &ifr) < 0) |
| 1224 | ife->outfill = 0; |
| 1225 | else |
| 1226 | ife->outfill = (unsigned int) ifr.ifr_data; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1227 | #endif |
| 1228 | #ifdef SIOCGKEEPALIVE |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1229 | strcpy(ifr.ifr_name, ifname); |
| 1230 | if (ioctl(skfd, SIOCGKEEPALIVE, &ifr) < 0) |
| 1231 | ife->keepalive = 0; |
| 1232 | else |
| 1233 | ife->keepalive = (unsigned int) ifr.ifr_data; |
| 1234 | #endif |
| 1235 | } |
| 1236 | #endif |
| 1237 | |
Rob Landley | 9398304 | 2005-05-03 21:30:26 +0000 | [diff] [blame] | 1238 | #ifdef SIOCGIFMAP |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1239 | strcpy(ifr.ifr_name, ifname); |
Rob Landley | 9398304 | 2005-05-03 21:30:26 +0000 | [diff] [blame] | 1240 | if (ioctl(skfd, SIOCGIFMAP, &ifr) == 0) |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1241 | ife->map = ifr.ifr_map; |
Rob Landley | 9398304 | 2005-05-03 21:30:26 +0000 | [diff] [blame] | 1242 | else |
| 1243 | #endif |
| 1244 | memset(&ife->map, 0, sizeof(struct ifmap)); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1245 | |
| 1246 | #ifdef HAVE_TXQUEUELEN |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1247 | strcpy(ifr.ifr_name, ifname); |
| 1248 | if (ioctl(skfd, SIOCGIFTXQLEN, &ifr) < 0) |
| 1249 | ife->tx_queue_len = -1; /* unknown value */ |
| 1250 | else |
| 1251 | ife->tx_queue_len = ifr.ifr_qlen; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1252 | #else |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1253 | ife->tx_queue_len = -1; /* unknown value */ |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1254 | #endif |
| 1255 | |
| 1256 | #if HAVE_AFINET |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1257 | /* IPv4 address? */ |
| 1258 | fd = get_socket_for_af(AF_INET); |
| 1259 | if (fd >= 0) { |
| 1260 | strcpy(ifr.ifr_name, ifname); |
| 1261 | ifr.ifr_addr.sa_family = AF_INET; |
| 1262 | if (ioctl(fd, SIOCGIFADDR, &ifr) == 0) { |
| 1263 | ife->has_ip = 1; |
| 1264 | ife->addr = ifr.ifr_addr; |
| 1265 | strcpy(ifr.ifr_name, ifname); |
| 1266 | if (ioctl(fd, SIOCGIFDSTADDR, &ifr) < 0) |
| 1267 | memset(&ife->dstaddr, 0, sizeof(struct sockaddr)); |
| 1268 | else |
| 1269 | ife->dstaddr = ifr.ifr_dstaddr; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1270 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1271 | strcpy(ifr.ifr_name, ifname); |
| 1272 | if (ioctl(fd, SIOCGIFBRDADDR, &ifr) < 0) |
| 1273 | memset(&ife->broadaddr, 0, sizeof(struct sockaddr)); |
| 1274 | else |
| 1275 | ife->broadaddr = ifr.ifr_broadaddr; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1276 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1277 | strcpy(ifr.ifr_name, ifname); |
| 1278 | if (ioctl(fd, SIOCGIFNETMASK, &ifr) < 0) |
| 1279 | memset(&ife->netmask, 0, sizeof(struct sockaddr)); |
| 1280 | else |
| 1281 | ife->netmask = ifr.ifr_netmask; |
| 1282 | } else |
| 1283 | memset(&ife->addr, 0, sizeof(struct sockaddr)); |
| 1284 | } |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1285 | #endif |
| 1286 | |
| 1287 | #if HAVE_AFATALK |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1288 | /* DDP address maybe ? */ |
| 1289 | fd = get_socket_for_af(AF_APPLETALK); |
| 1290 | if (fd >= 0) { |
| 1291 | strcpy(ifr.ifr_name, ifname); |
| 1292 | if (ioctl(fd, SIOCGIFADDR, &ifr) == 0) { |
| 1293 | ife->ddpaddr = ifr.ifr_addr; |
| 1294 | ife->has_ddp = 1; |
| 1295 | } |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1296 | } |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1297 | #endif |
| 1298 | |
| 1299 | #if HAVE_AFIPX |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1300 | /* Look for IPX addresses with all framing types */ |
| 1301 | fd = get_socket_for_af(AF_IPX); |
| 1302 | if (fd >= 0) { |
| 1303 | strcpy(ifr.ifr_name, ifname); |
| 1304 | if (!ipx_getaddr(fd, IPX_FRAME_ETHERII, &ifr)) { |
| 1305 | ife->has_ipx_bb = 1; |
| 1306 | ife->ipxaddr_bb = ifr.ifr_addr; |
| 1307 | } |
| 1308 | strcpy(ifr.ifr_name, ifname); |
| 1309 | if (!ipx_getaddr(fd, IPX_FRAME_SNAP, &ifr)) { |
| 1310 | ife->has_ipx_sn = 1; |
| 1311 | ife->ipxaddr_sn = ifr.ifr_addr; |
| 1312 | } |
| 1313 | strcpy(ifr.ifr_name, ifname); |
| 1314 | if (!ipx_getaddr(fd, IPX_FRAME_8023, &ifr)) { |
| 1315 | ife->has_ipx_e3 = 1; |
| 1316 | ife->ipxaddr_e3 = ifr.ifr_addr; |
| 1317 | } |
| 1318 | strcpy(ifr.ifr_name, ifname); |
| 1319 | if (!ipx_getaddr(fd, IPX_FRAME_8022, &ifr)) { |
| 1320 | ife->has_ipx_e2 = 1; |
| 1321 | ife->ipxaddr_e2 = ifr.ifr_addr; |
| 1322 | } |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1323 | } |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1324 | #endif |
| 1325 | |
| 1326 | #if HAVE_AFECONET |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1327 | /* Econet address maybe? */ |
| 1328 | fd = get_socket_for_af(AF_ECONET); |
| 1329 | if (fd >= 0) { |
| 1330 | strcpy(ifr.ifr_name, ifname); |
| 1331 | if (ioctl(fd, SIOCGIFADDR, &ifr) == 0) { |
| 1332 | ife->ecaddr = ifr.ifr_addr; |
| 1333 | ife->has_econet = 1; |
| 1334 | } |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1335 | } |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1336 | #endif |
| 1337 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1338 | return 0; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1339 | } |
| 1340 | |
| 1341 | |
Manuel Novoa III | 68ea1d0 | 2001-03-12 09:57:59 +0000 | [diff] [blame] | 1342 | static int do_if_fetch(struct interface *ife) |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1343 | { |
| 1344 | if (if_fetch(ife) < 0) { |
| 1345 | char *errmsg; |
| 1346 | |
| 1347 | if (errno == ENODEV) { |
| 1348 | /* Give better error message for this case. */ |
| 1349 | errmsg = _("Device not found"); |
| 1350 | } else { |
| 1351 | errmsg = strerror(errno); |
| 1352 | } |
"Vladimir N. Oleynik" | 0fa9ded | 2005-10-20 09:48:28 +0000 | [diff] [blame] | 1353 | bb_error_msg(_("%s: error fetching interface information: %s"), |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1354 | ife->name, errmsg); |
| 1355 | return -1; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1356 | } |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1357 | return 0; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1358 | } |
| 1359 | |
| 1360 | /* This structure defines hardware protocols and their handlers. */ |
| 1361 | struct hwtype { |
Bernhard Reutner-Fischer | a901b40 | 2006-01-19 14:51:17 +0000 | [diff] [blame] | 1362 | const char * const name; |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1363 | const char *title; |
| 1364 | int type; |
| 1365 | int alen; |
| 1366 | char *(*print) (unsigned char *); |
| 1367 | int (*input) (char *, struct sockaddr *); |
| 1368 | int (*activate) (int fd); |
| 1369 | int suppress_null_addr; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1370 | }; |
| 1371 | |
"Vladimir N. Oleynik" | 0fa9ded | 2005-10-20 09:48:28 +0000 | [diff] [blame] | 1372 | static const struct hwtype unspec_hwtype = { |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1373 | "unspec", "UNSPEC", -1, 0, |
| 1374 | UNSPEC_print, NULL, NULL |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1375 | }; |
| 1376 | |
"Vladimir N. Oleynik" | 0fa9ded | 2005-10-20 09:48:28 +0000 | [diff] [blame] | 1377 | static const struct hwtype loop_hwtype = { |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1378 | "loop", "Local Loopback", ARPHRD_LOOPBACK, 0, |
| 1379 | NULL, NULL, NULL |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1380 | }; |
| 1381 | |
| 1382 | #if HAVE_HWETHER |
| 1383 | #include <net/if_arp.h> |
Eric Andersen | ab4e19a | 2003-01-14 08:54:08 +0000 | [diff] [blame] | 1384 | |
Mike Frysinger | 3b05b80 | 2005-03-04 01:10:56 +0000 | [diff] [blame] | 1385 | #if (__GLIBC__ >=2 && __GLIBC_MINOR >= 1) || defined(_NEWLIB_VERSION) |
Eric Andersen | ab4e19a | 2003-01-14 08:54:08 +0000 | [diff] [blame] | 1386 | #include <net/ethernet.h> |
| 1387 | #else |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1388 | #include <linux/if_ether.h> |
Eric Andersen | ab4e19a | 2003-01-14 08:54:08 +0000 | [diff] [blame] | 1389 | #endif |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1390 | |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1391 | /* Display an Ethernet address in readable format. */ |
| 1392 | static char *pr_ether(unsigned char *ptr) |
| 1393 | { |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1394 | static char buff[64]; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1395 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1396 | snprintf(buff, sizeof(buff), "%02X:%02X:%02X:%02X:%02X:%02X", |
| 1397 | (ptr[0] & 0377), (ptr[1] & 0377), (ptr[2] & 0377), |
| 1398 | (ptr[3] & 0377), (ptr[4] & 0377), (ptr[5] & 0377) |
| 1399 | ); |
| 1400 | return (buff); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1401 | } |
| 1402 | |
Manuel Novoa III | 68ea1d0 | 2001-03-12 09:57:59 +0000 | [diff] [blame] | 1403 | #ifdef KEEP_UNUSED |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1404 | /* Input an Ethernet address and convert to binary. */ |
| 1405 | static int in_ether(char *bufp, struct sockaddr *sap) |
| 1406 | { |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1407 | unsigned char *ptr; |
| 1408 | char c, *orig; |
| 1409 | int i; |
| 1410 | unsigned val; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1411 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1412 | sap->sa_family = ether_hwtype.type; |
| 1413 | ptr = sap->sa_data; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1414 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1415 | i = 0; |
| 1416 | orig = bufp; |
| 1417 | while ((*bufp != '\0') && (i < ETH_ALEN)) { |
| 1418 | val = 0; |
| 1419 | c = *bufp++; |
| 1420 | if (isdigit(c)) |
| 1421 | val = c - '0'; |
| 1422 | else if (c >= 'a' && c <= 'f') |
| 1423 | val = c - 'a' + 10; |
| 1424 | else if (c >= 'A' && c <= 'F') |
| 1425 | val = c - 'A' + 10; |
| 1426 | else { |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1427 | #ifdef DEBUG |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 1428 | bb_error_msg(_("in_ether(%s): invalid ether address!\n"), orig); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1429 | #endif |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1430 | errno = EINVAL; |
| 1431 | return (-1); |
| 1432 | } |
| 1433 | val <<= 4; |
| 1434 | c = *bufp; |
| 1435 | if (isdigit(c)) |
| 1436 | val |= c - '0'; |
| 1437 | else if (c >= 'a' && c <= 'f') |
| 1438 | val |= c - 'a' + 10; |
| 1439 | else if (c >= 'A' && c <= 'F') |
| 1440 | val |= c - 'A' + 10; |
| 1441 | else if (c == ':' || c == 0) |
| 1442 | val >>= 4; |
| 1443 | else { |
| 1444 | #ifdef DEBUG |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 1445 | bb_error_msg(_("in_ether(%s): invalid ether address!"), orig); |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1446 | #endif |
| 1447 | errno = EINVAL; |
| 1448 | return (-1); |
| 1449 | } |
| 1450 | if (c != 0) |
| 1451 | bufp++; |
| 1452 | *ptr++ = (unsigned char) (val & 0377); |
| 1453 | i++; |
| 1454 | |
| 1455 | /* We might get a semicolon here - not required. */ |
| 1456 | if (*bufp == ':') { |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1457 | #ifdef DEBUG |
Glenn L McGrath | 642f289 | 2002-11-28 10:20:45 +0000 | [diff] [blame] | 1458 | if (i == ETH_ALEN) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 1459 | bb_error_msg(_("in_ether(%s): trailing : ignored!"), orig); |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1460 | } |
Glenn L McGrath | 642f289 | 2002-11-28 10:20:45 +0000 | [diff] [blame] | 1461 | #endif |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1462 | bufp++; |
| 1463 | } |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1464 | } |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1465 | |
Glenn L McGrath | 642f289 | 2002-11-28 10:20:45 +0000 | [diff] [blame] | 1466 | #ifdef DEBUG |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1467 | /* That's it. Any trailing junk? */ |
| 1468 | if ((i == ETH_ALEN) && (*bufp != '\0')) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 1469 | bb_error_msg(_("in_ether(%s): trailing junk!"), orig); |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1470 | errno = EINVAL; |
| 1471 | return (-1); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1472 | } |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 1473 | bb_error_msg("in_ether(%s): %s", orig, pr_ether(sap->sa_data)); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1474 | #endif |
| 1475 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1476 | return (0); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1477 | } |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1478 | #endif /* KEEP_UNUSED */ |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1479 | |
| 1480 | |
"Vladimir N. Oleynik" | 0fa9ded | 2005-10-20 09:48:28 +0000 | [diff] [blame] | 1481 | static const struct hwtype ether_hwtype = { |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1482 | "ether", "Ethernet", ARPHRD_ETHER, ETH_ALEN, |
| 1483 | pr_ether, NULL /* UNUSED in_ether */ , NULL |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1484 | }; |
| 1485 | |
| 1486 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1487 | #endif /* HAVE_HWETHER */ |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1488 | |
| 1489 | |
| 1490 | #if HAVE_HWPPP |
| 1491 | |
| 1492 | #include <net/if_arp.h> |
| 1493 | |
Manuel Novoa III | 68ea1d0 | 2001-03-12 09:57:59 +0000 | [diff] [blame] | 1494 | #ifdef KEEP_UNUSED |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1495 | /* Start the PPP encapsulation on the file descriptor. */ |
| 1496 | static int do_ppp(int fd) |
| 1497 | { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 1498 | bb_error_msg(_("You cannot start PPP with this program.")); |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1499 | return -1; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1500 | } |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1501 | #endif /* KEEP_UNUSED */ |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1502 | |
"Vladimir N. Oleynik" | 0fa9ded | 2005-10-20 09:48:28 +0000 | [diff] [blame] | 1503 | static const struct hwtype ppp_hwtype = { |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1504 | "ppp", "Point-Point Protocol", ARPHRD_PPP, 0, |
| 1505 | NULL, NULL, NULL /* UNUSED do_ppp */ , 0 |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1506 | }; |
| 1507 | |
| 1508 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1509 | #endif /* HAVE_PPP */ |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1510 | |
"Vladimir N. Oleynik" | 0fa9ded | 2005-10-20 09:48:28 +0000 | [diff] [blame] | 1511 | static const struct hwtype * const hwtypes[] = { |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1512 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1513 | &loop_hwtype, |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1514 | |
| 1515 | #if HAVE_HWSLIP |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1516 | &slip_hwtype, |
| 1517 | &cslip_hwtype, |
| 1518 | &slip6_hwtype, |
| 1519 | &cslip6_hwtype, |
| 1520 | &adaptive_hwtype, |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1521 | #endif |
| 1522 | #if HAVE_HWSTRIP |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1523 | &strip_hwtype, |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1524 | #endif |
| 1525 | #if HAVE_HWASH |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1526 | &ash_hwtype, |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1527 | #endif |
| 1528 | #if HAVE_HWETHER |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1529 | ðer_hwtype, |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1530 | #endif |
| 1531 | #if HAVE_HWTR |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1532 | &tr_hwtype, |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1533 | #ifdef ARPHRD_IEEE802_TR |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1534 | &tr_hwtype1, |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1535 | #endif |
| 1536 | #endif |
| 1537 | #if HAVE_HWAX25 |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1538 | &ax25_hwtype, |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1539 | #endif |
| 1540 | #if HAVE_HWNETROM |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1541 | &netrom_hwtype, |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1542 | #endif |
| 1543 | #if HAVE_HWROSE |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1544 | &rose_hwtype, |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1545 | #endif |
| 1546 | #if HAVE_HWTUNNEL |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1547 | &tunnel_hwtype, |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1548 | #endif |
| 1549 | #if HAVE_HWPPP |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1550 | &ppp_hwtype, |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1551 | #endif |
| 1552 | #if HAVE_HWHDLCLAPB |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1553 | &hdlc_hwtype, |
| 1554 | &lapb_hwtype, |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1555 | #endif |
| 1556 | #if HAVE_HWARC |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1557 | &arcnet_hwtype, |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1558 | #endif |
| 1559 | #if HAVE_HWFR |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1560 | &dlci_hwtype, |
| 1561 | &frad_hwtype, |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1562 | #endif |
| 1563 | #if HAVE_HWSIT |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1564 | &sit_hwtype, |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1565 | #endif |
| 1566 | #if HAVE_HWFDDI |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1567 | &fddi_hwtype, |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1568 | #endif |
| 1569 | #if HAVE_HWHIPPI |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1570 | &hippi_hwtype, |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1571 | #endif |
| 1572 | #if HAVE_HWIRDA |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1573 | &irda_hwtype, |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1574 | #endif |
| 1575 | #if HAVE_HWEC |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1576 | &ec_hwtype, |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1577 | #endif |
| 1578 | #if HAVE_HWX25 |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1579 | &x25_hwtype, |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1580 | #endif |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1581 | &unspec_hwtype, |
| 1582 | NULL |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1583 | }; |
| 1584 | |
Manuel Novoa III | 68ea1d0 | 2001-03-12 09:57:59 +0000 | [diff] [blame] | 1585 | #ifdef KEEP_UNUSED |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1586 | static short sVhwinit = 0; |
| 1587 | |
Manuel Novoa III | 68ea1d0 | 2001-03-12 09:57:59 +0000 | [diff] [blame] | 1588 | static void hwinit() |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1589 | { |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1590 | loop_hwtype.title = _("Local Loopback"); |
| 1591 | unspec_hwtype.title = _("UNSPEC"); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1592 | #if HAVE_HWSLIP |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1593 | slip_hwtype.title = _("Serial Line IP"); |
| 1594 | cslip_hwtype.title = _("VJ Serial Line IP"); |
| 1595 | slip6_hwtype.title = _("6-bit Serial Line IP"); |
| 1596 | cslip6_hwtype.title = _("VJ 6-bit Serial Line IP"); |
| 1597 | adaptive_hwtype.title = _("Adaptive Serial Line IP"); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1598 | #endif |
| 1599 | #if HAVE_HWETHER |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1600 | ether_hwtype.title = _("Ethernet"); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1601 | #endif |
| 1602 | #if HAVE_HWASH |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1603 | ash_hwtype.title = _("Ash"); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1604 | #endif |
| 1605 | #if HAVE_HWFDDI |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1606 | fddi_hwtype.title = _("Fiber Distributed Data Interface"); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1607 | #endif |
| 1608 | #if HAVE_HWHIPPI |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1609 | hippi_hwtype.title = _("HIPPI"); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1610 | #endif |
| 1611 | #if HAVE_HWAX25 |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1612 | ax25_hwtype.title = _("AMPR AX.25"); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1613 | #endif |
| 1614 | #if HAVE_HWROSE |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1615 | rose_hwtype.title = _("AMPR ROSE"); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1616 | #endif |
| 1617 | #if HAVE_HWNETROM |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1618 | netrom_hwtype.title = _("AMPR NET/ROM"); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1619 | #endif |
| 1620 | #if HAVE_HWX25 |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1621 | x25_hwtype.title = _("generic X.25"); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1622 | #endif |
| 1623 | #if HAVE_HWTUNNEL |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1624 | tunnel_hwtype.title = _("IPIP Tunnel"); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1625 | #endif |
| 1626 | #if HAVE_HWPPP |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1627 | ppp_hwtype.title = _("Point-to-Point Protocol"); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1628 | #endif |
| 1629 | #if HAVE_HWHDLCLAPB |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1630 | hdlc_hwtype.title = _("(Cisco)-HDLC"); |
| 1631 | lapb_hwtype.title = _("LAPB"); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1632 | #endif |
| 1633 | #if HAVE_HWARC |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1634 | arcnet_hwtype.title = _("ARCnet"); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1635 | #endif |
| 1636 | #if HAVE_HWFR |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1637 | dlci_hwtype.title = _("Frame Relay DLCI"); |
| 1638 | frad_hwtype.title = _("Frame Relay Access Device"); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1639 | #endif |
| 1640 | #if HAVE_HWSIT |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1641 | sit_hwtype.title = _("IPv6-in-IPv4"); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1642 | #endif |
| 1643 | #if HAVE_HWIRDA |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1644 | irda_hwtype.title = _("IrLAP"); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1645 | #endif |
| 1646 | #if HAVE_HWTR |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1647 | tr_hwtype.title = _("16/4 Mbps Token Ring"); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1648 | #ifdef ARPHRD_IEEE802_TR |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1649 | tr_hwtype1.title = _("16/4 Mbps Token Ring (New)"); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1650 | #endif |
| 1651 | #endif |
| 1652 | #if HAVE_HWEC |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1653 | ec_hwtype.title = _("Econet"); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1654 | #endif |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1655 | sVhwinit = 1; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1656 | } |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1657 | #endif /* KEEP_UNUSED */ |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1658 | |
| 1659 | #ifdef IFF_PORTSEL |
Manuel Novoa III | b1d5b74 | 2003-08-02 00:04:18 +0000 | [diff] [blame] | 1660 | #if 0 |
| 1661 | static const char * const if_port_text[][4] = { |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1662 | /* Keep in step with <linux/netdevice.h> */ |
| 1663 | {"unknown", NULL, NULL, NULL}, |
| 1664 | {"10base2", "bnc", "coax", NULL}, |
| 1665 | {"10baseT", "utp", "tpe", NULL}, |
| 1666 | {"AUI", "thick", "db15", NULL}, |
| 1667 | {"100baseT", NULL, NULL, NULL}, |
| 1668 | {"100baseTX", NULL, NULL, NULL}, |
| 1669 | {"100baseFX", NULL, NULL, NULL}, |
| 1670 | {NULL, NULL, NULL, NULL}, |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1671 | }; |
Manuel Novoa III | b1d5b74 | 2003-08-02 00:04:18 +0000 | [diff] [blame] | 1672 | #else |
| 1673 | static const char * const if_port_text[] = { |
| 1674 | /* Keep in step with <linux/netdevice.h> */ |
| 1675 | "unknown", |
| 1676 | "10base2", |
| 1677 | "10baseT", |
| 1678 | "AUI", |
| 1679 | "100baseT", |
| 1680 | "100baseTX", |
| 1681 | "100baseFX", |
| 1682 | NULL |
| 1683 | }; |
| 1684 | #endif |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1685 | #endif |
| 1686 | |
| 1687 | /* Check our hardware type table for this type. */ |
"Vladimir N. Oleynik" | 0fa9ded | 2005-10-20 09:48:28 +0000 | [diff] [blame] | 1688 | static const struct hwtype *get_hwntype(int type) |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1689 | { |
"Vladimir N. Oleynik" | 0fa9ded | 2005-10-20 09:48:28 +0000 | [diff] [blame] | 1690 | const struct hwtype * const *hwp; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1691 | |
Manuel Novoa III | 68ea1d0 | 2001-03-12 09:57:59 +0000 | [diff] [blame] | 1692 | #ifdef KEEP_UNUSED |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1693 | if (!sVhwinit) |
| 1694 | hwinit(); |
| 1695 | #endif /* KEEP_UNUSED */ |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1696 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1697 | hwp = hwtypes; |
| 1698 | while (*hwp != NULL) { |
| 1699 | if ((*hwp)->type == type) |
| 1700 | return (*hwp); |
| 1701 | hwp++; |
| 1702 | } |
| 1703 | return (NULL); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1704 | } |
| 1705 | |
| 1706 | /* return 1 if address is all zeros */ |
"Vladimir N. Oleynik" | 0fa9ded | 2005-10-20 09:48:28 +0000 | [diff] [blame] | 1707 | static int hw_null_address(const struct hwtype *hw, void *ap) |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1708 | { |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1709 | unsigned int i; |
| 1710 | unsigned char *address = (unsigned char *) ap; |
| 1711 | |
| 1712 | for (i = 0; i < hw->alen; i++) |
| 1713 | if (address[i]) |
| 1714 | return 0; |
| 1715 | return 1; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1716 | } |
| 1717 | |
Manuel Novoa III | b1d5b74 | 2003-08-02 00:04:18 +0000 | [diff] [blame] | 1718 | static const char TRext[] = "\0\0\0Ki\0Mi\0Gi\0Ti"; |
Manuel Novoa III | 68ea1d0 | 2001-03-12 09:57:59 +0000 | [diff] [blame] | 1719 | |
| 1720 | static void print_bytes_scaled(unsigned long long ull, const char *end) |
| 1721 | { |
| 1722 | unsigned long long int_part; |
Manuel Novoa III | 68ea1d0 | 2001-03-12 09:57:59 +0000 | [diff] [blame] | 1723 | const char *ext; |
Manuel Novoa III | b1d5b74 | 2003-08-02 00:04:18 +0000 | [diff] [blame] | 1724 | unsigned int frac_part; |
Manuel Novoa III | 68ea1d0 | 2001-03-12 09:57:59 +0000 | [diff] [blame] | 1725 | int i; |
| 1726 | |
| 1727 | frac_part = 0; |
| 1728 | ext = TRext; |
| 1729 | int_part = ull; |
Manuel Novoa III | b1d5b74 | 2003-08-02 00:04:18 +0000 | [diff] [blame] | 1730 | i = 4; |
| 1731 | do { |
| 1732 | #if 0 |
| 1733 | /* This does correct rounding and is a little larger. But it |
| 1734 | * uses KiB as the smallest displayed unit. */ |
| 1735 | if ((int_part < (1024*1024 - 51)) || !--i) { |
| 1736 | i = 0; |
| 1737 | int_part += 51; /* 1024*.05 = 51.2 */ |
| 1738 | frac_part = ((((unsigned int) int_part) & (1024-1)) * 10) / 1024; |
Manuel Novoa III | 68ea1d0 | 2001-03-12 09:57:59 +0000 | [diff] [blame] | 1739 | } |
Manuel Novoa III | b1d5b74 | 2003-08-02 00:04:18 +0000 | [diff] [blame] | 1740 | int_part /= 1024; |
| 1741 | ext += 3; /* KiB, MiB, GiB, TiB */ |
| 1742 | #else |
| 1743 | if (int_part >= 1024) { |
| 1744 | frac_part = ((((unsigned int) int_part) & (1024-1)) * 10) / 1024; |
| 1745 | int_part /= 1024; |
| 1746 | ext += 3; /* KiB, MiB, GiB, TiB */ |
| 1747 | } |
| 1748 | --i; |
| 1749 | #endif |
| 1750 | } while (i); |
Manuel Novoa III | 68ea1d0 | 2001-03-12 09:57:59 +0000 | [diff] [blame] | 1751 | |
Manuel Novoa III | b1d5b74 | 2003-08-02 00:04:18 +0000 | [diff] [blame] | 1752 | printf("X bytes:%Lu (%Lu.%u %sB)%s", ull, int_part, frac_part, ext, end); |
Manuel Novoa III | 68ea1d0 | 2001-03-12 09:57:59 +0000 | [diff] [blame] | 1753 | } |
| 1754 | |
Manuel Novoa III | b1d5b74 | 2003-08-02 00:04:18 +0000 | [diff] [blame] | 1755 | static const char * const ife_print_flags_strs[] = { |
| 1756 | "UP ", |
| 1757 | "BROADCAST ", |
| 1758 | "DEBUG ", |
| 1759 | "LOOPBACK ", |
| 1760 | "POINTOPOINT ", |
| 1761 | "NOTRAILERS ", |
| 1762 | "RUNNING ", |
| 1763 | "NOARP ", |
| 1764 | "PROMISC ", |
| 1765 | "ALLMULTI ", |
| 1766 | "SLAVE ", |
| 1767 | "MASTER ", |
| 1768 | "MULTICAST ", |
| 1769 | #ifdef HAVE_DYNAMIC |
| 1770 | "DYNAMIC " |
| 1771 | #endif |
| 1772 | }; |
| 1773 | |
| 1774 | static const unsigned short ife_print_flags_mask[] = { |
| 1775 | IFF_UP, |
| 1776 | IFF_BROADCAST, |
| 1777 | IFF_DEBUG, |
| 1778 | IFF_LOOPBACK, |
| 1779 | IFF_POINTOPOINT, |
| 1780 | IFF_NOTRAILERS, |
| 1781 | IFF_RUNNING, |
| 1782 | IFF_NOARP, |
| 1783 | IFF_PROMISC, |
| 1784 | IFF_ALLMULTI, |
| 1785 | IFF_SLAVE, |
| 1786 | IFF_MASTER, |
| 1787 | IFF_MULTICAST, |
| 1788 | #ifdef HAVE_DYNAMIC |
| 1789 | IFF_DYNAMIC |
| 1790 | #endif |
| 1791 | 0 |
| 1792 | }; |
| 1793 | |
Manuel Novoa III | 68ea1d0 | 2001-03-12 09:57:59 +0000 | [diff] [blame] | 1794 | static void ife_print(struct interface *ptr) |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1795 | { |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1796 | struct aftype *ap; |
"Vladimir N. Oleynik" | 0fa9ded | 2005-10-20 09:48:28 +0000 | [diff] [blame] | 1797 | const struct hwtype *hw; |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1798 | int hf; |
| 1799 | int can_compress = 0; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1800 | |
| 1801 | #if HAVE_AFIPX |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1802 | static struct aftype *ipxtype = NULL; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1803 | #endif |
| 1804 | #if HAVE_AFECONET |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1805 | static struct aftype *ectype = NULL; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1806 | #endif |
| 1807 | #if HAVE_AFATALK |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1808 | static struct aftype *ddptype = NULL; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1809 | #endif |
| 1810 | #if HAVE_AFINET6 |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1811 | FILE *f; |
| 1812 | char addr6[40], devname[20]; |
| 1813 | struct sockaddr_in6 sap; |
| 1814 | int plen, scope, dad_status, if_idx; |
| 1815 | char addr6p[8][5]; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1816 | #endif |
| 1817 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1818 | ap = get_afntype(ptr->addr.sa_family); |
| 1819 | if (ap == NULL) |
| 1820 | ap = get_afntype(0); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1821 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1822 | hf = ptr->type; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1823 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1824 | if (hf == ARPHRD_CSLIP || hf == ARPHRD_CSLIP6) |
| 1825 | can_compress = 1; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1826 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1827 | hw = get_hwntype(hf); |
| 1828 | if (hw == NULL) |
| 1829 | hw = get_hwntype(-1); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1830 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1831 | printf(_("%-9.9s Link encap:%s "), ptr->name, _(hw->title)); |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 1832 | /* For some hardware types (eg Ash, ATM) we don't print the |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1833 | hardware address if it's null. */ |
| 1834 | if (hw->print != NULL && (!(hw_null_address(hw, ptr->hwaddr) && |
| 1835 | hw->suppress_null_addr))) |
| 1836 | printf(_("HWaddr %s "), hw->print(ptr->hwaddr)); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1837 | #ifdef IFF_PORTSEL |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1838 | if (ptr->flags & IFF_PORTSEL) { |
Manuel Novoa III | b1d5b74 | 2003-08-02 00:04:18 +0000 | [diff] [blame] | 1839 | printf(_("Media:%s"), if_port_text[ptr->map.port] /* [0] */); |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1840 | if (ptr->flags & IFF_AUTOMEDIA) |
| 1841 | printf(_("(auto)")); |
| 1842 | } |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1843 | #endif |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1844 | printf("\n"); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1845 | |
| 1846 | #if HAVE_AFINET |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1847 | if (ptr->has_ip) { |
| 1848 | printf(_(" %s addr:%s "), ap->name, |
| 1849 | ap->sprint(&ptr->addr, 1)); |
| 1850 | if (ptr->flags & IFF_POINTOPOINT) { |
| 1851 | printf(_(" P-t-P:%s "), ap->sprint(&ptr->dstaddr, 1)); |
| 1852 | } |
| 1853 | if (ptr->flags & IFF_BROADCAST) { |
| 1854 | printf(_(" Bcast:%s "), ap->sprint(&ptr->broadaddr, 1)); |
| 1855 | } |
| 1856 | printf(_(" Mask:%s\n"), ap->sprint(&ptr->netmask, 1)); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1857 | } |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1858 | #endif |
| 1859 | |
| 1860 | #if HAVE_AFINET6 |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1861 | |
Eric Andersen | 51b8bd6 | 2002-07-03 11:46:38 +0000 | [diff] [blame] | 1862 | #define IPV6_ADDR_ANY 0x0000U |
| 1863 | |
| 1864 | #define IPV6_ADDR_UNICAST 0x0001U |
| 1865 | #define IPV6_ADDR_MULTICAST 0x0002U |
| 1866 | #define IPV6_ADDR_ANYCAST 0x0004U |
| 1867 | |
| 1868 | #define IPV6_ADDR_LOOPBACK 0x0010U |
| 1869 | #define IPV6_ADDR_LINKLOCAL 0x0020U |
| 1870 | #define IPV6_ADDR_SITELOCAL 0x0040U |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1871 | |
Eric Andersen | 51b8bd6 | 2002-07-03 11:46:38 +0000 | [diff] [blame] | 1872 | #define IPV6_ADDR_COMPATv4 0x0080U |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1873 | |
Eric Andersen | 51b8bd6 | 2002-07-03 11:46:38 +0000 | [diff] [blame] | 1874 | #define IPV6_ADDR_SCOPE_MASK 0x00f0U |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1875 | |
Eric Andersen | 51b8bd6 | 2002-07-03 11:46:38 +0000 | [diff] [blame] | 1876 | #define IPV6_ADDR_MAPPED 0x1000U |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1877 | #define IPV6_ADDR_RESERVED 0x2000U /* reserved address space */ |
| 1878 | |
| 1879 | if ((f = fopen(_PATH_PROCNET_IFINET6, "r")) != NULL) { |
| 1880 | while (fscanf |
| 1881 | (f, "%4s%4s%4s%4s%4s%4s%4s%4s %02x %02x %02x %02x %20s\n", |
| 1882 | addr6p[0], addr6p[1], addr6p[2], addr6p[3], addr6p[4], |
| 1883 | addr6p[5], addr6p[6], addr6p[7], &if_idx, &plen, &scope, |
| 1884 | &dad_status, devname) != EOF) { |
| 1885 | if (!strcmp(devname, ptr->name)) { |
| 1886 | sprintf(addr6, "%s:%s:%s:%s:%s:%s:%s:%s", |
| 1887 | addr6p[0], addr6p[1], addr6p[2], addr6p[3], |
| 1888 | addr6p[4], addr6p[5], addr6p[6], addr6p[7]); |
| 1889 | inet_pton(AF_INET6, addr6, |
| 1890 | (struct sockaddr *) &sap.sin6_addr); |
| 1891 | sap.sin6_family = AF_INET6; |
| 1892 | printf(_(" inet6 addr: %s/%d"), |
| 1893 | inet6_aftype.sprint((struct sockaddr *) &sap, 1), |
| 1894 | plen); |
| 1895 | printf(_(" Scope:")); |
| 1896 | switch (scope & IPV6_ADDR_SCOPE_MASK) { |
| 1897 | case 0: |
| 1898 | printf(_("Global")); |
| 1899 | break; |
| 1900 | case IPV6_ADDR_LINKLOCAL: |
| 1901 | printf(_("Link")); |
| 1902 | break; |
| 1903 | case IPV6_ADDR_SITELOCAL: |
| 1904 | printf(_("Site")); |
| 1905 | break; |
| 1906 | case IPV6_ADDR_COMPATv4: |
| 1907 | printf(_("Compat")); |
| 1908 | break; |
| 1909 | case IPV6_ADDR_LOOPBACK: |
| 1910 | printf(_("Host")); |
| 1911 | break; |
| 1912 | default: |
| 1913 | printf(_("Unknown")); |
| 1914 | } |
| 1915 | printf("\n"); |
| 1916 | } |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1917 | } |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1918 | fclose(f); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1919 | } |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1920 | #endif |
| 1921 | |
| 1922 | #if HAVE_AFIPX |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1923 | if (ipxtype == NULL) |
| 1924 | ipxtype = get_afntype(AF_IPX); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1925 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1926 | if (ipxtype != NULL) { |
| 1927 | if (ptr->has_ipx_bb) |
| 1928 | printf(_(" IPX/Ethernet II addr:%s\n"), |
| 1929 | ipxtype->sprint(&ptr->ipxaddr_bb, 1)); |
| 1930 | if (ptr->has_ipx_sn) |
| 1931 | printf(_(" IPX/Ethernet SNAP addr:%s\n"), |
| 1932 | ipxtype->sprint(&ptr->ipxaddr_sn, 1)); |
| 1933 | if (ptr->has_ipx_e2) |
| 1934 | printf(_(" IPX/Ethernet 802.2 addr:%s\n"), |
| 1935 | ipxtype->sprint(&ptr->ipxaddr_e2, 1)); |
| 1936 | if (ptr->has_ipx_e3) |
| 1937 | printf(_(" IPX/Ethernet 802.3 addr:%s\n"), |
| 1938 | ipxtype->sprint(&ptr->ipxaddr_e3, 1)); |
| 1939 | } |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1940 | #endif |
| 1941 | |
| 1942 | #if HAVE_AFATALK |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1943 | if (ddptype == NULL) |
| 1944 | ddptype = get_afntype(AF_APPLETALK); |
| 1945 | if (ddptype != NULL) { |
| 1946 | if (ptr->has_ddp) |
| 1947 | printf(_(" EtherTalk Phase 2 addr:%s\n"), |
| 1948 | ddptype->sprint(&ptr->ddpaddr, 1)); |
| 1949 | } |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1950 | #endif |
| 1951 | |
| 1952 | #if HAVE_AFECONET |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1953 | if (ectype == NULL) |
| 1954 | ectype = get_afntype(AF_ECONET); |
| 1955 | if (ectype != NULL) { |
| 1956 | if (ptr->has_econet) |
| 1957 | printf(_(" econet addr:%s\n"), |
| 1958 | ectype->sprint(&ptr->ecaddr, 1)); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1959 | } |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1960 | #endif |
| 1961 | |
| 1962 | printf(" "); |
| 1963 | /* DONT FORGET TO ADD THE FLAGS IN ife_print_short, too */ |
Manuel Novoa III | b1d5b74 | 2003-08-02 00:04:18 +0000 | [diff] [blame] | 1964 | |
| 1965 | if (ptr->flags == 0) { |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1966 | printf(_("[NO FLAGS] ")); |
Manuel Novoa III | b1d5b74 | 2003-08-02 00:04:18 +0000 | [diff] [blame] | 1967 | } else { |
| 1968 | int i = 0; |
| 1969 | do { |
| 1970 | if (ptr->flags & ife_print_flags_mask[i]) { |
| 1971 | printf(_(ife_print_flags_strs[i])); |
| 1972 | } |
| 1973 | } while (ife_print_flags_mask[++i]); |
| 1974 | } |
| 1975 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1976 | /* DONT FORGET TO ADD THE FLAGS IN ife_print_short */ |
| 1977 | printf(_(" MTU:%d Metric:%d"), ptr->mtu, ptr->metric ? ptr->metric : 1); |
| 1978 | #ifdef SIOCSKEEPALIVE |
| 1979 | if (ptr->outfill || ptr->keepalive) |
| 1980 | printf(_(" Outfill:%d Keepalive:%d"), ptr->outfill, ptr->keepalive); |
| 1981 | #endif |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 1982 | printf("\n"); |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1983 | |
| 1984 | /* If needed, display the interface statistics. */ |
| 1985 | |
| 1986 | if (ptr->statistics_valid) { |
| 1987 | /* XXX: statistics are currently only printed for the primary address, |
| 1988 | * not for the aliases, although strictly speaking they're shared |
| 1989 | * by all addresses. |
| 1990 | */ |
| 1991 | printf(" "); |
| 1992 | |
Manuel Novoa III | b1d5b74 | 2003-08-02 00:04:18 +0000 | [diff] [blame] | 1993 | printf(_("RX packets:%Lu errors:%lu dropped:%lu overruns:%lu frame:%lu\n"), |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 1994 | ptr->stats.rx_packets, ptr->stats.rx_errors, |
| 1995 | ptr->stats.rx_dropped, ptr->stats.rx_fifo_errors, |
| 1996 | ptr->stats.rx_frame_errors); |
| 1997 | if (can_compress) |
| 1998 | printf(_(" compressed:%lu\n"), |
| 1999 | ptr->stats.rx_compressed); |
| 2000 | printf(" "); |
Manuel Novoa III | b1d5b74 | 2003-08-02 00:04:18 +0000 | [diff] [blame] | 2001 | printf(_("TX packets:%Lu errors:%lu dropped:%lu overruns:%lu carrier:%lu\n"), |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 2002 | ptr->stats.tx_packets, ptr->stats.tx_errors, |
| 2003 | ptr->stats.tx_dropped, ptr->stats.tx_fifo_errors, |
| 2004 | ptr->stats.tx_carrier_errors); |
| 2005 | printf(_(" collisions:%lu "), ptr->stats.collisions); |
| 2006 | if (can_compress) |
| 2007 | printf(_("compressed:%lu "), ptr->stats.tx_compressed); |
| 2008 | if (ptr->tx_queue_len != -1) |
| 2009 | printf(_("txqueuelen:%d "), ptr->tx_queue_len); |
| 2010 | printf("\n R"); |
| 2011 | print_bytes_scaled(ptr->stats.rx_bytes, " T"); |
| 2012 | print_bytes_scaled(ptr->stats.tx_bytes, "\n"); |
| 2013 | |
| 2014 | } |
| 2015 | |
| 2016 | if ((ptr->map.irq || ptr->map.mem_start || ptr->map.dma || |
| 2017 | ptr->map.base_addr)) { |
| 2018 | printf(" "); |
| 2019 | if (ptr->map.irq) |
| 2020 | printf(_("Interrupt:%d "), ptr->map.irq); |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 2021 | if (ptr->map.base_addr >= 0x100) /* Only print devices using it for |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 2022 | I/O maps */ |
| 2023 | printf(_("Base address:0x%lx "), |
| 2024 | (unsigned long) ptr->map.base_addr); |
| 2025 | if (ptr->map.mem_start) { |
| 2026 | printf(_("Memory:%lx-%lx "), ptr->map.mem_start, |
| 2027 | ptr->map.mem_end); |
| 2028 | } |
| 2029 | if (ptr->map.dma) |
| 2030 | printf(_("DMA chan:%x "), ptr->map.dma); |
| 2031 | printf("\n"); |
| 2032 | } |
| 2033 | printf("\n"); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 2034 | } |
| 2035 | |
| 2036 | |
Manuel Novoa III | 68ea1d0 | 2001-03-12 09:57:59 +0000 | [diff] [blame] | 2037 | static int do_if_print(struct interface *ife, void *cookie) |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 2038 | { |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 2039 | int *opt_a = (int *) cookie; |
| 2040 | int res; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 2041 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 2042 | res = do_if_fetch(ife); |
| 2043 | if (res >= 0) { |
| 2044 | if ((ife->flags & IFF_UP) || *opt_a) |
| 2045 | ife_print(ife); |
| 2046 | } |
| 2047 | return res; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 2048 | } |
| 2049 | |
Manuel Novoa III | 68ea1d0 | 2001-03-12 09:57:59 +0000 | [diff] [blame] | 2050 | static struct interface *lookup_interface(char *name) |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 2051 | { |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 2052 | struct interface *ife = NULL; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 2053 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 2054 | if (if_readlist_proc(name) < 0) |
| 2055 | return NULL; |
| 2056 | ife = add_interface(name); |
| 2057 | return ife; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 2058 | } |
| 2059 | |
| 2060 | /* for ipv4 add/del modes */ |
| 2061 | static int if_print(char *ifname) |
| 2062 | { |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 2063 | int res; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 2064 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 2065 | if (!ifname) { |
| 2066 | res = for_all_interfaces(do_if_print, &interface_opt_a); |
| 2067 | } else { |
| 2068 | struct interface *ife; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 2069 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 2070 | ife = lookup_interface(ifname); |
| 2071 | res = do_if_fetch(ife); |
| 2072 | if (res >= 0) |
| 2073 | ife_print(ife); |
| 2074 | } |
| 2075 | return res; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 2076 | } |
| 2077 | |
Manuel Novoa III | 68ea1d0 | 2001-03-12 09:57:59 +0000 | [diff] [blame] | 2078 | int display_interfaces(char *ifname) |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 2079 | { |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 2080 | int status; |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 2081 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 2082 | /* Create a channel to the NET kernel. */ |
| 2083 | if ((skfd = sockets_open(0)) < 0) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 2084 | bb_perror_msg_and_die("socket"); |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 2085 | } |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 2086 | |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 2087 | /* Do we have to show the current setup? */ |
| 2088 | status = if_print(ifname); |
Rob Landley | 9398304 | 2005-05-03 21:30:26 +0000 | [diff] [blame] | 2089 | #ifdef CONFIG_FEATURE_CLEAN_UP |
| 2090 | sockets_close(); |
| 2091 | #endif |
Glenn L McGrath | 1ed9dd9 | 2002-08-22 19:35:36 +0000 | [diff] [blame] | 2092 | exit(status < 0); |
Eric Andersen | f15d4da | 2001-03-06 00:48:59 +0000 | [diff] [blame] | 2093 | } |