comparison toys/other/ifconfig.c @ 1133:f8c926309a21 draft

Cleanup help text, remove dead fields unused by linux kernel.
author Rob Landley <rob@landley.net>
date Sat, 30 Nov 2013 00:16:28 -0600
parents 615505bb38b6
children 63f8c7fa94d7
comparison
equal deleted inserted replaced
1132:615505bb38b6 1133:f8c926309a21
10 10
11 config IFCONFIG 11 config IFCONFIG
12 bool "ifconfig" 12 bool "ifconfig"
13 default y 13 default y
14 help 14 help
15 usage: ifconfig [-a] interface [address] 15 usage: ifconfig [-a] [INTERFACE [ACTION...]]
16 16
17 Configure network interface. 17 Display or configure network interface.
18 18
19 [add ADDRESS[/PREFIXLEN]] 19 With no arguments, display active interfaces. First argument is interface
20 [del ADDRESS[/PREFIXLEN]] 20 to operate on, one argument by itself displays that interface.
21 [[-]broadcast [ADDRESS]] [[-]pointopoint [ADDRESS]] 21
22 [netmask ADDRESS] [dstaddr ADDRESS] 22 -a Show all interfaces, not just active ones
23 [outfill NN] [keepalive NN] 23
24 [hw ether|infiniband ADDRESS] [metric NN] [mtu NN] 24 Additional arguments are actions to perform on the interface:
25 [[-]trailers] [[-]arp] [[-]allmulti] 25
26 [multicast] [[-]promisc] [txqueuelen NN] [[-]dynamic] 26 ADDRESS[/NETMASK] - set IPv4 address (1.2.3.4/5)
27 [mem_start NN] [io_addr NN] [irq NN] 27 default - unset ipv4 address
28 [up|down] ... 28 add|del ADDRESS[/PREFIXLEN] - add/remove IPv6 address (1111::8888/128)
29 up - enable interface
30 down - disable interface
31
32 netmask|broadcast|pointopoint ADDRESS - set more IPv4 characteristics
33 hw ether|infiniband ADDRESS - set LAN hardware address (AA:BB:CC...)
34 txqueuelen LEN - number of buffered packets before output blocks
35 mtu LEN - size of outgoing packets (Maximum Transmission Unit)
36
37 Flags you can set on an interface (or -remove by prefixing with -):
38 arp - don't use Address Resolution Protocol to map LAN routes
39 promisc - don't discard packets that aren't to this LAN hardware address
40 multicast - force interface into multicast mode if the driver doesn't
41 allmulti - promisc for multicast packets
42
43 Obsolete fields included for historical purposes:
44 irq|io_addr|mem_start ADDR - micromanage obsolete hardware
45 outfill|keepalive INTEGER - SLIP analog dialup line quality monitoring
46 metric INTEGER - added to Linux 0.9.10 with comment "never used", still true
29 */ 47 */
30 48
31 #define FOR_ifconfig 49 #define FOR_ifconfig
32 #include "toys.h" 50 #include "toys.h"
33 51
60 if (!status) 78 if (!status)
61 for (rp = result; rp; rp = rp->ai_next) 79 for (rp = result; rp; rp = rp->ai_next)
62 if (rp->ai_family == af) break; 80 if (rp->ai_family == af) break;
63 if (!rp) error_exit("bad address '%s' : %s", host, gai_strerror(status)); 81 if (!rp) error_exit("bad address '%s' : %s", host, gai_strerror(status));
64 82
65 // You'd think ipv4 and ipv6 would ahve some basic compatability, but no. 83 // ai_addr isn't struct in_addr or in6_addr, it's struct sockaddr. Of course.
66 len = 4; 84 // You'd think ipv4 and ipv6 would have some basic compatibility, but no.
67 from = ((char *)rp->ai_addr->sa_data) + 2; 85 from = ((char *)rp->ai_addr) + 4;
68 if (af == AF_INET6) { 86 if (af == AF_INET6) {
69 len = 16; 87 len = 16;
70 from += 4; 88 from += 4; // skip "flowinfo" field ipv6 puts before address
71 } 89 } else len = 4;
72 memcpy(addr, from, len); 90 memcpy(addr, from, len);
73 freeaddrinfo(result); 91 freeaddrinfo(result);
74 } 92 }
75 93
76 static void display_ifconfig(char *name, int always, unsigned long long val[]) 94 static void display_ifconfig(char *name, int always, unsigned long long val[])
342 } try[] = { 360 } try[] = {
343 {0, IFF_UP|IFF_RUNNING, SIOCSIFADDR}, 361 {0, IFF_UP|IFF_RUNNING, SIOCSIFADDR},
344 {"up", IFF_UP|IFF_RUNNING, 0}, 362 {"up", IFF_UP|IFF_RUNNING, 0},
345 {"down", 0, IFF_UP}, 363 {"down", 0, IFF_UP},
346 {"arp", 0, IFF_NOARP}, 364 {"arp", 0, IFF_NOARP},
347 {"trailers", 0, IFF_NOTRAILERS},
348 {"promisc", IFF_PROMISC, 0}, 365 {"promisc", IFF_PROMISC, 0},
349 {"allmulti", IFF_ALLMULTI, 0}, 366 {"allmulti", IFF_ALLMULTI, 0},
350 {"multicast", IFF_MULTICAST, 0}, 367 {"multicast", IFF_MULTICAST, 0},
351 {"dynamic", IFF_DYNAMIC, 0},
352 {"pointopoint", IFF_POINTOPOINT, SIOCSIFDSTADDR}, 368 {"pointopoint", IFF_POINTOPOINT, SIOCSIFDSTADDR},
353 {"broadcast", IFF_BROADCAST, SIOCSIFBRDADDR}, 369 {"broadcast", IFF_BROADCAST, SIOCSIFBRDADDR},
354 {"netmask", 0, SIOCSIFNETMASK}, 370 {"netmask", 0, SIOCSIFNETMASK},
355 {"dstaddr", 0, SIOCSIFDSTADDR}, 371 {"dstaddr", 0, SIOCSIFDSTADDR},
356 {"mtu", IFREQ_OFFSZ(ifr_mtu), SIOCSIFMTU}, 372 {"mtu", IFREQ_OFFSZ(ifr_mtu), SIOCSIFMTU},