Mercurial > hg > toybox
annotate toys/pending/ifconfig.c @ 921:6a37f642b572
Yet more ifconfig cleanup.
author | Rob Landley <rob@landley.net> |
---|---|
date | Sat, 08 Jun 2013 14:11:41 -0500 |
parents | a186f9a1406d |
children | 1ec29d7540e2 |
rev | line source |
---|---|
841 | 1 /* ifconfig.c - Configure network interface. |
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 | 6 * |
7 * Not in SUSv4. | |
844
f8250900f94b
More ifconfig cleanups, mostly removing unused code.
Rob Landley <rob@landley.net>
parents:
843
diff
changeset
|
8 |
841 | 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 | 11 config IFCONFIG |
12 bool "ifconfig" | |
921 | 13 default y |
841 | 14 help |
15 usage: ifconfig [-a] interface [address] | |
16 | |
17 Configure network interface. | |
18 | |
19 [add ADDRESS[/PREFIXLEN]] | |
20 [del ADDRESS[/PREFIXLEN]] | |
21 [[-]broadcast [ADDRESS]] [[-]pointopoint [ADDRESS]] | |
22 [netmask ADDRESS] [dstaddr ADDRESS] | |
23 [outfill NN] [keepalive NN] | |
24 [hw ether|infiniband ADDRESS] [metric NN] [mtu NN] | |
25 [[-]trailers] [[-]arp] [[-]allmulti] | |
26 [multicast] [[-]promisc] [txqueuelen NN] [[-]dynamic] | |
27 [mem_start NN] [io_addr NN] [irq NN] | |
28 [up|down] ... | |
29 */ | |
30 | |
31 #define FOR_ifconfig | |
32 #include "toys.h" | |
33 #include "toynet.h" | |
844
f8250900f94b
More ifconfig cleanups, mostly removing unused code.
Rob Landley <rob@landley.net>
parents:
843
diff
changeset
|
34 |
841 | 35 #include <net/if_arp.h> |
36 #include <net/ethernet.h> | |
37 | |
866
0fa773e2a4fe
Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents:
864
diff
changeset
|
38 GLOBALS( |
870 | 39 void *if_list; |
921 | 40 |
41 int sockfd; | |
866
0fa773e2a4fe
Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents:
864
diff
changeset
|
42 ) |
0fa773e2a4fe
Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents:
864
diff
changeset
|
43 |
841 | 44 typedef struct sockaddr_with_len { |
45 union { | |
46 struct sockaddr sock; | |
47 struct sockaddr_in sock_in; | |
48 struct sockaddr_in6 sock_in6; | |
49 }sock_u; | |
50 socklen_t socklen; | |
844
f8250900f94b
More ifconfig cleanups, mostly removing unused code.
Rob Landley <rob@landley.net>
parents:
843
diff
changeset
|
51 } sockaddr_with_len; |
841 | 52 |
866
0fa773e2a4fe
Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents:
864
diff
changeset
|
53 // man netdevice |
870 | 54 struct if_list { |
55 struct if_list *next; | |
56 int hw_type, mtu, metric, txqueuelen, non_virtual_iface; | |
919
a186f9a1406d
More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents:
907
diff
changeset
|
57 short flags; |
870 | 58 struct sockaddr addr, dstaddr, broadaddr, netmask, hwaddr; |
59 struct ifmap map; | |
866
0fa773e2a4fe
Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents:
864
diff
changeset
|
60 |
870 | 61 char name[IFNAMSIZ]; |
62 unsigned long long val[16]; | |
866
0fa773e2a4fe
Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents:
864
diff
changeset
|
63 }; |
841 | 64 |
65 #define IO_MAP_INDEX 0x100 | |
66 | |
67 //for the param settings. | |
68 | |
69 //for ipv6 add/del | |
70 struct ifreq_inet6 { | |
71 struct in6_addr ifrinte6_addr; | |
72 uint32_t ifrinet6_prefixlen; | |
73 int ifrinet6_ifindex; | |
74 }; | |
75 | |
76 /* | |
77 * use to get the socket address with the given host ip. | |
78 */ | |
852 | 79 sockaddr_with_len *get_sockaddr(char *host, int port, sa_family_t af) |
841 | 80 { |
81 sockaddr_with_len *swl = NULL; | |
852 | 82 in_port_t port_num = htons(port); |
921 | 83 struct addrinfo hints, *result, *rp; |
84 int status; | |
905
e875b03e1fcc
Yet more ifconfig cleanup. (As described on the mailing list [CLEANUP] thread.)
Rob Landley <rob@landley.net>
parents:
898
diff
changeset
|
85 char *s; |
841 | 86 |
905
e875b03e1fcc
Yet more ifconfig cleanup. (As described on the mailing list [CLEANUP] thread.)
Rob Landley <rob@landley.net>
parents:
898
diff
changeset
|
87 if (!strncmp(host, "local:", 6)) { |
e875b03e1fcc
Yet more ifconfig cleanup. (As described on the mailing list [CLEANUP] thread.)
Rob Landley <rob@landley.net>
parents:
898
diff
changeset
|
88 struct sockaddr_un *sockun; |
e875b03e1fcc
Yet more ifconfig cleanup. (As described on the mailing list [CLEANUP] thread.)
Rob Landley <rob@landley.net>
parents:
898
diff
changeset
|
89 |
e875b03e1fcc
Yet more ifconfig cleanup. (As described on the mailing list [CLEANUP] thread.)
Rob Landley <rob@landley.net>
parents:
898
diff
changeset
|
90 swl = xzalloc(sizeof(struct sockaddr_with_len)); |
e875b03e1fcc
Yet more ifconfig cleanup. (As described on the mailing list [CLEANUP] thread.)
Rob Landley <rob@landley.net>
parents:
898
diff
changeset
|
91 swl->socklen = sizeof(struct sockaddr_un); |
e875b03e1fcc
Yet more ifconfig cleanup. (As described on the mailing list [CLEANUP] thread.)
Rob Landley <rob@landley.net>
parents:
898
diff
changeset
|
92 swl->sock_u.sock.sa_family = AF_UNIX; |
e875b03e1fcc
Yet more ifconfig cleanup. (As described on the mailing list [CLEANUP] thread.)
Rob Landley <rob@landley.net>
parents:
898
diff
changeset
|
93 sockun = (struct sockaddr_un *)&swl->sock_u.sock; |
e875b03e1fcc
Yet more ifconfig cleanup. (As described on the mailing list [CLEANUP] thread.)
Rob Landley <rob@landley.net>
parents:
898
diff
changeset
|
94 xstrncpy(sockun->sun_path, host + 6, sizeof(sockun->sun_path)); |
e875b03e1fcc
Yet more ifconfig cleanup. (As described on the mailing list [CLEANUP] thread.)
Rob Landley <rob@landley.net>
parents:
898
diff
changeset
|
95 |
e875b03e1fcc
Yet more ifconfig cleanup. (As described on the mailing list [CLEANUP] thread.)
Rob Landley <rob@landley.net>
parents:
898
diff
changeset
|
96 return swl; |
e875b03e1fcc
Yet more ifconfig cleanup. (As described on the mailing list [CLEANUP] thread.)
Rob Landley <rob@landley.net>
parents:
898
diff
changeset
|
97 } |
e875b03e1fcc
Yet more ifconfig cleanup. (As described on the mailing list [CLEANUP] thread.)
Rob Landley <rob@landley.net>
parents:
898
diff
changeset
|
98 |
e875b03e1fcc
Yet more ifconfig cleanup. (As described on the mailing list [CLEANUP] thread.)
Rob Landley <rob@landley.net>
parents:
898
diff
changeset
|
99 // [ipv6]:port or exactly one : |
841 | 100 |
905
e875b03e1fcc
Yet more ifconfig cleanup. (As described on the mailing list [CLEANUP] thread.)
Rob Landley <rob@landley.net>
parents:
898
diff
changeset
|
101 if (*host == '[') { |
e875b03e1fcc
Yet more ifconfig cleanup. (As described on the mailing list [CLEANUP] thread.)
Rob Landley <rob@landley.net>
parents:
898
diff
changeset
|
102 host++; |
e875b03e1fcc
Yet more ifconfig cleanup. (As described on the mailing list [CLEANUP] thread.)
Rob Landley <rob@landley.net>
parents:
898
diff
changeset
|
103 s = strchr(host, ']'); |
e875b03e1fcc
Yet more ifconfig cleanup. (As described on the mailing list [CLEANUP] thread.)
Rob Landley <rob@landley.net>
parents:
898
diff
changeset
|
104 if (s && !s[1]) s = 0; |
e875b03e1fcc
Yet more ifconfig cleanup. (As described on the mailing list [CLEANUP] thread.)
Rob Landley <rob@landley.net>
parents:
898
diff
changeset
|
105 else { |
e875b03e1fcc
Yet more ifconfig cleanup. (As described on the mailing list [CLEANUP] thread.)
Rob Landley <rob@landley.net>
parents:
898
diff
changeset
|
106 if (!s || s[1] != ':') error_exit("bad address '%s'", host-1); |
e875b03e1fcc
Yet more ifconfig cleanup. (As described on the mailing list [CLEANUP] thread.)
Rob Landley <rob@landley.net>
parents:
898
diff
changeset
|
107 s++; |
e875b03e1fcc
Yet more ifconfig cleanup. (As described on the mailing list [CLEANUP] thread.)
Rob Landley <rob@landley.net>
parents:
898
diff
changeset
|
108 } |
e875b03e1fcc
Yet more ifconfig cleanup. (As described on the mailing list [CLEANUP] thread.)
Rob Landley <rob@landley.net>
parents:
898
diff
changeset
|
109 } else { |
e875b03e1fcc
Yet more ifconfig cleanup. (As described on the mailing list [CLEANUP] thread.)
Rob Landley <rob@landley.net>
parents:
898
diff
changeset
|
110 s = strrchr(host, ':'); |
921 | 111 if (strchr(host, ':') != s) s = 0; |
905
e875b03e1fcc
Yet more ifconfig cleanup. (As described on the mailing list [CLEANUP] thread.)
Rob Landley <rob@landley.net>
parents:
898
diff
changeset
|
112 } |
e875b03e1fcc
Yet more ifconfig cleanup. (As described on the mailing list [CLEANUP] thread.)
Rob Landley <rob@landley.net>
parents:
898
diff
changeset
|
113 |
e875b03e1fcc
Yet more ifconfig cleanup. (As described on the mailing list [CLEANUP] thread.)
Rob Landley <rob@landley.net>
parents:
898
diff
changeset
|
114 if (s++) { |
e875b03e1fcc
Yet more ifconfig cleanup. (As described on the mailing list [CLEANUP] thread.)
Rob Landley <rob@landley.net>
parents:
898
diff
changeset
|
115 char *ss; |
e875b03e1fcc
Yet more ifconfig cleanup. (As described on the mailing list [CLEANUP] thread.)
Rob Landley <rob@landley.net>
parents:
898
diff
changeset
|
116 unsigned long p = strtoul(s, &ss, 0); |
e875b03e1fcc
Yet more ifconfig cleanup. (As described on the mailing list [CLEANUP] thread.)
Rob Landley <rob@landley.net>
parents:
898
diff
changeset
|
117 if (*ss || p > 65535) error_exit("bad port '%s'", s); |
e875b03e1fcc
Yet more ifconfig cleanup. (As described on the mailing list [CLEANUP] thread.)
Rob Landley <rob@landley.net>
parents:
898
diff
changeset
|
118 port = p; |
e875b03e1fcc
Yet more ifconfig cleanup. (As described on the mailing list [CLEANUP] thread.)
Rob Landley <rob@landley.net>
parents:
898
diff
changeset
|
119 } |
841 | 120 |
921 | 121 memset(&hints, 0 , sizeof(struct addrinfo)); |
122 hints.ai_family = af; | |
123 hints.ai_socktype = SOCK_STREAM; | |
124 | |
125 status = getaddrinfo(host, NULL, &hints, &result); | |
126 if (status) error_exit("bad address '%s' : %s", host, gai_strerror(status)); | |
127 | |
128 for (rp = result; rp; rp = rp->ai_next) { | |
129 if (rp->ai_family == AF_INET || rp->ai_family == AF_INET6) { | |
130 swl = xmalloc(sizeof(struct sockaddr_with_len)); | |
131 swl->socklen = rp->ai_addrlen; | |
132 memcpy(&swl->sock_u.sock, rp->ai_addr, rp->ai_addrlen); | |
133 break; | |
134 } | |
135 } | |
136 freeaddrinfo(result); | |
137 if (!rp) error_exit("bad host name"); | |
138 | |
841 | 139 |
852 | 140 if(swl->sock_u.sock.sa_family == AF_INET) |
141 swl->sock_u.sock_in.sin_port = port_num; | |
142 else if(swl->sock_u.sock.sa_family == AF_INET6) | |
143 swl->sock_u.sock_in6.sin6_port = port_num; | |
144 | |
841 | 145 return swl; |
146 } | |
147 | |
148 /* | |
149 * get the numeric hostname and service name, for a given socket address. | |
150 */ | |
852 | 151 char *address_to_name(struct sockaddr *sock) |
841 | 152 { |
153 //man page of getnameinfo. | |
154 char hbuf[NI_MAXHOST] = {0,}, sbuf[NI_MAXSERV] = {0,}; | |
155 int status = 0; | |
864 | 156 |
841 | 157 if(sock->sa_family == AF_INET) { |
158 socklen_t len = sizeof(struct sockaddr_in); | |
159 if((status = getnameinfo(sock, len, hbuf, sizeof(hbuf), sbuf, sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV)) == 0) | |
160 return xmsprintf("%s:%s", hbuf, sbuf); | |
161 else { | |
162 fprintf(stderr, "getnameinfo: %s\n", gai_strerror(status)); | |
163 return NULL; | |
164 } | |
864 | 165 } else if(sock->sa_family == AF_INET6) { |
841 | 166 socklen_t len = sizeof(struct sockaddr_in6); |
167 if((status = getnameinfo(sock, len, hbuf, sizeof(hbuf), sbuf, sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV)) == 0) { | |
168 //verification for resolved hostname. | |
169 if(strchr(hbuf, ':')) return xmsprintf("[%s]:%s", hbuf, sbuf); | |
170 else return xmsprintf("%s:%s", hbuf, sbuf); | |
864 | 171 } else { |
841 | 172 fprintf(stderr, "getnameinfo: %s\n", gai_strerror(status)); |
173 return NULL; | |
174 } | |
864 | 175 } else if(sock->sa_family == AF_UNIX) { |
841 | 176 struct sockaddr_un *sockun = (void*)sock; |
177 return xmsprintf("local:%.*s", (int) sizeof(sockun->sun_path), sockun->sun_path); | |
864 | 178 } else return NULL; |
841 | 179 } |
180 | |
921 | 181 static void set_address(char *host_name, struct ifreq *ifre, int request) |
841 | 182 { |
921 | 183 struct sockaddr_in *sock_in = (struct sockaddr_in *)&ifre->ifr_addr; |
841 | 184 sockaddr_with_len *swl = NULL; |
185 | |
921 | 186 memset(sock_in, 0, sizeof(struct sockaddr_in)); |
187 sock_in->sin_family = AF_INET; | |
841 | 188 |
189 //Default 0.0.0.0 | |
921 | 190 if(strcmp(host_name, "default") == 0) sock_in->sin_addr.s_addr = INADDR_ANY; |
841 | 191 else { |
192 swl = get_sockaddr(host_name, 0, AF_INET); | |
921 | 193 sock_in->sin_addr = swl->sock_u.sock_in.sin_addr; |
194 free(swl); | |
841 | 195 } |
921 | 196 xioctl(TT.sockfd, request, ifre); |
841 | 197 } |
198 | |
870 | 199 static void add_iface_to_list(struct if_list *newnode) |
841 | 200 { |
870 | 201 struct if_list *head_ref = TT.if_list; |
841 | 202 |
870 | 203 if(!head_ref || strcmp(newnode->name, head_ref->name) < 0) { |
841 | 204 newnode->next = head_ref; |
205 head_ref = newnode; | |
862 | 206 } else { |
870 | 207 struct if_list *current = head_ref; |
208 while(current->next && strcmp(current->next->name, newnode->name) < 0) | |
841 | 209 current = current->next; |
210 newnode->next = current->next; | |
211 current->next = newnode; | |
212 } | |
870 | 213 TT.if_list = (void *)head_ref; |
841 | 214 } |
215 | |
878
d4263ebf6f9b
Yet more drive-by cleanup of ifconfig.
Rob Landley <rob@landley.net>
parents:
870
diff
changeset
|
216 static void get_device_info(struct if_list *il) |
841 | 217 { |
218 struct ifreq ifre; | |
870 | 219 char *name = il->name; |
841 | 220 |
919
a186f9a1406d
More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents:
907
diff
changeset
|
221 il->txqueuelen = -1; |
a186f9a1406d
More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents:
907
diff
changeset
|
222 |
878
d4263ebf6f9b
Yet more drive-by cleanup of ifconfig.
Rob Landley <rob@landley.net>
parents:
870
diff
changeset
|
223 xstrncpy(ifre.ifr_name, name, IFNAMSIZ); |
921 | 224 if (ioctl(TT.sockfd, SIOCGIFFLAGS, &ifre)<0) perror_exit("%s", il->name); |
878
d4263ebf6f9b
Yet more drive-by cleanup of ifconfig.
Rob Landley <rob@landley.net>
parents:
870
diff
changeset
|
225 il->flags = ifre.ifr_flags; |
841 | 226 |
921 | 227 if (ioctl(TT.sockfd, SIOCGIFHWADDR, &ifre) >= 0) |
870 | 228 memcpy(il->hwaddr.sa_data, ifre.ifr_hwaddr.sa_data, sizeof(il->hwaddr.sa_data)); |
866
0fa773e2a4fe
Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents:
864
diff
changeset
|
229 il->hw_type = ifre.ifr_hwaddr.sa_family; |
841 | 230 |
921 | 231 if (ioctl(TT.sockfd, SIOCGIFMETRIC, &ifre) >= 0) |
232 il->metric = ifre.ifr_metric; | |
233 if (ioctl(TT.sockfd, SIOCGIFMTU, &ifre) >= 0) il->mtu = ifre.ifr_mtu; | |
234 if (ioctl(TT.sockfd, SIOCGIFMAP, &ifre) == 0) il->map = ifre.ifr_map; | |
235 if (ioctl(TT.sockfd, SIOCGIFTXQLEN, &ifre) >= 0) | |
236 il->txqueuelen = ifre.ifr_qlen; | |
841 | 237 |
919
a186f9a1406d
More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents:
907
diff
changeset
|
238 // If an address is assigned record that. |
841 | 239 |
240 ifre.ifr_addr.sa_family = AF_INET; | |
921 | 241 if (!ioctl(TT.sockfd, SIOCGIFADDR, &ifre)) il->addr = ifre.ifr_addr; |
242 if (ioctl(TT.sockfd, SIOCGIFDSTADDR, &ifre) >= 0) | |
243 il->dstaddr = ifre.ifr_dstaddr; | |
244 if (ioctl(TT.sockfd, SIOCGIFBRDADDR, &ifre) >= 0) | |
245 il->broadaddr = ifre.ifr_broadaddr; | |
246 if (ioctl(TT.sockfd, SIOCGIFNETMASK, &ifre) >= 0) | |
247 il->netmask = ifre.ifr_netmask; | |
841 | 248 } |
249 | |
870 | 250 static void display_ifconfig(struct if_list *il) |
841 | 251 { |
879
bc7aa2d123b9
And another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents:
878
diff
changeset
|
252 struct { |
bc7aa2d123b9
And another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents:
878
diff
changeset
|
253 int type; |
bc7aa2d123b9
And another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents:
878
diff
changeset
|
254 char *title; |
bc7aa2d123b9
And another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents:
878
diff
changeset
|
255 } types[] = { |
bc7aa2d123b9
And another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents:
878
diff
changeset
|
256 {ARPHRD_LOOPBACK, "Local Loopback"}, {ARPHRD_ETHER, "Ethernet"}, |
bc7aa2d123b9
And another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents:
878
diff
changeset
|
257 {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
|
258 {ARPHRD_SIT, "IPv6-in-IPv4"}, {-1, "UNSPEC"} |
bc7aa2d123b9
And another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents:
878
diff
changeset
|
259 }; |
bc7aa2d123b9
And another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents:
878
diff
changeset
|
260 int i; |
919
a186f9a1406d
More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents:
907
diff
changeset
|
261 char *p; |
921 | 262 FILE *fp; |
841 | 263 |
879
bc7aa2d123b9
And another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents:
878
diff
changeset
|
264 for (i=0; i < (sizeof(types)/sizeof(*types))-1; i++) |
bc7aa2d123b9
And another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents:
878
diff
changeset
|
265 if (il->hw_type == types[i].type) break; |
bc7aa2d123b9
And another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents:
878
diff
changeset
|
266 |
bc7aa2d123b9
And another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents:
878
diff
changeset
|
267 xprintf("%-9s Link encap:%s ", il->name, types[i].title); |
bc7aa2d123b9
And another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents:
878
diff
changeset
|
268 if(il->hwaddr.sa_data && il->hw_type == ARPHRD_ETHER) { |
bc7aa2d123b9
And another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents:
878
diff
changeset
|
269 xprintf("HWaddr "); |
bc7aa2d123b9
And another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents:
878
diff
changeset
|
270 for (i=0; i<6; i++) xprintf(":%02X"+!i, il->hwaddr.sa_data[i]); |
bc7aa2d123b9
And another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents:
878
diff
changeset
|
271 } |
852 | 272 xputc('\n'); |
866
0fa773e2a4fe
Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents:
864
diff
changeset
|
273 |
919
a186f9a1406d
More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents:
907
diff
changeset
|
274 p = (char *)&il->addr; |
a186f9a1406d
More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents:
907
diff
changeset
|
275 for (i = 0; i<sizeof(il->addr); i++) if (p[i]) break; |
a186f9a1406d
More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents:
907
diff
changeset
|
276 if (i != sizeof(il->addr)) { |
879
bc7aa2d123b9
And another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents:
878
diff
changeset
|
277 int af = il->addr.sa_family; |
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
|
278 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
|
279 char *name; |
ecb0befac82a
More ifconfig cleanup, inlining show_ip_addr(), hex_to_binary(), and set_hw_address().
Rob Landley <rob@landley.net>
parents:
906
diff
changeset
|
280 int flag, offset; |
ecb0befac82a
More ifconfig cleanup, inlining show_ip_addr(), hex_to_binary(), and set_hw_address().
Rob Landley <rob@landley.net>
parents:
906
diff
changeset
|
281 } addr[] = { |
ecb0befac82a
More ifconfig cleanup, inlining show_ip_addr(), hex_to_binary(), and set_hw_address().
Rob Landley <rob@landley.net>
parents:
906
diff
changeset
|
282 {"addr", 0, offsetof(struct if_list, addr)}, |
ecb0befac82a
More ifconfig cleanup, inlining show_ip_addr(), hex_to_binary(), and set_hw_address().
Rob Landley <rob@landley.net>
parents:
906
diff
changeset
|
283 {"P-t-P", IFF_POINTOPOINT, offsetof(struct if_list, dstaddr)}, |
ecb0befac82a
More ifconfig cleanup, inlining show_ip_addr(), hex_to_binary(), and set_hw_address().
Rob Landley <rob@landley.net>
parents:
906
diff
changeset
|
284 {"Bcast", IFF_BROADCAST, offsetof(struct if_list, broadaddr)}, |
ecb0befac82a
More ifconfig cleanup, inlining show_ip_addr(), hex_to_binary(), and set_hw_address().
Rob Landley <rob@landley.net>
parents:
906
diff
changeset
|
285 {"Mask", 0, offsetof(struct if_list, netmask)} |
ecb0befac82a
More ifconfig cleanup, inlining show_ip_addr(), hex_to_binary(), and set_hw_address().
Rob Landley <rob@landley.net>
parents:
906
diff
changeset
|
286 }; |
879
bc7aa2d123b9
And another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents:
878
diff
changeset
|
287 |
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
|
288 xprintf("%10c%s", ' ', |
ecb0befac82a
More ifconfig cleanup, inlining show_ip_addr(), hex_to_binary(), and set_hw_address().
Rob Landley <rob@landley.net>
parents:
906
diff
changeset
|
289 (af == AF_INET) ? "inet" : (af == AF_INET6) ? "inet6" : "unspec"); |
ecb0befac82a
More ifconfig cleanup, inlining show_ip_addr(), hex_to_binary(), and set_hw_address().
Rob Landley <rob@landley.net>
parents:
906
diff
changeset
|
290 |
ecb0befac82a
More ifconfig cleanup, inlining show_ip_addr(), hex_to_binary(), and set_hw_address().
Rob Landley <rob@landley.net>
parents:
906
diff
changeset
|
291 for (i=0; i < sizeof(addr)/sizeof(*addr); i++) { |
ecb0befac82a
More ifconfig cleanup, inlining show_ip_addr(), hex_to_binary(), and set_hw_address().
Rob Landley <rob@landley.net>
parents:
906
diff
changeset
|
292 struct sockaddr_in *s = (struct sockaddr_in *)(addr[i].offset+(char *)il); |
841 | 293 |
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
|
294 if (!addr[i].flag || (il->flags & addr[i].flag)) |
ecb0befac82a
More ifconfig cleanup, inlining show_ip_addr(), hex_to_binary(), and set_hw_address().
Rob Landley <rob@landley.net>
parents:
906
diff
changeset
|
295 xprintf(" %s:%s ", addr[i].name, |
ecb0befac82a
More ifconfig cleanup, inlining show_ip_addr(), hex_to_binary(), and set_hw_address().
Rob Landley <rob@landley.net>
parents:
906
diff
changeset
|
296 (s->sin_family == 0xFFFF || !s->sin_family) ? "[NOT SET]" : |
ecb0befac82a
More ifconfig cleanup, inlining show_ip_addr(), hex_to_binary(), and set_hw_address().
Rob Landley <rob@landley.net>
parents:
906
diff
changeset
|
297 inet_ntoa(s->sin_addr)); |
ecb0befac82a
More ifconfig cleanup, inlining show_ip_addr(), hex_to_binary(), and set_hw_address().
Rob Landley <rob@landley.net>
parents:
906
diff
changeset
|
298 } |
ecb0befac82a
More ifconfig cleanup, inlining show_ip_addr(), hex_to_binary(), and set_hw_address().
Rob Landley <rob@landley.net>
parents:
906
diff
changeset
|
299 |
879
bc7aa2d123b9
And another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents:
878
diff
changeset
|
300 xputc('\n'); |
bc7aa2d123b9
And another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents:
878
diff
changeset
|
301 } |
bc7aa2d123b9
And another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents:
878
diff
changeset
|
302 |
921 | 303 fp = fopen("/proc/net/if_net6", "r"); |
304 if (fp) { | |
305 char iface_name[IFNAMSIZ] = {0,}; | |
306 int plen, scope; | |
307 | |
308 while(fgets(toybuf, sizeof(toybuf), fp)) { | |
309 int nitems = 0; | |
310 char ipv6_addr[40] = {0,}; | |
311 nitems = sscanf(toybuf, "%32s %*08x %02x %02x %*02x %15s\n", | |
312 ipv6_addr+7, &plen, &scope, iface_name); | |
313 if(nitems != 4) { | |
314 if((nitems < 0) && feof(fp)) break; | |
315 perror_exit("sscanf"); | |
316 } | |
317 if(strcmp(il->name, iface_name) == 0) { | |
318 int i = 0; | |
319 struct sockaddr_in6 sock_in6; | |
320 int len = sizeof(ipv6_addr) / (sizeof ipv6_addr[0]); | |
321 char *ptr = ipv6_addr+7; | |
322 | |
323 while((i < len-2) && (*ptr)) { | |
324 ipv6_addr[i++] = *ptr++; | |
325 //put ':' after 4th bit | |
326 if(!((i+1) % 5)) ipv6_addr[i++] = ':'; | |
327 } | |
328 ipv6_addr[i+1] = '\0'; | |
329 if(inet_pton(AF_INET6, ipv6_addr, (struct sockaddr *) &sock_in6.sin6_addr) > 0) { | |
330 sock_in6.sin6_family = AF_INET6; | |
331 if(inet_ntop(AF_INET6, &sock_in6.sin6_addr, toybuf, BUFSIZ)) { | |
332 char *names[] = {"Global","Host","Link","Site","Compat"}, | |
333 *name = "Unknown"; | |
334 int j; | |
335 | |
336 for (j=0; j < sizeof(names)/sizeof(*names); j++) | |
337 if (scope == (!!j)<<(j+3)) name = names[j]; | |
338 xprintf("%10cinet6 addr: %s/%d Scope: %s\n", ' ', toybuf, plen, name); | |
339 } | |
340 } | |
341 } | |
342 } | |
343 fclose(fp); | |
344 } | |
345 | |
879
bc7aa2d123b9
And another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents:
878
diff
changeset
|
346 xprintf("%10c", ' '); |
866
0fa773e2a4fe
Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents:
864
diff
changeset
|
347 |
870 | 348 if (il->flags) { |
866
0fa773e2a4fe
Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents:
864
diff
changeset
|
349 unsigned short mask = 1; |
0fa773e2a4fe
Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents:
864
diff
changeset
|
350 char **s, *str[] = { |
0fa773e2a4fe
Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents:
864
diff
changeset
|
351 "UP", "BROADCAST", "DEBUG", "LOOPBACK", "POINTOPOINT", "NOTRAILERS", |
0fa773e2a4fe
Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents:
864
diff
changeset
|
352 "RUNNING", "NOARP", "PROMISC", "ALLMULTI", "MASTER", "SLAVE", "MULTICAST", |
0fa773e2a4fe
Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents:
864
diff
changeset
|
353 "PORTSEL", "AUTOMEDIA", "DYNAMIC", NULL |
0fa773e2a4fe
Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents:
864
diff
changeset
|
354 }; |
0fa773e2a4fe
Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents:
864
diff
changeset
|
355 |
0fa773e2a4fe
Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents:
864
diff
changeset
|
356 for(s = str; *s; s++) { |
870 | 357 if(il->flags & mask) xprintf("%s ", *s); |
866
0fa773e2a4fe
Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents:
864
diff
changeset
|
358 mask = mask << 1; |
0fa773e2a4fe
Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents:
864
diff
changeset
|
359 } |
0fa773e2a4fe
Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents:
864
diff
changeset
|
360 } else xprintf("[NO FLAGS] "); |
0fa773e2a4fe
Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents:
864
diff
changeset
|
361 |
870 | 362 if(!il->metric) il->metric = 1; |
363 xprintf(" MTU:%d Metric:%d", il->mtu, il->metric); | |
866
0fa773e2a4fe
Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents:
864
diff
changeset
|
364 |
0fa773e2a4fe
Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents:
864
diff
changeset
|
365 if(il->non_virtual_iface) { |
870 | 366 char *label[] = {"RX bytes", "RX packets", "errors", "dropped", "overruns", |
367 "frame", 0, 0, "TX bytes", "TX packets", "errors", "dropped", "overruns", | |
368 "collisions", "carrier", 0, "txqueuelen"}; | |
369 signed char order[] = {-1, 1, 2, 3, 4, 5, -1, 9, 10, 11, 12, 14, -1, | |
370 13, 16, -1, 0, 8}; | |
371 int i; | |
372 | |
373 for (i = 0; i < sizeof(order); i++) { | |
374 int j = order[i]; | |
841 | 375 |
870 | 376 if (j < 0) xprintf("\n%10c", ' '); |
377 else xprintf("%s:%llu ", label[j], | |
378 j==16 ? (unsigned long long)il->txqueuelen : il->val[j]); | |
379 } | |
842
af5aab6e6678
An ifconfig bugfix from the original submitter.
Rob Landley <rob@landley.net>
parents:
841
diff
changeset
|
380 } |
870 | 381 xputc('\n'); |
382 | |
383 if(il->map.irq || il->map.mem_start || il->map.dma || il->map.base_addr) { | |
866
0fa773e2a4fe
Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents:
864
diff
changeset
|
384 xprintf("%10c", ' '); |
870 | 385 if(il->map.irq) xprintf("Interrupt:%d ", il->map.irq); |
386 if(il->map.base_addr >= IO_MAP_INDEX) | |
387 xprintf("Base address:0x%lx ", il->map.base_addr); | |
388 if(il->map.mem_start) | |
389 xprintf("Memory:%lx-%lx ", il->map.mem_start, il->map.mem_end); | |
390 if(il->map.dma) xprintf("DMA chan:%x ", il->map.dma); | |
852 | 391 xputc('\n'); |
841 | 392 } |
852 | 393 xputc('\n'); |
841 | 394 } |
395 | |
870 | 396 static void readconf(void) |
842
af5aab6e6678
An ifconfig bugfix from the original submitter.
Rob Landley <rob@landley.net>
parents:
841
diff
changeset
|
397 { |
863
493f412fc5da
Fix the help commit I screwed up, and replace leading tabs with spaces.
Rob Landley <rob@landley.net>
parents:
862
diff
changeset
|
398 struct ifconf ifcon; |
493f412fc5da
Fix the help commit I screwed up, and replace leading tabs with spaces.
Rob Landley <rob@landley.net>
parents:
862
diff
changeset
|
399 struct ifreq *ifre; |
921 | 400 int num; |
842
af5aab6e6678
An ifconfig bugfix from the original submitter.
Rob Landley <rob@landley.net>
parents:
841
diff
changeset
|
401 |
919
a186f9a1406d
More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents:
907
diff
changeset
|
402 // Loop until buffer's big enough |
a186f9a1406d
More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents:
907
diff
changeset
|
403 ifcon.ifc_buf = NULL; |
a186f9a1406d
More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents:
907
diff
changeset
|
404 for (num = 30;;num += 10) { |
a186f9a1406d
More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents:
907
diff
changeset
|
405 ifcon.ifc_len = sizeof(struct ifreq)*num; |
a186f9a1406d
More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents:
907
diff
changeset
|
406 ifcon.ifc_buf = xrealloc(ifcon.ifc_buf, ifcon.ifc_len); |
921 | 407 xioctl(TT.sockfd, SIOCGIFCONF, &ifcon); |
919
a186f9a1406d
More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents:
907
diff
changeset
|
408 if (ifcon.ifc_len != sizeof(struct ifreq)*num) break; |
864 | 409 } |
842
af5aab6e6678
An ifconfig bugfix from the original submitter.
Rob Landley <rob@landley.net>
parents:
841
diff
changeset
|
410 |
863
493f412fc5da
Fix the help commit I screwed up, and replace leading tabs with spaces.
Rob Landley <rob@landley.net>
parents:
862
diff
changeset
|
411 ifre = ifcon.ifc_req; |
919
a186f9a1406d
More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents:
907
diff
changeset
|
412 for(num = 0; num < ifcon.ifc_len && ifre; num += sizeof(struct ifreq), ifre++) |
a186f9a1406d
More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents:
907
diff
changeset
|
413 { |
870 | 414 struct if_list *il; |
866
0fa773e2a4fe
Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents:
864
diff
changeset
|
415 |
919
a186f9a1406d
More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents:
907
diff
changeset
|
416 // Skip duplicates |
870 | 417 for(il = TT.if_list; il; il = il->next) |
418 if(!strcmp(ifre->ifr_name, il->name)) break; | |
866
0fa773e2a4fe
Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents:
864
diff
changeset
|
419 if(!il) { |
870 | 420 il = xzalloc(sizeof(struct if_list)); |
421 xstrncpy(il->name, ifre->ifr_name, IFNAMSIZ); | |
866
0fa773e2a4fe
Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents:
864
diff
changeset
|
422 add_iface_to_list(il); |
878
d4263ebf6f9b
Yet more drive-by cleanup of ifconfig.
Rob Landley <rob@landley.net>
parents:
870
diff
changeset
|
423 get_device_info(il); |
863
493f412fc5da
Fix the help commit I screwed up, and replace leading tabs with spaces.
Rob Landley <rob@landley.net>
parents:
862
diff
changeset
|
424 } |
493f412fc5da
Fix the help commit I screwed up, and replace leading tabs with spaces.
Rob Landley <rob@landley.net>
parents:
862
diff
changeset
|
425 } |
842
af5aab6e6678
An ifconfig bugfix from the original submitter.
Rob Landley <rob@landley.net>
parents:
841
diff
changeset
|
426 |
863
493f412fc5da
Fix the help commit I screwed up, and replace leading tabs with spaces.
Rob Landley <rob@landley.net>
parents:
862
diff
changeset
|
427 free(ifcon.ifc_buf); |
842
af5aab6e6678
An ifconfig bugfix from the original submitter.
Rob Landley <rob@landley.net>
parents:
841
diff
changeset
|
428 } |
af5aab6e6678
An ifconfig bugfix from the original submitter.
Rob Landley <rob@landley.net>
parents:
841
diff
changeset
|
429 |
870 | 430 static void show_iface(char *iface_name) |
841 | 431 { |
870 | 432 struct if_list *il; |
433 int i, j; | |
434 FILE *fp; | |
435 | |
436 fp = xfopen("/proc/net/dev", "r"); | |
437 | |
438 for (i=0; fgets(toybuf, sizeof(toybuf), fp); i++) { | |
439 char *name, *buf; | |
440 | |
441 if (i<2) continue; | |
866
0fa773e2a4fe
Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents:
864
diff
changeset
|
442 |
870 | 443 il = xzalloc(sizeof(struct if_list)); |
444 for (buf = toybuf; isspace(*buf); buf++); | |
445 name = strsep(&buf, ":"); | |
446 if(!buf) error_exit("bad name %s", name); | |
447 xstrncpy(il->name, name, IFNAMSIZ); | |
448 | |
449 errno = 0; | |
450 for (j=0; j<16 && !errno; j++) il->val[j] = strtoll(buf, &buf, 0); | |
451 if (errno) perror_exit("bad %s at %s", name, buf); | |
452 | |
453 add_iface_to_list(il); | |
454 il->non_virtual_iface = 1; | |
878
d4263ebf6f9b
Yet more drive-by cleanup of ifconfig.
Rob Landley <rob@landley.net>
parents:
870
diff
changeset
|
455 get_device_info(il); |
870 | 456 } |
457 fclose(fp); | |
842
af5aab6e6678
An ifconfig bugfix from the original submitter.
Rob Landley <rob@landley.net>
parents:
841
diff
changeset
|
458 |
919
a186f9a1406d
More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents:
907
diff
changeset
|
459 if (iface_name) { |
870 | 460 for(il = TT.if_list; il; il = il->next) { |
461 if(!strcmp(il->name, iface_name)) { | |
866
0fa773e2a4fe
Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents:
864
diff
changeset
|
462 display_ifconfig(il); |
841 | 463 break; |
464 } | |
465 } | |
842
af5aab6e6678
An ifconfig bugfix from the original submitter.
Rob Landley <rob@landley.net>
parents:
841
diff
changeset
|
466 //if the given interface is not in the list. |
866
0fa773e2a4fe
Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents:
864
diff
changeset
|
467 if(!il) { |
870 | 468 il = xzalloc(sizeof(struct if_list)); |
469 xstrncpy(il->name, iface_name, IFNAMSIZ); | |
878
d4263ebf6f9b
Yet more drive-by cleanup of ifconfig.
Rob Landley <rob@landley.net>
parents:
870
diff
changeset
|
470 get_device_info(il); |
d4263ebf6f9b
Yet more drive-by cleanup of ifconfig.
Rob Landley <rob@landley.net>
parents:
870
diff
changeset
|
471 display_ifconfig(il); |
866
0fa773e2a4fe
Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents:
864
diff
changeset
|
472 free(il); |
841 | 473 } |
852 | 474 } else { |
870 | 475 readconf(); |
476 for(il = TT.if_list; il; il = il->next) | |
477 if((il->flags & IFF_UP) || (toys.optflags & FLAG_a)) | |
866
0fa773e2a4fe
Another round of ifconfig cleanup.
Rob Landley <rob@landley.net>
parents:
864
diff
changeset
|
478 display_ifconfig(il); |
841 | 479 } |
878
d4263ebf6f9b
Yet more drive-by cleanup of ifconfig.
Rob Landley <rob@landley.net>
parents:
870
diff
changeset
|
480 |
d4263ebf6f9b
Yet more drive-by cleanup of ifconfig.
Rob Landley <rob@landley.net>
parents:
870
diff
changeset
|
481 if (CFG_TOYBOX_FREE) llist_traverse(TT.if_list, free); |
841 | 482 } |
869
571e95bdf6af
ifconfig cleanup (Reorder functions to eliminate need for prototypes, put main at end).
Rob Landley <rob@landley.net>
parents:
866
diff
changeset
|
483 |
919
a186f9a1406d
More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents:
907
diff
changeset
|
484 // 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
|
485 #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
|
486 |
869
571e95bdf6af
ifconfig cleanup (Reorder functions to eliminate need for prototypes, put main at end).
Rob Landley <rob@landley.net>
parents:
866
diff
changeset
|
487 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
|
488 { |
571e95bdf6af
ifconfig cleanup (Reorder functions to eliminate need for prototypes, put main at end).
Rob Landley <rob@landley.net>
parents:
866
diff
changeset
|
489 char **argv = toys.optargs; |
898
f6db08574875
Ifconfig cleanup to option parsing.
Rob Landley <rob@landley.net>
parents:
883
diff
changeset
|
490 struct ifreq ifre; |
921 | 491 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
|
492 |
571e95bdf6af
ifconfig cleanup (Reorder functions to eliminate need for prototypes, put main at end).
Rob Landley <rob@landley.net>
parents:
866
diff
changeset
|
493 if(*argv && (strcmp(*argv, "--help") == 0)) show_help(); |
571e95bdf6af
ifconfig cleanup (Reorder functions to eliminate need for prototypes, put main at end).
Rob Landley <rob@landley.net>
parents:
866
diff
changeset
|
494 |
921 | 495 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
|
496 if(toys.optc < 2) { |
870 | 497 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
|
498 return; |
571e95bdf6af
ifconfig cleanup (Reorder functions to eliminate need for prototypes, put main at end).
Rob Landley <rob@landley.net>
parents:
866
diff
changeset
|
499 } |
571e95bdf6af
ifconfig cleanup (Reorder functions to eliminate need for prototypes, put main at end).
Rob Landley <rob@landley.net>
parents:
866
diff
changeset
|
500 |
919
a186f9a1406d
More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents:
907
diff
changeset
|
501 // Open interface |
898
f6db08574875
Ifconfig cleanup to option parsing.
Rob Landley <rob@landley.net>
parents:
883
diff
changeset
|
502 memset(&ifre, 0, sizeof(struct ifreq)); |
f6db08574875
Ifconfig cleanup to option parsing.
Rob Landley <rob@landley.net>
parents:
883
diff
changeset
|
503 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
|
504 |
919
a186f9a1406d
More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents:
907
diff
changeset
|
505 // Perform operations on interface |
898
f6db08574875
Ifconfig cleanup to option parsing.
Rob Landley <rob@landley.net>
parents:
883
diff
changeset
|
506 while(*++argv) { |
905
e875b03e1fcc
Yet more ifconfig cleanup. (As described on the mailing list [CLEANUP] thread.)
Rob Landley <rob@landley.net>
parents:
898
diff
changeset
|
507 struct argh { |
898
f6db08574875
Ifconfig cleanup to option parsing.
Rob Landley <rob@landley.net>
parents:
883
diff
changeset
|
508 char *name; |
906
ce0a9368b82f
Next round of ifconfig cleanup, to be described on mailing list.
Rob Landley <rob@landley.net>
parents:
905
diff
changeset
|
509 int on, off; // set, clear |
898
f6db08574875
Ifconfig cleanup to option parsing.
Rob Landley <rob@landley.net>
parents:
883
diff
changeset
|
510 } try[] = { |
906
ce0a9368b82f
Next round of ifconfig cleanup, to be described on mailing list.
Rob Landley <rob@landley.net>
parents:
905
diff
changeset
|
511 {"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
|
512 {"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
|
513 {"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
|
514 {"trailers", 0, IFF_NOTRAILERS}, |
ce0a9368b82f
Next round of ifconfig cleanup, to be described on mailing list.
Rob Landley <rob@landley.net>
parents:
905
diff
changeset
|
515 {"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
|
516 {"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
|
517 {"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
|
518 {"dynamic", IFF_DYNAMIC, 0}, |
ce0a9368b82f
Next round of ifconfig cleanup, to be described on mailing list.
Rob Landley <rob@landley.net>
parents:
905
diff
changeset
|
519 {"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
|
520 {"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
|
521 {"netmask", 0, SIOCSIFNETMASK}, |
919
a186f9a1406d
More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents:
907
diff
changeset
|
522 {"dstaddr", 0, SIOCSIFDSTADDR}, |
a186f9a1406d
More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents:
907
diff
changeset
|
523 {"mtu", IFREQ_OFFSZ(ifr_mtu), SIOCSIFMTU}, |
921 | 524 {"keepalive", IFREQ_OFFSZ(ifr_data), SIOCDEVPRIVATE}, // SIOCSKEEPALIVE |
525 {"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
|
526 {"metric", IFREQ_OFFSZ(ifr_metric), SIOCSIFMETRIC}, |
a186f9a1406d
More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents:
907
diff
changeset
|
527 {"txqueuelen", IFREQ_OFFSZ(ifr_qlen), SIOCSIFTXQLEN}, |
a186f9a1406d
More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents:
907
diff
changeset
|
528 {"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
|
529 {"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
|
530 {"irq", IFREQ_OFFSZ(ifr_map.irq), SIOCSIFMAP}, |
a186f9a1406d
More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents:
907
diff
changeset
|
531 {"inet", 0, 0}, |
a186f9a1406d
More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents:
907
diff
changeset
|
532 {"inet6", 0, 0} |
898
f6db08574875
Ifconfig cleanup to option parsing.
Rob Landley <rob@landley.net>
parents:
883
diff
changeset
|
533 }; |
f6db08574875
Ifconfig cleanup to option parsing.
Rob Landley <rob@landley.net>
parents:
883
diff
changeset
|
534 char *s = *argv; |
f6db08574875
Ifconfig cleanup to option parsing.
Rob Landley <rob@landley.net>
parents:
883
diff
changeset
|
535 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
|
536 |
898
f6db08574875
Ifconfig cleanup to option parsing.
Rob Landley <rob@landley.net>
parents:
883
diff
changeset
|
537 s += rev; |
f6db08574875
Ifconfig cleanup to option parsing.
Rob Landley <rob@landley.net>
parents:
883
diff
changeset
|
538 |
f6db08574875
Ifconfig cleanup to option parsing.
Rob Landley <rob@landley.net>
parents:
883
diff
changeset
|
539 for (i = 0; i < sizeof(try)/sizeof(*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
|
540 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
|
541 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
|
542 |
e875b03e1fcc
Yet more ifconfig cleanup. (As described on the mailing list [CLEANUP] thread.)
Rob Landley <rob@landley.net>
parents:
898
diff
changeset
|
543 if (strcmp(t->name, s)) continue; |
898
f6db08574875
Ifconfig cleanup to option parsing.
Rob Landley <rob@landley.net>
parents:
883
diff
changeset
|
544 |
906
ce0a9368b82f
Next round of ifconfig cleanup, to be described on mailing list.
Rob Landley <rob@landley.net>
parents:
905
diff
changeset
|
545 // Is this an SIOCSI entry? |
919
a186f9a1406d
More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents:
907
diff
changeset
|
546 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
|
547 if (!rev) { |
ce0a9368b82f
Next round of ifconfig cleanup, to be described on mailing list.
Rob Landley <rob@landley.net>
parents:
905
diff
changeset
|
548 if (!*++argv) show_help(); |
919
a186f9a1406d
More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents:
907
diff
changeset
|
549 |
a186f9a1406d
More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents:
907
diff
changeset
|
550 // 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
|
551 if (on < 0) { |
a186f9a1406d
More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents:
907
diff
changeset
|
552 long l = strtoul(*argv, 0, 0); |
a186f9a1406d
More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents:
907
diff
changeset
|
553 |
921 | 554 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
|
555 on = -on; |
a186f9a1406d
More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents:
907
diff
changeset
|
556 poke((on>>16) + (char *)&ifre, l, on&15); |
921 | 557 xioctl(TT.sockfd, off, &ifre); |
919
a186f9a1406d
More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents:
907
diff
changeset
|
558 break; |
921 | 559 } else set_address(*argv, &ifre, off); |
906
ce0a9368b82f
Next round of ifconfig cleanup, to be described on mailing list.
Rob Landley <rob@landley.net>
parents:
905
diff
changeset
|
560 } |
ce0a9368b82f
Next round of ifconfig cleanup, to be described on mailing list.
Rob Landley <rob@landley.net>
parents:
905
diff
changeset
|
561 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
|
562 } |
919
a186f9a1406d
More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents:
907
diff
changeset
|
563 |
a186f9a1406d
More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents:
907
diff
changeset
|
564 // Set flags |
906
ce0a9368b82f
Next round of ifconfig cleanup, to be described on mailing list.
Rob Landley <rob@landley.net>
parents:
905
diff
changeset
|
565 if (on || off) { |
921 | 566 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
|
567 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
|
568 ifre.ifr_flags |= (rev ? off : on); |
921 | 569 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
|
570 } |
898
f6db08574875
Ifconfig cleanup to option parsing.
Rob Landley <rob@landley.net>
parents:
883
diff
changeset
|
571 |
f6db08574875
Ifconfig cleanup to option parsing.
Rob Landley <rob@landley.net>
parents:
883
diff
changeset
|
572 break; |
f6db08574875
Ifconfig cleanup to option parsing.
Rob Landley <rob@landley.net>
parents:
883
diff
changeset
|
573 } |
f6db08574875
Ifconfig cleanup to option parsing.
Rob Landley <rob@landley.net>
parents:
883
diff
changeset
|
574 if (i != sizeof(try)/sizeof(*try)) continue; |
f6db08574875
Ifconfig cleanup to option parsing.
Rob Landley <rob@landley.net>
parents:
883
diff
changeset
|
575 |
905
e875b03e1fcc
Yet more ifconfig cleanup. (As described on the mailing list [CLEANUP] thread.)
Rob Landley <rob@landley.net>
parents:
898
diff
changeset
|
576 if (!strcmp(*argv, "hw")) { |
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
|
577 char *hw_addr, *ptr, *p; |
ecb0befac82a
More ifconfig cleanup, inlining show_ip_addr(), hex_to_binary(), and set_hw_address().
Rob Landley <rob@landley.net>
parents:
906
diff
changeset
|
578 struct sockaddr *sock = &ifre.ifr_hwaddr; |
ecb0befac82a
More ifconfig cleanup, inlining show_ip_addr(), hex_to_binary(), and set_hw_address().
Rob Landley <rob@landley.net>
parents:
906
diff
changeset
|
579 int count = 6; |
ecb0befac82a
More ifconfig cleanup, inlining show_ip_addr(), hex_to_binary(), and set_hw_address().
Rob Landley <rob@landley.net>
parents:
906
diff
changeset
|
580 |
869
571e95bdf6af
ifconfig cleanup (Reorder functions to eliminate need for prototypes, put main at end).
Rob Landley <rob@landley.net>
parents:
866
diff
changeset
|
581 if (!*++argv) show_help(); |
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
|
582 |
ecb0befac82a
More ifconfig cleanup, inlining show_ip_addr(), hex_to_binary(), and set_hw_address().
Rob Landley <rob@landley.net>
parents:
906
diff
changeset
|
583 memset(sock, 0, sizeof(struct sockaddr)); |
ecb0befac82a
More ifconfig cleanup, inlining show_ip_addr(), hex_to_binary(), and set_hw_address().
Rob Landley <rob@landley.net>
parents:
906
diff
changeset
|
584 if (!strcmp("ether", *argv)) sock->sa_family = ARPHRD_ETHER; |
ecb0befac82a
More ifconfig cleanup, inlining show_ip_addr(), hex_to_binary(), and set_hw_address().
Rob Landley <rob@landley.net>
parents:
906
diff
changeset
|
585 else if (!strcmp("infiniband", *argv)) { |
ecb0befac82a
More ifconfig cleanup, inlining show_ip_addr(), hex_to_binary(), and set_hw_address().
Rob Landley <rob@landley.net>
parents:
906
diff
changeset
|
586 sock->sa_family = ARPHRD_INFINIBAND; |
ecb0befac82a
More ifconfig cleanup, inlining show_ip_addr(), hex_to_binary(), and set_hw_address().
Rob Landley <rob@landley.net>
parents:
906
diff
changeset
|
587 count = 20; |
ecb0befac82a
More ifconfig cleanup, inlining show_ip_addr(), hex_to_binary(), and set_hw_address().
Rob Landley <rob@landley.net>
parents:
906
diff
changeset
|
588 } else { |
ecb0befac82a
More ifconfig cleanup, inlining show_ip_addr(), hex_to_binary(), and set_hw_address().
Rob Landley <rob@landley.net>
parents:
906
diff
changeset
|
589 toys.exithelp++; |
ecb0befac82a
More ifconfig cleanup, inlining show_ip_addr(), hex_to_binary(), and set_hw_address().
Rob Landley <rob@landley.net>
parents:
906
diff
changeset
|
590 error_exit("bad hw '%s'", *argv); |
ecb0befac82a
More ifconfig cleanup, inlining show_ip_addr(), hex_to_binary(), and set_hw_address().
Rob Landley <rob@landley.net>
parents:
906
diff
changeset
|
591 } |
ecb0befac82a
More ifconfig cleanup, inlining show_ip_addr(), hex_to_binary(), and set_hw_address().
Rob Landley <rob@landley.net>
parents:
906
diff
changeset
|
592 hw_addr = *++argv; |
ecb0befac82a
More ifconfig cleanup, inlining show_ip_addr(), hex_to_binary(), and set_hw_address().
Rob Landley <rob@landley.net>
parents:
906
diff
changeset
|
593 |
ecb0befac82a
More ifconfig cleanup, inlining show_ip_addr(), hex_to_binary(), and set_hw_address().
Rob Landley <rob@landley.net>
parents:
906
diff
changeset
|
594 ptr = p = (char *) sock->sa_data; |
905
e875b03e1fcc
Yet more ifconfig cleanup. (As described on the mailing list [CLEANUP] thread.)
Rob Landley <rob@landley.net>
parents:
898
diff
changeset
|
595 |
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
|
596 while (*hw_addr && (p-ptr) < count) { |
ecb0befac82a
More ifconfig cleanup, inlining show_ip_addr(), hex_to_binary(), and set_hw_address().
Rob Landley <rob@landley.net>
parents:
906
diff
changeset
|
597 int val, len = 0; |
ecb0befac82a
More ifconfig cleanup, inlining show_ip_addr(), hex_to_binary(), and set_hw_address().
Rob Landley <rob@landley.net>
parents:
906
diff
changeset
|
598 |
ecb0befac82a
More ifconfig cleanup, inlining show_ip_addr(), hex_to_binary(), and set_hw_address().
Rob Landley <rob@landley.net>
parents:
906
diff
changeset
|
599 if (*hw_addr == ':') hw_addr++; |
ecb0befac82a
More ifconfig cleanup, inlining show_ip_addr(), hex_to_binary(), and set_hw_address().
Rob Landley <rob@landley.net>
parents:
906
diff
changeset
|
600 sscanf(hw_addr, "%2x%n", &val, &len); |
ecb0befac82a
More ifconfig cleanup, inlining show_ip_addr(), hex_to_binary(), and set_hw_address().
Rob Landley <rob@landley.net>
parents:
906
diff
changeset
|
601 if (len != 2) break; |
ecb0befac82a
More ifconfig cleanup, inlining show_ip_addr(), hex_to_binary(), and set_hw_address().
Rob Landley <rob@landley.net>
parents:
906
diff
changeset
|
602 hw_addr += len; |
ecb0befac82a
More ifconfig cleanup, inlining show_ip_addr(), hex_to_binary(), and set_hw_address().
Rob Landley <rob@landley.net>
parents:
906
diff
changeset
|
603 *p++ = val; |
ecb0befac82a
More ifconfig cleanup, inlining show_ip_addr(), hex_to_binary(), and set_hw_address().
Rob Landley <rob@landley.net>
parents:
906
diff
changeset
|
604 } |
ecb0befac82a
More ifconfig cleanup, inlining show_ip_addr(), hex_to_binary(), and set_hw_address().
Rob Landley <rob@landley.net>
parents:
906
diff
changeset
|
605 |
ecb0befac82a
More ifconfig cleanup, inlining show_ip_addr(), hex_to_binary(), and set_hw_address().
Rob Landley <rob@landley.net>
parents:
906
diff
changeset
|
606 if ((p-ptr) != count || *hw_addr) |
ecb0befac82a
More ifconfig cleanup, inlining show_ip_addr(), hex_to_binary(), and set_hw_address().
Rob Landley <rob@landley.net>
parents:
906
diff
changeset
|
607 error_exit("bad hw-addr '%s'", hw_addr ? hw_addr : ""); |
921 | 608 xioctl(TT.sockfd, SIOCSIFHWADDR, &ifre); |
609 | |
610 // Add/remove ipv6 address to interface | |
906
ce0a9368b82f
Next round of ifconfig cleanup, to be described on mailing list.
Rob Landley <rob@landley.net>
parents:
905
diff
changeset
|
611 |
919
a186f9a1406d
More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents:
907
diff
changeset
|
612 } else if (!strcmp(*argv, "add") || !strcmp(*argv, "del")) { |
921 | 613 sockaddr_with_len *swl = NULL; |
614 struct ifreq_inet6 ifre6; | |
615 char *prefix; | |
616 int plen = 0, sockfd6 = xsocket(AF_INET6, SOCK_DGRAM, 0); | |
617 | |
919
a186f9a1406d
More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents:
907
diff
changeset
|
618 if (!argv[1]) show_help(); |
921 | 619 |
620 prefix = strchr(argv[1], '/'); | |
621 if (prefix) { | |
622 plen = get_int_value(prefix + 1, 0, 128); | |
623 *prefix = 0; | |
624 } | |
625 swl = get_sockaddr(argv[1], 0, AF_INET6); | |
626 ifre6.ifrinte6_addr = swl->sock_u.sock_in6.sin6_addr; | |
627 xioctl(sockfd6, SIOCGIFINDEX, &ifre); | |
628 ifre6.ifrinet6_ifindex = ifre.ifr_ifindex; | |
629 ifre6.ifrinet6_prefixlen = plen; | |
630 xioctl(sockfd6, **argv=='a' ? SIOCSIFADDR : SIOCDIFADDR, &ifre6); | |
631 | |
632 free(swl); | |
633 close(sockfd6); | |
634 | |
919
a186f9a1406d
More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents:
907
diff
changeset
|
635 argv++; |
a186f9a1406d
More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents:
907
diff
changeset
|
636 } else if (isdigit(**argv) || !strcmp(*argv, "default")) { |
921 | 637 set_address(*argv, &ifre, SIOCSIFADDR); |
869
571e95bdf6af
ifconfig cleanup (Reorder functions to eliminate need for prototypes, put main at end).
Rob Landley <rob@landley.net>
parents:
866
diff
changeset
|
638 //if the interface name is not an alias; set the flag and continue. |
919
a186f9a1406d
More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents:
907
diff
changeset
|
639 if(!strchr(ifre.ifr_name, ':')) { |
921 | 640 xioctl(TT.sockfd, SIOCGIFFLAGS, &ifre); |
919
a186f9a1406d
More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents:
907
diff
changeset
|
641 ifre.ifr_flags |= IFF_UP|IFF_RUNNING; |
921 | 642 xioctl(TT.sockfd, SIOCSIFFLAGS, &ifre); |
919
a186f9a1406d
More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents:
907
diff
changeset
|
643 } |
869
571e95bdf6af
ifconfig cleanup (Reorder functions to eliminate need for prototypes, put main at end).
Rob Landley <rob@landley.net>
parents:
866
diff
changeset
|
644 |
919
a186f9a1406d
More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents:
907
diff
changeset
|
645 } else { |
a186f9a1406d
More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents:
907
diff
changeset
|
646 errno = EINVAL; |
a186f9a1406d
More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents:
907
diff
changeset
|
647 toys.exithelp++; |
a186f9a1406d
More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents:
907
diff
changeset
|
648 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
|
649 } |
919
a186f9a1406d
More ifconfig cleanup, described on list.
Rob Landley <rob@landley.net>
parents:
907
diff
changeset
|
650 } |
921 | 651 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
|
652 } |