aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-09-03 12:23:56 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-09-03 12:23:56 +0000
commit035aae584111cd92af37a124160dbcb9e810d84c (patch)
treee0293b09f2e455e94e11cd406eb4956a65956030
parent27af5a0dd34b1b392aa69b548e18935aafe66e5f (diff)
downloadbusybox-w32-035aae584111cd92af37a124160dbcb9e810d84c.tar.gz
busybox-w32-035aae584111cd92af37a124160dbcb9e810d84c.tar.bz2
busybox-w32-035aae584111cd92af37a124160dbcb9e810d84c.zip
zcip: use xfunc() where appropriate
-rw-r--r--networking/zcip.c52
1 files changed, 23 insertions, 29 deletions
diff --git a/networking/zcip.c b/networking/zcip.c
index e9dd05011..176bc0101 100644
--- a/networking/zcip.c
+++ b/networking/zcip.c
@@ -132,6 +132,7 @@ static int arp(int fd, struct sockaddr *saddr, int op,
132 132
133/** 133/**
134 * Run a script. 134 * Run a script.
135 * TODO: sort out stderr/syslog reporting.
135 */ 136 */
136static int run(char *script, char *arg, char *intf, struct in_addr *ip) 137static int run(char *script, char *arg, char *intf, struct in_addr *ip)
137{ 138{
@@ -207,6 +208,9 @@ int zcip_main(int argc, char *argv[])
207 int t; 208 int t;
208 int state = PROBE; 209 int state = PROBE;
209 210
211 struct ifreq ifr;
212 unsigned short seed[3];
213
210 // parse commandline: prog [options] ifname script 214 // parse commandline: prog [options] ifname script
211 while ((t = getopt(argc, argv, "fqr:v")) != EOF) { 215 while ((t = getopt(argc, argv, "fqr:v")) != EOF) {
212 switch (t) { 216 switch (t) {
@@ -249,38 +253,28 @@ int zcip_main(int argc, char *argv[])
249 safe_strncpy(saddr.sa_data, intf, sizeof (saddr.sa_data)); 253 safe_strncpy(saddr.sa_data, intf, sizeof (saddr.sa_data));
250 254
251 // open an ARP socket 255 // open an ARP socket
252 if ((fd = socket(PF_PACKET, SOCK_PACKET, htons(ETH_P_ARP))) < 0) { 256 fd = xsocket(PF_PACKET, SOCK_PACKET, htons(ETH_P_ARP));
253 why = "open"; 257 // bind to the interface's ARP socket
254fail: 258 xbind(fd, &saddr, sizeof (saddr);
259
260 // get the interface's ethernet address
261 memset(&ifr, 0, sizeof (ifr));
262 strncpy(ifr.ifr_name, intf, sizeof (ifr.ifr_name));
263 if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0) {
255 foreground = 1; 264 foreground = 1;
265 why = "get ethernet address";
256 goto bad; 266 goto bad;
257 } 267 }
258 // bind to the interface's ARP socket 268 memcpy(&addr, &ifr.ifr_hwaddr.sa_data, ETH_ALEN);
259 if (bind(fd, &saddr, sizeof (saddr)) < 0) { 269
260 why = "bind"; 270 // start with some stable ip address, either a function of
261 goto fail; 271 // the hardware address or else the last address we used.
262 } else { 272 // NOTE: the sequence of addresses we try changes only
263 struct ifreq ifr; 273 // depending on when we detect conflicts.
264 unsigned short seed[3]; 274 memcpy(seed, &ifr.ifr_hwaddr.sa_data, ETH_ALEN);
265 275 seed48(seed);
266 // get the interface's ethernet address 276 if (ip.s_addr == 0)
267 memset(&ifr, 0, sizeof (ifr)); 277 pick(&ip);
268 strncpy(ifr.ifr_name, intf, sizeof (ifr.ifr_name));
269 if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0) {
270 why = "get ethernet address";
271 goto fail;
272 }
273 memcpy(&addr, &ifr.ifr_hwaddr.sa_data, ETH_ALEN);
274
275 // start with some stable ip address, either a function of
276 // the hardware address or else the last address we used.
277 // NOTE: the sequence of addresses we try changes only
278 // depending on when we detect conflicts.
279 memcpy(seed, &ifr.ifr_hwaddr.sa_data, ETH_ALEN);
280 seed48(seed);
281 if (ip.s_addr == 0)
282 pick(&ip);
283 }
284 278
285 // FIXME cases to handle: 279 // FIXME cases to handle:
286 // - zcip already running! 280 // - zcip already running!