annotate toys/other/ifconfig.c @ 1714:0c8ef714cf03 draft

Patches from Elliott Hughes to fix various printf() format strings. (Don't specify the space flag when it's the default behavior. The ifconfig stuff was actual bugs.)
author Rob Landley <rob@landley.net>
date Sun, 01 Mar 2015 16:08:51 -0600
parents 8d52be1c6cf3
children 57f2a26fa92c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
841
cb0c3a773437 Kyungwan Han submitted ifconfig.
Rob Landley <rob@landley.net>
parents:
diff changeset
1 /* ifconfig.c - Configure network interface.
cb0c3a773437 Kyungwan Han submitted ifconfig.
Rob Landley <rob@landley.net>
parents:
diff changeset
2 *
844
f8250900f94b More ifconfig cleanups, mostly removing unused code.
Rob Landley <rob@landley.net>
parents: 843
diff changeset
3 * Copyright 2012 Ranjan Kumar <ranjankumar.bth@gmail.com>
f8250900f94b More ifconfig cleanups, mostly removing unused code.
Rob Landley <rob@landley.net>
parents: 843
diff changeset
4 * Copyright 2012 Kyungwan Han <asura321@gamil.com>
f8250900f94b More ifconfig cleanups, mostly removing unused code.
Rob Landley <rob@landley.net>
parents: 843
diff changeset
5 * Reviewed by Kyungsu Kim <kaspyx@gmail.com>
841
cb0c3a773437 Kyungwan Han submitted ifconfig.
Rob Landley <rob@landley.net>
parents:
diff changeset
6 *
cb0c3a773437 Kyungwan Han submitted ifconfig.
Rob Landley <rob@landley.net>
parents:
diff changeset
7 * Not in SUSv4.
844
f8250900f94b More ifconfig cleanups, mostly removing unused code.
Rob Landley <rob@landley.net>
parents: 843
diff changeset
8
1518
4bfbd8b96f66 Various bugfixes (mostly resource leaks) from Ashwini Sharma's static analysis, plus occasional tweak by me while reviewing them.
Rob Landley <rob@landley.net>
parents: 1433
diff changeset
9 USE_IFCONFIG(NEWTOY(ifconfig, "^?a", TOYFLAG_BIN))
844
f8250900f94b More ifconfig cleanups, mostly removing unused code.
Rob Landley <rob@landley.net>
parents: 843
diff changeset
10
841
cb0c3a773437 Kyungwan Han submitted ifconfig.
Rob Landley <rob@landley.net>
parents:
diff changeset
11 config IFCONFIG
cb0c3a773437 Kyungwan Han submitted ifconfig.
Rob Landley <rob@landley.net>
parents:
diff changeset
12 bool "ifconfig"
921
6a37f642b572 Yet more ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 919
diff changeset
13 default y
841
cb0c3a773437 Kyungwan Han submitted ifconfig.
Rob Landley <rob@landley.net>
parents:
diff changeset
14 help
1133
f8c926309a21 Cleanup help text, remove dead fields unused by linux kernel.
Rob Landley <rob@landley.net>
parents: 1132
diff changeset
15 usage: ifconfig [-a] [INTERFACE [ACTION...]]
f8c926309a21 Cleanup help text, remove dead fields unused by linux kernel.
Rob Landley <rob@landley.net>
parents: 1132
diff changeset
16
f8c926309a21 Cleanup help text, remove dead fields unused by linux kernel.
Rob Landley <rob@landley.net>
parents: 1132
diff changeset
17 Display or configure network interface.
841
cb0c3a773437 Kyungwan Han submitted ifconfig.
Rob Landley <rob@landley.net>
parents:
diff changeset
18
1133
f8c926309a21 Cleanup help text, remove dead fields unused by linux kernel.
Rob Landley <rob@landley.net>
parents: 1132
diff changeset
19 With no arguments, display active interfaces. First argument is interface
f8c926309a21 Cleanup help text, remove dead fields unused by linux kernel.
Rob Landley <rob@landley.net>
parents: 1132
diff changeset
20 to operate on, one argument by itself displays that interface.
f8c926309a21 Cleanup help text, remove dead fields unused by linux kernel.
Rob Landley <rob@landley.net>
parents: 1132
diff changeset
21
f8c926309a21 Cleanup help text, remove dead fields unused by linux kernel.
Rob Landley <rob@landley.net>
parents: 1132
diff changeset
22 -a Show all interfaces, not just active ones
f8c926309a21 Cleanup help text, remove dead fields unused by linux kernel.
Rob Landley <rob@landley.net>
parents: 1132
diff changeset
23
f8c926309a21 Cleanup help text, remove dead fields unused by linux kernel.
Rob Landley <rob@landley.net>
parents: 1132
diff changeset
24 Additional arguments are actions to perform on the interface:
841
cb0c3a773437 Kyungwan Han submitted ifconfig.
Rob Landley <rob@landley.net>
parents:
diff changeset
25
1133
f8c926309a21 Cleanup help text, remove dead fields unused by linux kernel.
Rob Landley <rob@landley.net>
parents: 1132
diff changeset
26 ADDRESS[/NETMASK] - set IPv4 address (1.2.3.4/5)
f8c926309a21 Cleanup help text, remove dead fields unused by linux kernel.
Rob Landley <rob@landley.net>
parents: 1132
diff changeset
27 default - unset ipv4 address
f8c926309a21 Cleanup help text, remove dead fields unused by linux kernel.
Rob Landley <rob@landley.net>
parents: 1132
diff changeset
28 add|del ADDRESS[/PREFIXLEN] - add/remove IPv6 address (1111::8888/128)
f8c926309a21 Cleanup help text, remove dead fields unused by linux kernel.
Rob Landley <rob@landley.net>
parents: 1132
diff changeset
29 up - enable interface
f8c926309a21 Cleanup help text, remove dead fields unused by linux kernel.
Rob Landley <rob@landley.net>
parents: 1132
diff changeset
30 down - disable interface
f8c926309a21 Cleanup help text, remove dead fields unused by linux kernel.
Rob Landley <rob@landley.net>
parents: 1132
diff changeset
31
f8c926309a21 Cleanup help text, remove dead fields unused by linux kernel.
Rob Landley <rob@landley.net>
parents: 1132
diff changeset
32 netmask|broadcast|pointopoint ADDRESS - set more IPv4 characteristics
f8c926309a21 Cleanup help text, remove dead fields unused by linux kernel.
Rob Landley <rob@landley.net>
parents: 1132
diff changeset
33 hw ether|infiniband ADDRESS - set LAN hardware address (AA:BB:CC...)
f8c926309a21 Cleanup help text, remove dead fields unused by linux kernel.
Rob Landley <rob@landley.net>
parents: 1132
diff changeset
34 txqueuelen LEN - number of buffered packets before output blocks
f8c926309a21 Cleanup help text, remove dead fields unused by linux kernel.
Rob Landley <rob@landley.net>
parents: 1132
diff changeset
35 mtu LEN - size of outgoing packets (Maximum Transmission Unit)
f8c926309a21 Cleanup help text, remove dead fields unused by linux kernel.
Rob Landley <rob@landley.net>
parents: 1132
diff changeset
36
f8c926309a21 Cleanup help text, remove dead fields unused by linux kernel.
Rob Landley <rob@landley.net>
parents: 1132
diff changeset
37 Flags you can set on an interface (or -remove by prefixing with -):
f8c926309a21 Cleanup help text, remove dead fields unused by linux kernel.
Rob Landley <rob@landley.net>
parents: 1132
diff changeset
38 arp - don't use Address Resolution Protocol to map LAN routes
f8c926309a21 Cleanup help text, remove dead fields unused by linux kernel.
Rob Landley <rob@landley.net>
parents: 1132
diff changeset
39 promisc - don't discard packets that aren't to this LAN hardware address
f8c926309a21 Cleanup help text, remove dead fields unused by linux kernel.
Rob Landley <rob@landley.net>
parents: 1132
diff changeset
40 multicast - force interface into multicast mode if the driver doesn't
f8c926309a21 Cleanup help text, remove dead fields unused by linux kernel.
Rob Landley <rob@landley.net>
parents: 1132
diff changeset
41 allmulti - promisc for multicast packets
f8c926309a21 Cleanup help text, remove dead fields unused by linux kernel.
Rob Landley <rob@landley.net>
parents: 1132
diff changeset
42
f8c926309a21 Cleanup help text, remove dead fields unused by linux kernel.
Rob Landley <rob@landley.net>
parents: 1132
diff changeset
43 Obsolete fields included for historical purposes:
f8c926309a21 Cleanup help text, remove dead fields unused by linux kernel.
Rob Landley <rob@landley.net>
parents: 1132
diff changeset
44 irq|io_addr|mem_start ADDR - micromanage obsolete hardware
f8c926309a21 Cleanup help text, remove dead fields unused by linux kernel.
Rob Landley <rob@landley.net>
parents: 1132
diff changeset
45 outfill|keepalive INTEGER - SLIP analog dialup line quality monitoring
f8c926309a21 Cleanup help text, remove dead fields unused by linux kernel.
Rob Landley <rob@landley.net>
parents: 1132
diff changeset
46 metric INTEGER - added to Linux 0.9.10 with comment "never used", still true
841
cb0c3a773437 Kyungwan Han submitted ifconfig.
Rob Landley <rob@landley.net>
parents:
diff changeset
47 */
cb0c3a773437 Kyungwan Han submitted ifconfig.
Rob Landley <rob@landley.net>
parents:
diff changeset
48
cb0c3a773437 Kyungwan Han submitted ifconfig.
Rob Landley <rob@landley.net>
parents:
diff changeset
49 #define FOR_ifconfig
cb0c3a773437 Kyungwan Han submitted ifconfig.
Rob Landley <rob@landley.net>
parents:
diff changeset
50 #include "toys.h"
844
f8250900f94b More ifconfig cleanups, mostly removing unused code.
Rob Landley <rob@landley.net>
parents: 843
diff changeset
51
841
cb0c3a773437 Kyungwan Han submitted ifconfig.
Rob Landley <rob@landley.net>
parents:
diff changeset
52 #include <net/if_arp.h>
cb0c3a773437 Kyungwan Han submitted ifconfig.
Rob Landley <rob@landley.net>
parents:
diff changeset
53 #include <net/ethernet.h>
cb0c3a773437 Kyungwan Han submitted ifconfig.
Rob Landley <rob@landley.net>
parents:
diff changeset
54
866
0fa773e2a4fe Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 864
diff changeset
55 GLOBALS(
921
6a37f642b572 Yet more ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 919
diff changeset
56 int sockfd;
866
0fa773e2a4fe Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 864
diff changeset
57 )
0fa773e2a4fe Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 864
diff changeset
58
1128
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
59 // Convert hostname to binary address for AF_INET or AF_INET6
1193
f6f56a002d9a Add /prefix netmask support to ifconfig, ala "ifconfig eth0 192.168.1.42/28"
Rob Landley <rob@landley.net>
parents: 1155
diff changeset
60 // return /prefix (or range max if none)
f6f56a002d9a Add /prefix netmask support to ifconfig, ala "ifconfig eth0 192.168.1.42/28"
Rob Landley <rob@landley.net>
parents: 1155
diff changeset
61 int get_addrinfo(char *host, sa_family_t af, void *addr)
841
cb0c3a773437 Kyungwan Han submitted ifconfig.
Rob Landley <rob@landley.net>
parents:
diff changeset
62 {
1128
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
63 struct addrinfo hints, *result, *rp = 0;
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
64 int status, len;
1193
f6f56a002d9a Add /prefix netmask support to ifconfig, ala "ifconfig eth0 192.168.1.42/28"
Rob Landley <rob@landley.net>
parents: 1155
diff changeset
65 char *from, *slash;
841
cb0c3a773437 Kyungwan Han submitted ifconfig.
Rob Landley <rob@landley.net>
parents:
diff changeset
66
921
6a37f642b572 Yet more ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 919
diff changeset
67 memset(&hints, 0 , sizeof(struct addrinfo));
6a37f642b572 Yet more ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 919
diff changeset
68 hints.ai_family = af;
6a37f642b572 Yet more ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 919
diff changeset
69 hints.ai_socktype = SOCK_STREAM;
6a37f642b572 Yet more ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 919
diff changeset
70
1193
f6f56a002d9a Add /prefix netmask support to ifconfig, ala "ifconfig eth0 192.168.1.42/28"
Rob Landley <rob@landley.net>
parents: 1155
diff changeset
71 slash = strchr(host, '/');
f6f56a002d9a Add /prefix netmask support to ifconfig, ala "ifconfig eth0 192.168.1.42/28"
Rob Landley <rob@landley.net>
parents: 1155
diff changeset
72 if (slash) *slash = 0;
f6f56a002d9a Add /prefix netmask support to ifconfig, ala "ifconfig eth0 192.168.1.42/28"
Rob Landley <rob@landley.net>
parents: 1155
diff changeset
73
921
6a37f642b572 Yet more ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 919
diff changeset
74 status = getaddrinfo(host, NULL, &hints, &result);
1128
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
75 if (!status)
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
76 for (rp = result; rp; rp = rp->ai_next)
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
77 if (rp->ai_family == af) break;
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
78 if (!rp) error_exit("bad address '%s' : %s", host, gai_strerror(status));
852
6be04ec7b7ac More ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 844
diff changeset
79
1133
f8c926309a21 Cleanup help text, remove dead fields unused by linux kernel.
Rob Landley <rob@landley.net>
parents: 1132
diff changeset
80 // ai_addr isn't struct in_addr or in6_addr, it's struct sockaddr. Of course.
f8c926309a21 Cleanup help text, remove dead fields unused by linux kernel.
Rob Landley <rob@landley.net>
parents: 1132
diff changeset
81 // You'd think ipv4 and ipv6 would have some basic compatibility, but no.
f8c926309a21 Cleanup help text, remove dead fields unused by linux kernel.
Rob Landley <rob@landley.net>
parents: 1132
diff changeset
82 from = ((char *)rp->ai_addr) + 4;
1128
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
83 if (af == AF_INET6) {
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
84 len = 16;
1133
f8c926309a21 Cleanup help text, remove dead fields unused by linux kernel.
Rob Landley <rob@landley.net>
parents: 1132
diff changeset
85 from += 4; // skip "flowinfo" field ipv6 puts before address
f8c926309a21 Cleanup help text, remove dead fields unused by linux kernel.
Rob Landley <rob@landley.net>
parents: 1132
diff changeset
86 } else len = 4;
1128
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
87 memcpy(addr, from, len);
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
88 freeaddrinfo(result);
1193
f6f56a002d9a Add /prefix netmask support to ifconfig, ala "ifconfig eth0 192.168.1.42/28"
Rob Landley <rob@landley.net>
parents: 1155
diff changeset
89
f6f56a002d9a Add /prefix netmask support to ifconfig, ala "ifconfig eth0 192.168.1.42/28"
Rob Landley <rob@landley.net>
parents: 1155
diff changeset
90 len = -1;
1238
1aa9b7f39e4a In ifconfig.c, there is a glitch in function get_addrinfo() when computing the prefix length.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents: 1211
diff changeset
91 if (slash) len = atolx_range(slash+1, 0, (af == AF_INET) ? 32 : 128);
1193
f6f56a002d9a Add /prefix netmask support to ifconfig, ala "ifconfig eth0 192.168.1.42/28"
Rob Landley <rob@landley.net>
parents: 1155
diff changeset
92
f6f56a002d9a Add /prefix netmask support to ifconfig, ala "ifconfig eth0 192.168.1.42/28"
Rob Landley <rob@landley.net>
parents: 1155
diff changeset
93 return len;
841
cb0c3a773437 Kyungwan Han submitted ifconfig.
Rob Landley <rob@landley.net>
parents:
diff changeset
94 }
cb0c3a773437 Kyungwan Han submitted ifconfig.
Rob Landley <rob@landley.net>
parents:
diff changeset
95
958
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
96 static void display_ifconfig(char *name, int always, unsigned long long val[])
841
cb0c3a773437 Kyungwan Han submitted ifconfig.
Rob Landley <rob@landley.net>
parents:
diff changeset
97 {
cb0c3a773437 Kyungwan Han submitted ifconfig.
Rob Landley <rob@landley.net>
parents:
diff changeset
98 struct ifreq ifre;
879
bc7aa2d123b9 And another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 878
diff changeset
99 struct {
bc7aa2d123b9 And another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 878
diff changeset
100 int type;
bc7aa2d123b9 And another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 878
diff changeset
101 char *title;
bc7aa2d123b9 And another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 878
diff changeset
102 } types[] = {
bc7aa2d123b9 And another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 878
diff changeset
103 {ARPHRD_LOOPBACK, "Local Loopback"}, {ARPHRD_ETHER, "Ethernet"},
bc7aa2d123b9 And another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 878
diff changeset
104 {ARPHRD_PPP, "Point-to-Point Protocol"}, {ARPHRD_INFINIBAND, "InfiniBand"},
bc7aa2d123b9 And another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 878
diff changeset
105 {ARPHRD_SIT, "IPv6-in-IPv4"}, {-1, "UNSPEC"}
bc7aa2d123b9 And another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 878
diff changeset
106 };
bc7aa2d123b9 And another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 878
diff changeset
107 int i;
1127
e0a8cbb1a5e3 The return of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
108 char *pp;
921
6a37f642b572 Yet more ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 919
diff changeset
109 FILE *fp;
958
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
110 short flags;
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
111
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
112 xstrncpy(ifre.ifr_name, name, IFNAMSIZ);
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
113 if (ioctl(TT.sockfd, SIOCGIFFLAGS, &ifre)<0) perror_exit("%s", name);
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
114 flags = ifre.ifr_flags;
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
115 if (!always && !(flags & IFF_UP)) return;
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
116
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
117 // query hardware type and hardware address
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
118 i = ioctl(TT.sockfd, SIOCGIFHWADDR, &ifre);
841
cb0c3a773437 Kyungwan Han submitted ifconfig.
Rob Landley <rob@landley.net>
parents:
diff changeset
119
879
bc7aa2d123b9 And another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 878
diff changeset
120 for (i=0; i < (sizeof(types)/sizeof(*types))-1; i++)
958
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
121 if (ifre.ifr_hwaddr.sa_family == types[i].type) break;
879
bc7aa2d123b9 And another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 878
diff changeset
122
957
1ec29d7540e2 Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 921
diff changeset
123 xprintf("%-9s Link encap:%s ", name, types[i].title);
958
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
124 if(i >= 0 && ifre.ifr_hwaddr.sa_family == ARPHRD_ETHER) {
879
bc7aa2d123b9 And another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 878
diff changeset
125 xprintf("HWaddr ");
958
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
126 for (i=0; i<6; i++) xprintf(":%02X"+!i, ifre.ifr_hwaddr.sa_data[i]);
879
bc7aa2d123b9 And another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 878
diff changeset
127 }
852
6be04ec7b7ac More ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 844
diff changeset
128 xputc('\n');
866
0fa773e2a4fe Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 864
diff changeset
129
958
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
130 // If an address is assigned record that.
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
131
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
132 ifre.ifr_addr.sa_family = AF_INET;
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
133 memset(&ifre.ifr_addr, 0, sizeof(ifre.ifr_addr));
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
134 ioctl(TT.sockfd, SIOCGIFADDR, &ifre);
1127
e0a8cbb1a5e3 The return of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
135 pp = (char *)&ifre.ifr_addr;
e0a8cbb1a5e3 The return of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
136 for (i = 0; i<sizeof(ifre.ifr_addr); i++) if (pp[i]) break;
958
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
137
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
138 if (i != sizeof(ifre.ifr_addr)) {
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
139 struct sockaddr_in *si = (struct sockaddr_in *)&ifre.ifr_addr;
907
ecb0befac82a More ifconfig cleanup, inlining show_ip_addr(), hex_to_binary(), and set_hw_address().
Rob Landley <rob@landley.net>
parents: 906
diff changeset
140 struct {
ecb0befac82a More ifconfig cleanup, inlining show_ip_addr(), hex_to_binary(), and set_hw_address().
Rob Landley <rob@landley.net>
parents: 906
diff changeset
141 char *name;
958
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
142 int flag, ioctl;
907
ecb0befac82a More ifconfig cleanup, inlining show_ip_addr(), hex_to_binary(), and set_hw_address().
Rob Landley <rob@landley.net>
parents: 906
diff changeset
143 } addr[] = {
958
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
144 {"addr", 0, 0},
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
145 {"P-t-P", IFF_POINTOPOINT, SIOCGIFDSTADDR},
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
146 {"Bcast", IFF_BROADCAST, SIOCGIFBRDADDR},
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
147 {"Mask", 0, SIOCGIFNETMASK}
907
ecb0befac82a More ifconfig cleanup, inlining show_ip_addr(), hex_to_binary(), and set_hw_address().
Rob Landley <rob@landley.net>
parents: 906
diff changeset
148 };
879
bc7aa2d123b9 And another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 878
diff changeset
149
958
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
150 xprintf("%10c%s", ' ', (si->sin_family == AF_INET) ? "inet" :
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
151 (si->sin_family == AF_INET6) ? "inet6" : "unspec");
907
ecb0befac82a More ifconfig cleanup, inlining show_ip_addr(), hex_to_binary(), and set_hw_address().
Rob Landley <rob@landley.net>
parents: 906
diff changeset
152
ecb0befac82a More ifconfig cleanup, inlining show_ip_addr(), hex_to_binary(), and set_hw_address().
Rob Landley <rob@landley.net>
parents: 906
diff changeset
153 for (i=0; i < sizeof(addr)/sizeof(*addr); i++) {
958
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
154 if (!addr[i].flag || (flags & addr[i].flag)) {
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
155 if (addr[i].ioctl && ioctl(TT.sockfd, addr[i].ioctl, &ifre))
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
156 si->sin_family = 0;
907
ecb0befac82a More ifconfig cleanup, inlining show_ip_addr(), hex_to_binary(), and set_hw_address().
Rob Landley <rob@landley.net>
parents: 906
diff changeset
157 xprintf(" %s:%s ", addr[i].name,
958
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
158 (si->sin_family == 0xFFFF || !si->sin_family)
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
159 ? "[NOT SET]" : inet_ntoa(si->sin_addr));
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
160 }
907
ecb0befac82a More ifconfig cleanup, inlining show_ip_addr(), hex_to_binary(), and set_hw_address().
Rob Landley <rob@landley.net>
parents: 906
diff changeset
161 }
ecb0befac82a More ifconfig cleanup, inlining show_ip_addr(), hex_to_binary(), and set_hw_address().
Rob Landley <rob@landley.net>
parents: 906
diff changeset
162
879
bc7aa2d123b9 And another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 878
diff changeset
163 xputc('\n');
bc7aa2d123b9 And another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 878
diff changeset
164 }
bc7aa2d123b9 And another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 878
diff changeset
165
1127
e0a8cbb1a5e3 The return of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
166 fp = fopen(pp = "/proc/net/if_inet6", "r");
921
6a37f642b572 Yet more ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 919
diff changeset
167 if (fp) {
1127
e0a8cbb1a5e3 The return of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
168 char iface_name[IFNAMSIZ];
957
1ec29d7540e2 Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 921
diff changeset
169 int plen, iscope;
921
6a37f642b572 Yet more ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 919
diff changeset
170
1127
e0a8cbb1a5e3 The return of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
171 while (fgets(toybuf, sizeof(toybuf), fp)) {
e0a8cbb1a5e3 The return of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
172 int nitems;
e0a8cbb1a5e3 The return of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
173 char ipv6_addr[40];
e0a8cbb1a5e3 The return of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
174
921
6a37f642b572 Yet more ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 919
diff changeset
175 nitems = sscanf(toybuf, "%32s %*08x %02x %02x %*02x %15s\n",
1127
e0a8cbb1a5e3 The return of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
176 ipv6_addr, &plen, &iscope, iface_name);
e0a8cbb1a5e3 The return of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
177 if (nitems<0 && feof(fp)) break;
e0a8cbb1a5e3 The return of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
178 if (nitems != 4) perror_exit("bad %s", pp);
e0a8cbb1a5e3 The return of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
179
e0a8cbb1a5e3 The return of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
180 if (!strcmp(name, iface_name)) {
e0a8cbb1a5e3 The return of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
181 struct sockaddr_in6 s6;
e0a8cbb1a5e3 The return of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
182 char *ptr = ipv6_addr+sizeof(ipv6_addr)-1;
921
6a37f642b572 Yet more ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 919
diff changeset
183
1127
e0a8cbb1a5e3 The return of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
184 // convert giant hex string into colon-spearated ipv6 address by
e0a8cbb1a5e3 The return of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
185 // inserting ':' every 4 characters.
e0a8cbb1a5e3 The return of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
186 for (i = 32; i; i--)
e0a8cbb1a5e3 The return of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
187 if ((*(ptr--) = ipv6_addr[i])) if (!(i&3)) *(ptr--) = ':';
e0a8cbb1a5e3 The return of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
188
e0a8cbb1a5e3 The return of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
189 // Convert to binary and back to get abbreviated :: version
e0a8cbb1a5e3 The return of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
190 if (inet_pton(AF_INET6, ipv6_addr, (void *)&s6.sin6_addr) > 0) {
e0a8cbb1a5e3 The return of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
191 if (inet_ntop(AF_INET6, &s6.sin6_addr, toybuf, sizeof(toybuf))) {
957
1ec29d7540e2 Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 921
diff changeset
192 char *scopes[] = {"Global","Host","Link","Site","Compat"},
1ec29d7540e2 Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 921
diff changeset
193 *scope = "Unknown";
921
6a37f642b572 Yet more ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 919
diff changeset
194
1127
e0a8cbb1a5e3 The return of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
195 for (i=0; i < sizeof(scopes)/sizeof(*scopes); i++)
e0a8cbb1a5e3 The return of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
196 if (iscope == (!!i)<<(i+3)) scope = scopes[i];
e0a8cbb1a5e3 The return of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
197 xprintf("%10cinet6 addr: %s/%d Scope: %s\n",
e0a8cbb1a5e3 The return of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
198 ' ', toybuf, plen, scope);
921
6a37f642b572 Yet more ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 919
diff changeset
199 }
6a37f642b572 Yet more ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 919
diff changeset
200 }
6a37f642b572 Yet more ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 919
diff changeset
201 }
6a37f642b572 Yet more ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 919
diff changeset
202 }
6a37f642b572 Yet more ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 919
diff changeset
203 fclose(fp);
6a37f642b572 Yet more ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 919
diff changeset
204 }
6a37f642b572 Yet more ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 919
diff changeset
205
879
bc7aa2d123b9 And another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 878
diff changeset
206 xprintf("%10c", ' ');
866
0fa773e2a4fe Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 864
diff changeset
207
958
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
208 if (flags) {
866
0fa773e2a4fe Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 864
diff changeset
209 unsigned short mask = 1;
0fa773e2a4fe Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 864
diff changeset
210 char **s, *str[] = {
0fa773e2a4fe Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 864
diff changeset
211 "UP", "BROADCAST", "DEBUG", "LOOPBACK", "POINTOPOINT", "NOTRAILERS",
0fa773e2a4fe Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 864
diff changeset
212 "RUNNING", "NOARP", "PROMISC", "ALLMULTI", "MASTER", "SLAVE", "MULTICAST",
0fa773e2a4fe Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 864
diff changeset
213 "PORTSEL", "AUTOMEDIA", "DYNAMIC", NULL
0fa773e2a4fe Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 864
diff changeset
214 };
0fa773e2a4fe Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 864
diff changeset
215
1127
e0a8cbb1a5e3 The return of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
216 for (s = str; *s; s++) {
e0a8cbb1a5e3 The return of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
217 if (flags & mask) xprintf("%s ", *s);
866
0fa773e2a4fe Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 864
diff changeset
218 mask = mask << 1;
0fa773e2a4fe Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 864
diff changeset
219 }
0fa773e2a4fe Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 864
diff changeset
220 } else xprintf("[NO FLAGS] ");
0fa773e2a4fe Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 864
diff changeset
221
958
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
222 if (ioctl(TT.sockfd, SIOCGIFMTU, &ifre) < 0) ifre.ifr_mtu = 0;
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
223 xprintf(" MTU:%d", ifre.ifr_mtu);
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
224 if (ioctl(TT.sockfd, SIOCGIFMETRIC, &ifre) < 0) ifre.ifr_metric = 0;
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
225 if (!ifre.ifr_metric) ifre.ifr_metric = 1;
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
226 xprintf(" Metric:%d", ifre.ifr_metric);
866
0fa773e2a4fe Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 864
diff changeset
227
958
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
228 // non-virtual interface
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
229
1128
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
230 if (val) {
870
aa5bd0a358dd More ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 869
diff changeset
231 char *label[] = {"RX bytes", "RX packets", "errors", "dropped", "overruns",
aa5bd0a358dd More ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 869
diff changeset
232 "frame", 0, 0, "TX bytes", "TX packets", "errors", "dropped", "overruns",
aa5bd0a358dd More ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 869
diff changeset
233 "collisions", "carrier", 0, "txqueuelen"};
aa5bd0a358dd More ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 869
diff changeset
234 signed char order[] = {-1, 1, 2, 3, 4, 5, -1, 9, 10, 11, 12, 14, -1,
aa5bd0a358dd More ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 869
diff changeset
235 13, 16, -1, 0, 8};
aa5bd0a358dd More ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 869
diff changeset
236 int i;
aa5bd0a358dd More ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 869
diff changeset
237
958
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
238 // Query txqueuelen
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
239 if (ioctl(TT.sockfd, SIOCGIFTXQLEN, &ifre) >= 0) val[16] = ifre.ifr_qlen;
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
240 else val[16] = -1;
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
241
870
aa5bd0a358dd More ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 869
diff changeset
242 for (i = 0; i < sizeof(order); i++) {
aa5bd0a358dd More ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 869
diff changeset
243 int j = order[i];
841
cb0c3a773437 Kyungwan Han submitted ifconfig.
Rob Landley <rob@landley.net>
parents:
diff changeset
244
870
aa5bd0a358dd More ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 869
diff changeset
245 if (j < 0) xprintf("\n%10c", ' ');
958
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
246 else xprintf("%s:%llu ", label[j], val[j]);
870
aa5bd0a358dd More ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 869
diff changeset
247 }
842
af5aab6e6678 An ifconfig bugfix from the original submitter.
Rob Landley <rob@landley.net>
parents: 841
diff changeset
248 }
870
aa5bd0a358dd More ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 869
diff changeset
249 xputc('\n');
aa5bd0a358dd More ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 869
diff changeset
250
958
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
251 if(!ioctl(TT.sockfd, SIOCGIFMAP, &ifre) && (ifre.ifr_map.irq ||
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
252 ifre.ifr_map.mem_start || ifre.ifr_map.dma || ifre.ifr_map.base_addr))
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
253 {
866
0fa773e2a4fe Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 864
diff changeset
254 xprintf("%10c", ' ');
958
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
255 if(ifre.ifr_map.irq) xprintf("Interrupt:%d ", ifre.ifr_map.irq);
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
256 if(ifre.ifr_map.base_addr >= 0x100) // IO_MAP_INDEX
1714
0c8ef714cf03 Patches from Elliott Hughes to fix various printf() format strings.
Rob Landley <rob@landley.net>
parents: 1684
diff changeset
257 xprintf("Base address:0x%x ", ifre.ifr_map.base_addr);
958
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
258 if(ifre.ifr_map.mem_start)
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
259 xprintf("Memory:%lx-%lx ", ifre.ifr_map.mem_start, ifre.ifr_map.mem_end);
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
260 if(ifre.ifr_map.dma) xprintf("DMA chan:%x ", ifre.ifr_map.dma);
852
6be04ec7b7ac More ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 844
diff changeset
261 xputc('\n');
841
cb0c3a773437 Kyungwan Han submitted ifconfig.
Rob Landley <rob@landley.net>
parents:
diff changeset
262 }
852
6be04ec7b7ac More ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 844
diff changeset
263 xputc('\n');
841
cb0c3a773437 Kyungwan Han submitted ifconfig.
Rob Landley <rob@landley.net>
parents:
diff changeset
264 }
cb0c3a773437 Kyungwan Han submitted ifconfig.
Rob Landley <rob@landley.net>
parents:
diff changeset
265
870
aa5bd0a358dd More ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 869
diff changeset
266 static void show_iface(char *iface_name)
841
cb0c3a773437 Kyungwan Han submitted ifconfig.
Rob Landley <rob@landley.net>
parents:
diff changeset
267 {
957
1ec29d7540e2 Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 921
diff changeset
268 char *name;
1ec29d7540e2 Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 921
diff changeset
269 struct string_list *ifaces = 0, *sl;
870
aa5bd0a358dd More ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 869
diff changeset
270 int i, j;
aa5bd0a358dd More ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 869
diff changeset
271 FILE *fp;
aa5bd0a358dd More ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 869
diff changeset
272
aa5bd0a358dd More ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 869
diff changeset
273 fp = xfopen("/proc/net/dev", "r");
aa5bd0a358dd More ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 869
diff changeset
274
aa5bd0a358dd More ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 869
diff changeset
275 for (i=0; fgets(toybuf, sizeof(toybuf), fp); i++) {
957
1ec29d7540e2 Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 921
diff changeset
276 char *buf = toybuf;
958
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
277 unsigned long long val[17];
870
aa5bd0a358dd More ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 869
diff changeset
278
aa5bd0a358dd More ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 869
diff changeset
279 if (i<2) continue;
866
0fa773e2a4fe Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 864
diff changeset
280
957
1ec29d7540e2 Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 921
diff changeset
281 while (isspace(*buf)) buf++;
870
aa5bd0a358dd More ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 869
diff changeset
282 name = strsep(&buf, ":");
aa5bd0a358dd More ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 869
diff changeset
283 if(!buf) error_exit("bad name %s", name);
aa5bd0a358dd More ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 869
diff changeset
284
aa5bd0a358dd More ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 869
diff changeset
285 errno = 0;
958
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
286 for (j=0; j<16 && !errno; j++) val[j] = strtoll(buf, &buf, 0);
870
aa5bd0a358dd More ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 869
diff changeset
287 if (errno) perror_exit("bad %s at %s", name, buf);
aa5bd0a358dd More ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 869
diff changeset
288
957
1ec29d7540e2 Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 921
diff changeset
289 if (iface_name) {
1ec29d7540e2 Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 921
diff changeset
290 if (!strcmp(iface_name, name)) {
1127
e0a8cbb1a5e3 The return of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
291 display_ifconfig(iface_name, 1, val);
957
1ec29d7540e2 Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 921
diff changeset
292
1ec29d7540e2 Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 921
diff changeset
293 return;
1ec29d7540e2 Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 921
diff changeset
294 }
1ec29d7540e2 Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 921
diff changeset
295 } else {
1ec29d7540e2 Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 921
diff changeset
296 sl = xmalloc(sizeof(*sl)+strlen(name)+1);
1ec29d7540e2 Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 921
diff changeset
297 strcpy(sl->str, name);
1ec29d7540e2 Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 921
diff changeset
298 sl->next = ifaces;
1ec29d7540e2 Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 921
diff changeset
299 ifaces = sl;
1ec29d7540e2 Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 921
diff changeset
300
1128
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
301 display_ifconfig(sl->str, toys.optflags & FLAG_a, val);
957
1ec29d7540e2 Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 921
diff changeset
302 }
870
aa5bd0a358dd More ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 869
diff changeset
303 }
aa5bd0a358dd More ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 869
diff changeset
304 fclose(fp);
842
af5aab6e6678 An ifconfig bugfix from the original submitter.
Rob Landley <rob@landley.net>
parents: 841
diff changeset
305
958
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
306 if (iface_name) display_ifconfig(iface_name, 1, 0);
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
307 else {
957
1ec29d7540e2 Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 921
diff changeset
308 struct ifconf ifcon;
1ec29d7540e2 Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 921
diff changeset
309 struct ifreq *ifre;
1ec29d7540e2 Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 921
diff changeset
310 int num;
1ec29d7540e2 Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 921
diff changeset
311
1ec29d7540e2 Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 921
diff changeset
312 // Loop until buffer's big enough
1ec29d7540e2 Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 921
diff changeset
313 ifcon.ifc_buf = NULL;
1ec29d7540e2 Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 921
diff changeset
314 for (num = 30;;num += 10) {
1ec29d7540e2 Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 921
diff changeset
315 ifcon.ifc_len = sizeof(struct ifreq)*num;
1ec29d7540e2 Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 921
diff changeset
316 ifcon.ifc_buf = xrealloc(ifcon.ifc_buf, ifcon.ifc_len);
1ec29d7540e2 Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 921
diff changeset
317 xioctl(TT.sockfd, SIOCGIFCONF, &ifcon);
1ec29d7540e2 Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 921
diff changeset
318 if (ifcon.ifc_len != sizeof(struct ifreq)*num) break;
1ec29d7540e2 Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 921
diff changeset
319 }
1ec29d7540e2 Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 921
diff changeset
320
1ec29d7540e2 Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 921
diff changeset
321 ifre = ifcon.ifc_req;
1ec29d7540e2 Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 921
diff changeset
322 for(num = 0; num < ifcon.ifc_len && ifre; num += sizeof(struct ifreq), ifre++)
1ec29d7540e2 Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 921
diff changeset
323 {
1ec29d7540e2 Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 921
diff changeset
324 // Skip duplicates
1ec29d7540e2 Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 921
diff changeset
325 for(sl = ifaces; sl; sl = sl->next)
1ec29d7540e2 Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 921
diff changeset
326 if(!strcmp(sl->str, ifre->ifr_name)) break;
1ec29d7540e2 Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 921
diff changeset
327
958
019f54d50c8b More ifconfig cleanup: Remove if_list, unify get_device_info and display_ifconfig(), inline another magic constant #define that's only used once.
Rob Landley <rob@landley.net>
parents: 957
diff changeset
328 if(!sl) display_ifconfig(ifre->ifr_name, toys.optflags & FLAG_a, 0);
841
cb0c3a773437 Kyungwan Han submitted ifconfig.
Rob Landley <rob@landley.net>
parents:
diff changeset
329 }
957
1ec29d7540e2 Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 921
diff changeset
330
1ec29d7540e2 Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 921
diff changeset
331 free(ifcon.ifc_buf);
841
cb0c3a773437 Kyungwan Han submitted ifconfig.
Rob Landley <rob@landley.net>
parents:
diff changeset
332 }
878
d4263ebf6f9b Yet more drive-by cleanup of ifconfig.
Rob Landley <rob@landley.net>
parents: 870
diff changeset
333
957
1ec29d7540e2 Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 921
diff changeset
334 llist_traverse(ifaces, free);
841
cb0c3a773437 Kyungwan Han submitted ifconfig.
Rob Landley <rob@landley.net>
parents:
diff changeset
335 }
869
571e95bdf6af ifconfig cleanup (Reorder functions to eliminate need for prototypes, put main at end).
Rob Landley <rob@landley.net>
parents: 866
diff changeset
336
919
a186f9a1406d More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents: 907
diff changeset
337 // Encode offset and size of field into an int, and make result negative
a186f9a1406d More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents: 907
diff changeset
338 #define IFREQ_OFFSZ(x) -(int)((offsetof(struct ifreq, x)<<16) + sizeof(ifre.x))
a186f9a1406d More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents: 907
diff changeset
339
869
571e95bdf6af ifconfig cleanup (Reorder functions to eliminate need for prototypes, put main at end).
Rob Landley <rob@landley.net>
parents: 866
diff changeset
340 void ifconfig_main(void)
571e95bdf6af ifconfig cleanup (Reorder functions to eliminate need for prototypes, put main at end).
Rob Landley <rob@landley.net>
parents: 866
diff changeset
341 {
571e95bdf6af ifconfig cleanup (Reorder functions to eliminate need for prototypes, put main at end).
Rob Landley <rob@landley.net>
parents: 866
diff changeset
342 char **argv = toys.optargs;
898
f6db08574875 Ifconfig cleanup to option parsing.
Rob Landley <rob@landley.net>
parents: 883
diff changeset
343 struct ifreq ifre;
921
6a37f642b572 Yet more ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 919
diff changeset
344 int i;
869
571e95bdf6af ifconfig cleanup (Reorder functions to eliminate need for prototypes, put main at end).
Rob Landley <rob@landley.net>
parents: 866
diff changeset
345
921
6a37f642b572 Yet more ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 919
diff changeset
346 TT.sockfd = xsocket(AF_INET, SOCK_DGRAM, 0);
878
d4263ebf6f9b Yet more drive-by cleanup of ifconfig.
Rob Landley <rob@landley.net>
parents: 870
diff changeset
347 if(toys.optc < 2) {
870
aa5bd0a358dd More ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 869
diff changeset
348 show_iface(*argv);
869
571e95bdf6af ifconfig cleanup (Reorder functions to eliminate need for prototypes, put main at end).
Rob Landley <rob@landley.net>
parents: 866
diff changeset
349 return;
571e95bdf6af ifconfig cleanup (Reorder functions to eliminate need for prototypes, put main at end).
Rob Landley <rob@landley.net>
parents: 866
diff changeset
350 }
571e95bdf6af ifconfig cleanup (Reorder functions to eliminate need for prototypes, put main at end).
Rob Landley <rob@landley.net>
parents: 866
diff changeset
351
919
a186f9a1406d More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents: 907
diff changeset
352 // Open interface
898
f6db08574875 Ifconfig cleanup to option parsing.
Rob Landley <rob@landley.net>
parents: 883
diff changeset
353 memset(&ifre, 0, sizeof(struct ifreq));
f6db08574875 Ifconfig cleanup to option parsing.
Rob Landley <rob@landley.net>
parents: 883
diff changeset
354 xstrncpy(ifre.ifr_name, *argv, IFNAMSIZ);
869
571e95bdf6af ifconfig cleanup (Reorder functions to eliminate need for prototypes, put main at end).
Rob Landley <rob@landley.net>
parents: 866
diff changeset
355
919
a186f9a1406d More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents: 907
diff changeset
356 // Perform operations on interface
898
f6db08574875 Ifconfig cleanup to option parsing.
Rob Landley <rob@landley.net>
parents: 883
diff changeset
357 while(*++argv) {
1128
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
358 // Table of known operations
905
e875b03e1fcc Yet more ifconfig cleanup. (As described on the mailing list [CLEANUP] thread.)
Rob Landley <rob@landley.net>
parents: 898
diff changeset
359 struct argh {
898
f6db08574875 Ifconfig cleanup to option parsing.
Rob Landley <rob@landley.net>
parents: 883
diff changeset
360 char *name;
906
ce0a9368b82f Next round of ifconfig cleanup, to be described on mailing list.
Rob Landley <rob@landley.net>
parents: 905
diff changeset
361 int on, off; // set, clear
898
f6db08574875 Ifconfig cleanup to option parsing.
Rob Landley <rob@landley.net>
parents: 883
diff changeset
362 } try[] = {
1128
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
363 {0, IFF_UP|IFF_RUNNING, SIOCSIFADDR},
906
ce0a9368b82f Next round of ifconfig cleanup, to be described on mailing list.
Rob Landley <rob@landley.net>
parents: 905
diff changeset
364 {"up", IFF_UP|IFF_RUNNING, 0},
ce0a9368b82f Next round of ifconfig cleanup, to be described on mailing list.
Rob Landley <rob@landley.net>
parents: 905
diff changeset
365 {"down", 0, IFF_UP},
ce0a9368b82f Next round of ifconfig cleanup, to be described on mailing list.
Rob Landley <rob@landley.net>
parents: 905
diff changeset
366 {"arp", 0, IFF_NOARP},
ce0a9368b82f Next round of ifconfig cleanup, to be described on mailing list.
Rob Landley <rob@landley.net>
parents: 905
diff changeset
367 {"promisc", IFF_PROMISC, 0},
ce0a9368b82f Next round of ifconfig cleanup, to be described on mailing list.
Rob Landley <rob@landley.net>
parents: 905
diff changeset
368 {"allmulti", IFF_ALLMULTI, 0},
ce0a9368b82f Next round of ifconfig cleanup, to be described on mailing list.
Rob Landley <rob@landley.net>
parents: 905
diff changeset
369 {"multicast", IFF_MULTICAST, 0},
ce0a9368b82f Next round of ifconfig cleanup, to be described on mailing list.
Rob Landley <rob@landley.net>
parents: 905
diff changeset
370 {"pointopoint", IFF_POINTOPOINT, SIOCSIFDSTADDR},
ce0a9368b82f Next round of ifconfig cleanup, to be described on mailing list.
Rob Landley <rob@landley.net>
parents: 905
diff changeset
371 {"broadcast", IFF_BROADCAST, SIOCSIFBRDADDR},
ce0a9368b82f Next round of ifconfig cleanup, to be described on mailing list.
Rob Landley <rob@landley.net>
parents: 905
diff changeset
372 {"netmask", 0, SIOCSIFNETMASK},
919
a186f9a1406d More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents: 907
diff changeset
373 {"dstaddr", 0, SIOCSIFDSTADDR},
a186f9a1406d More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents: 907
diff changeset
374 {"mtu", IFREQ_OFFSZ(ifr_mtu), SIOCSIFMTU},
921
6a37f642b572 Yet more ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 919
diff changeset
375 {"keepalive", IFREQ_OFFSZ(ifr_data), SIOCDEVPRIVATE}, // SIOCSKEEPALIVE
6a37f642b572 Yet more ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 919
diff changeset
376 {"outfill", IFREQ_OFFSZ(ifr_data), SIOCDEVPRIVATE+2}, // SIOCSOUTFILL
919
a186f9a1406d More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents: 907
diff changeset
377 {"metric", IFREQ_OFFSZ(ifr_metric), SIOCSIFMETRIC},
a186f9a1406d More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents: 907
diff changeset
378 {"txqueuelen", IFREQ_OFFSZ(ifr_qlen), SIOCSIFTXQLEN},
a186f9a1406d More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents: 907
diff changeset
379 {"mem_start", IFREQ_OFFSZ(ifr_map.mem_start), SIOCSIFMAP},
a186f9a1406d More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents: 907
diff changeset
380 {"io_addr", IFREQ_OFFSZ(ifr_map.base_addr), SIOCSIFMAP},
a186f9a1406d More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents: 907
diff changeset
381 {"irq", IFREQ_OFFSZ(ifr_map.irq), SIOCSIFMAP},
a186f9a1406d More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents: 907
diff changeset
382 {"inet", 0, 0},
a186f9a1406d More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents: 907
diff changeset
383 {"inet6", 0, 0}
898
f6db08574875 Ifconfig cleanup to option parsing.
Rob Landley <rob@landley.net>
parents: 883
diff changeset
384 };
f6db08574875 Ifconfig cleanup to option parsing.
Rob Landley <rob@landley.net>
parents: 883
diff changeset
385 char *s = *argv;
f6db08574875 Ifconfig cleanup to option parsing.
Rob Landley <rob@landley.net>
parents: 883
diff changeset
386 int rev = (*s == '-');
869
571e95bdf6af ifconfig cleanup (Reorder functions to eliminate need for prototypes, put main at end).
Rob Landley <rob@landley.net>
parents: 866
diff changeset
387
898
f6db08574875 Ifconfig cleanup to option parsing.
Rob Landley <rob@landley.net>
parents: 883
diff changeset
388 s += rev;
f6db08574875 Ifconfig cleanup to option parsing.
Rob Landley <rob@landley.net>
parents: 883
diff changeset
389
1128
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
390 // "set hardware address" is oddball enough to special case
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
391 if (!strcmp(*argv, "hw")) {
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
392 char *hw_addr, *ptr, *p;
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
393 struct sockaddr *sock = &ifre.ifr_hwaddr;
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
394 int count = 6;
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
395
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
396 ptr = p = (char *)sock->sa_data;
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
397 memset(sock, 0, sizeof(struct sockaddr));
1211
40e0f7b09b77 Fix two bugs reported by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents: 1202
diff changeset
398 if (argv[1]) {
1128
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
399 if (!strcmp("ether", *++argv)) sock->sa_family = ARPHRD_ETHER;
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
400 else if (!strcmp("infiniband", *argv)) {
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
401 sock->sa_family = ARPHRD_INFINIBAND;
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
402 count = 20;
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
403 p = ptr = toybuf;
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
404 }
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
405 }
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
406 if (!sock->sa_family || !argv[1]) {
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
407 toys.exithelp++;
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
408 error_exit("bad hw '%s'", *argv);
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
409 }
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
410 hw_addr = *++argv;
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
411
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
412 // Parse and verify address.
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
413 while (*hw_addr && (p-ptr) < count) {
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
414 int val, len = 0;
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
415
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
416 if (*hw_addr == ':') hw_addr++;
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
417 sscanf(hw_addr, "%2x%n", &val, &len);
1257
eb19245b94b6 An issue in ifconfig while verifying the HW Address, which is assumed to be of the format __C2:79:38:95:CD:AB__ but can be of form __C2:79:38:95:D:A__. In this case the HW address is reported as bad.
Ashwini sharma <ak.ashwini1981@gmail.com>
parents: 1238
diff changeset
418 if (!len || len > 2) break; // 1 nibble can be set e.g. C2:79:38:95:D:A
1128
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
419 hw_addr += len;
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
420 *p++ = val;
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
421 }
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
422
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
423 if ((p-ptr) != count || *hw_addr)
1433
00c20f410c46 Patches to commands for issues reported from static analysis tool.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents: 1257
diff changeset
424 error_exit("bad hw-addr '%s'", *argv);
1128
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
425
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
426 // the linux kernel's "struct sockaddr" (include/linux/socket.h in the
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
427 // kernel source) only has 14 bytes of sa_data, and an infiniband address
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
428 // is 20. So if we go through the ioctl, the kernel will truncate
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
429 // infiniband addresses, meaning we have to go through sysfs instead.
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
430 if (sock->sa_family == ARPHRD_INFINIBAND && !strchr(ifre.ifr_name, '/')) {
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
431 int fd;
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
432
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
433 sprintf(toybuf, "/sys/class/net/%s/address", ifre.ifr_name);
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
434 fd = xopen(toybuf, O_RDWR);
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
435 xwrite(fd, *argv, strlen(*argv));
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
436 close(fd);
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
437 } else xioctl(TT.sockfd, SIOCSIFHWADDR, &ifre);
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
438 continue;
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
439
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
440 // Add/remove ipv6 address to interface
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
441
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
442 } else if (!strcmp(*argv, "add") || !strcmp(*argv, "del")) {
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
443 struct ifreq_inet6 {
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
444 struct in6_addr addr;
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
445 unsigned prefix;
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
446 int index;
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
447 } ifre6;
1193
f6f56a002d9a Add /prefix netmask support to ifconfig, ala "ifconfig eth0 192.168.1.42/28"
Rob Landley <rob@landley.net>
parents: 1155
diff changeset
448 int plen, fd6 = xsocket(AF_INET6, SOCK_DGRAM, 0);
1128
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
449
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
450 if (!argv[1]) {
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
451 toys.exithelp++;
1714
0c8ef714cf03 Patches from Elliott Hughes to fix various printf() format strings.
Rob Landley <rob@landley.net>
parents: 1684
diff changeset
452 error_exit("%s", *argv);
1128
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
453 }
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
454
1193
f6f56a002d9a Add /prefix netmask support to ifconfig, ala "ifconfig eth0 192.168.1.42/28"
Rob Landley <rob@landley.net>
parents: 1155
diff changeset
455 plen = get_addrinfo(argv[1], AF_INET6, &ifre6.addr);
f6f56a002d9a Add /prefix netmask support to ifconfig, ala "ifconfig eth0 192.168.1.42/28"
Rob Landley <rob@landley.net>
parents: 1155
diff changeset
456 if (plen < 0) plen = 128;
1128
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
457 xioctl(fd6, SIOCGIFINDEX, &ifre);
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
458 ifre6.index = ifre.ifr_ifindex;
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
459 ifre6.prefix = plen;
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
460 xioctl(fd6, **(argv++)=='a' ? SIOCSIFADDR : SIOCDIFADDR, &ifre6);
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
461
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
462 close(fd6);
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
463 continue;
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
464 // Iterate through table to find/perform operation
1684
8d52be1c6cf3 For some reason, ifconfig was explicitly excluding "ifconfig lo:0 127.0.0.2" style alias address assignments. No idea why.
Rob Landley <rob@landley.net>
parents: 1518
diff changeset
465 } else for (i = 0; i < ARRAY_LEN(try); i++) {
905
e875b03e1fcc Yet more ifconfig cleanup. (As described on the mailing list [CLEANUP] thread.)
Rob Landley <rob@landley.net>
parents: 898
diff changeset
466 struct argh *t = try+i;
906
ce0a9368b82f Next round of ifconfig cleanup, to be described on mailing list.
Rob Landley <rob@landley.net>
parents: 905
diff changeset
467 int on = t->on, off = t->off;
905
e875b03e1fcc Yet more ifconfig cleanup. (As described on the mailing list [CLEANUP] thread.)
Rob Landley <rob@landley.net>
parents: 898
diff changeset
468
1128
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
469 if (!t->name) {
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
470 if (isdigit(**argv) || !strcmp(*argv, "default")) argv--;
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
471 else continue;
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
472 } else if (strcmp(t->name, s)) continue;
898
f6db08574875 Ifconfig cleanup to option parsing.
Rob Landley <rob@landley.net>
parents: 883
diff changeset
473
906
ce0a9368b82f Next round of ifconfig cleanup, to be described on mailing list.
Rob Landley <rob@landley.net>
parents: 905
diff changeset
474 // Is this an SIOCSI entry?
919
a186f9a1406d More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents: 907
diff changeset
475 if ((off|0xff) == 0x89ff) {
906
ce0a9368b82f Next round of ifconfig cleanup, to be described on mailing list.
Rob Landley <rob@landley.net>
parents: 905
diff changeset
476 if (!rev) {
1155
63f8c7fa94d7 Ashwini sharma pointed out that show_help() doesn't exit so "ifconfig eth0 netmask" would segfault. Replace it with an error_exit(), see list for aesthetic issue this raises re: help text.
Rob Landley <rob@landley.net>
parents: 1133
diff changeset
477 if (!*++argv) error_exit("%s needs argument", t->name);
919
a186f9a1406d More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents: 907
diff changeset
478
a186f9a1406d More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents: 907
diff changeset
479 // Assign value to ifre field and call ioctl? (via IFREQ_OFFSZ.)
a186f9a1406d More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents: 907
diff changeset
480 if (on < 0) {
a186f9a1406d More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents: 907
diff changeset
481 long l = strtoul(*argv, 0, 0);
a186f9a1406d More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents: 907
diff changeset
482
921
6a37f642b572 Yet more ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 919
diff changeset
483 if (off == SIOCSIFMAP) xioctl(TT.sockfd, SIOCGIFMAP, &ifre);
919
a186f9a1406d More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents: 907
diff changeset
484 on = -on;
a186f9a1406d More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents: 907
diff changeset
485 poke((on>>16) + (char *)&ifre, l, on&15);
921
6a37f642b572 Yet more ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 919
diff changeset
486 xioctl(TT.sockfd, off, &ifre);
919
a186f9a1406d More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents: 907
diff changeset
487 break;
1684
8d52be1c6cf3 For some reason, ifconfig was explicitly excluding "ifconfig lo:0 127.0.0.2" style alias address assignments. No idea why.
Rob Landley <rob@landley.net>
parents: 1518
diff changeset
488 } else {
1128
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
489 struct sockaddr_in *si = (struct sockaddr_in *)&ifre.ifr_addr;
1193
f6f56a002d9a Add /prefix netmask support to ifconfig, ala "ifconfig eth0 192.168.1.42/28"
Rob Landley <rob@landley.net>
parents: 1155
diff changeset
490 int mask = -1;
1128
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
491
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
492 si->sin_family = AF_INET;
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
493
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
494 if (!strcmp(*argv, "default")) si->sin_addr.s_addr = INADDR_ANY;
1193
f6f56a002d9a Add /prefix netmask support to ifconfig, ala "ifconfig eth0 192.168.1.42/28"
Rob Landley <rob@landley.net>
parents: 1155
diff changeset
495 else mask = get_addrinfo(*argv, AF_INET, &si->sin_addr);
1128
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
496 xioctl(TT.sockfd, off, &ifre);
1193
f6f56a002d9a Add /prefix netmask support to ifconfig, ala "ifconfig eth0 192.168.1.42/28"
Rob Landley <rob@landley.net>
parents: 1155
diff changeset
497
f6f56a002d9a Add /prefix netmask support to ifconfig, ala "ifconfig eth0 192.168.1.42/28"
Rob Landley <rob@landley.net>
parents: 1155
diff changeset
498 // Handle /netmask
f6f56a002d9a Add /prefix netmask support to ifconfig, ala "ifconfig eth0 192.168.1.42/28"
Rob Landley <rob@landley.net>
parents: 1155
diff changeset
499 if (mask >= 0) {
f6f56a002d9a Add /prefix netmask support to ifconfig, ala "ifconfig eth0 192.168.1.42/28"
Rob Landley <rob@landley.net>
parents: 1155
diff changeset
500 // sin_addr probably isn't unaligned, but just in case...
f6f56a002d9a Add /prefix netmask support to ifconfig, ala "ifconfig eth0 192.168.1.42/28"
Rob Landley <rob@landley.net>
parents: 1155
diff changeset
501 mask = htonl((~0)<<(32-mask));
f6f56a002d9a Add /prefix netmask support to ifconfig, ala "ifconfig eth0 192.168.1.42/28"
Rob Landley <rob@landley.net>
parents: 1155
diff changeset
502 memcpy(&si->sin_addr, &mask, 4);
f6f56a002d9a Add /prefix netmask support to ifconfig, ala "ifconfig eth0 192.168.1.42/28"
Rob Landley <rob@landley.net>
parents: 1155
diff changeset
503 xioctl(TT.sockfd, SIOCSIFNETMASK, &ifre);
f6f56a002d9a Add /prefix netmask support to ifconfig, ala "ifconfig eth0 192.168.1.42/28"
Rob Landley <rob@landley.net>
parents: 1155
diff changeset
504 }
1128
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
505 }
906
ce0a9368b82f Next round of ifconfig cleanup, to be described on mailing list.
Rob Landley <rob@landley.net>
parents: 905
diff changeset
506 }
ce0a9368b82f Next round of ifconfig cleanup, to be described on mailing list.
Rob Landley <rob@landley.net>
parents: 905
diff changeset
507 off = 0;
905
e875b03e1fcc Yet more ifconfig cleanup. (As described on the mailing list [CLEANUP] thread.)
Rob Landley <rob@landley.net>
parents: 898
diff changeset
508 }
919
a186f9a1406d More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents: 907
diff changeset
509
a186f9a1406d More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents: 907
diff changeset
510 // Set flags
906
ce0a9368b82f Next round of ifconfig cleanup, to be described on mailing list.
Rob Landley <rob@landley.net>
parents: 905
diff changeset
511 if (on || off) {
921
6a37f642b572 Yet more ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 919
diff changeset
512 xioctl(TT.sockfd, SIOCGIFFLAGS, &ifre);
906
ce0a9368b82f Next round of ifconfig cleanup, to be described on mailing list.
Rob Landley <rob@landley.net>
parents: 905
diff changeset
513 ifre.ifr_flags &= ~(rev ? on : off);
ce0a9368b82f Next round of ifconfig cleanup, to be described on mailing list.
Rob Landley <rob@landley.net>
parents: 905
diff changeset
514 ifre.ifr_flags |= (rev ? off : on);
921
6a37f642b572 Yet more ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 919
diff changeset
515 xioctl(TT.sockfd, SIOCSIFFLAGS, &ifre);
905
e875b03e1fcc Yet more ifconfig cleanup. (As described on the mailing list [CLEANUP] thread.)
Rob Landley <rob@landley.net>
parents: 898
diff changeset
516 }
898
f6db08574875 Ifconfig cleanup to option parsing.
Rob Landley <rob@landley.net>
parents: 883
diff changeset
517
f6db08574875 Ifconfig cleanup to option parsing.
Rob Landley <rob@landley.net>
parents: 883
diff changeset
518 break;
f6db08574875 Ifconfig cleanup to option parsing.
Rob Landley <rob@landley.net>
parents: 883
diff changeset
519 }
1128
9eaec92e3713 Ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 1127
diff changeset
520 if (i == sizeof(try)/sizeof(*try)) {
919
a186f9a1406d More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents: 907
diff changeset
521 toys.exithelp++;
a186f9a1406d More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents: 907
diff changeset
522 error_exit("bad argument '%s'", *argv);
869
571e95bdf6af ifconfig cleanup (Reorder functions to eliminate need for prototypes, put main at end).
Rob Landley <rob@landley.net>
parents: 866
diff changeset
523 }
919
a186f9a1406d More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents: 907
diff changeset
524 }
921
6a37f642b572 Yet more ifconfig cleanup.
Rob Landley <rob@landley.net>
parents: 919
diff changeset
525 close(TT.sockfd);
869
571e95bdf6af ifconfig cleanup (Reorder functions to eliminate need for prototypes, put main at end).
Rob Landley <rob@landley.net>
parents: 866
diff changeset
526 }