arp.c (0442747236f4a934d1fc6a3354ce691b4b97067a) arp.c (9d34414bc2a9385fb400e1ca7384bd4c4d1291cd)
1/*
2 * Copyright (c) 1984, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Sun Microsystems, Inc.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 70 unchanged lines hidden (view full) ---

79#include <stdio.h>
80#include <stdlib.h>
81#include <strings.h>
82#include <unistd.h>
83
84void search(u_long addr, void (*action)(struct sockaddr_dl *sdl,
85 struct sockaddr_inarp *sin, struct rt_msghdr *rtm));
86void print_entry(struct sockaddr_dl *sdl,
1/*
2 * Copyright (c) 1984, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Sun Microsystems, Inc.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 70 unchanged lines hidden (view full) ---

79#include <stdio.h>
80#include <stdlib.h>
81#include <strings.h>
82#include <unistd.h>
83
84void search(u_long addr, void (*action)(struct sockaddr_dl *sdl,
85 struct sockaddr_inarp *sin, struct rt_msghdr *rtm));
86void print_entry(struct sockaddr_dl *sdl,
87 struct sockaddr_inarp *sin, struct rt_msghdr *rtm);
87 struct sockaddr_inarp *addr, struct rt_msghdr *rtm);
88void nuke_entry(struct sockaddr_dl *sdl,
88void nuke_entry(struct sockaddr_dl *sdl,
89 struct sockaddr_inarp *sin, struct rt_msghdr *rtm);
89 struct sockaddr_inarp *addr, struct rt_msghdr *rtm);
90int delete(char *host, char *info);
91void ether_print(u_char *cp);
92void usage(void);
93int set(int argc, char **argv);
94int get(char *host);
95int file(char *name);
96void getsocket(void);
97int my_ether_aton(char *a, u_char *n);
98int rtmsg(int cmd);
99int get_ether_addr(u_int32_t ipaddr, u_char *hwaddr);
100
101static int pid;
102static int nflag; /* no reverse dns lookups */
103static int aflag; /* do it for all entries */
104static int s = -1;
105
90int delete(char *host, char *info);
91void ether_print(u_char *cp);
92void usage(void);
93int set(int argc, char **argv);
94int get(char *host);
95int file(char *name);
96void getsocket(void);
97int my_ether_aton(char *a, u_char *n);
98int rtmsg(int cmd);
99int get_ether_addr(u_int32_t ipaddr, u_char *hwaddr);
100
101static int pid;
102static int nflag; /* no reverse dns lookups */
103static int aflag; /* do it for all entries */
104static int s = -1;
105
106struct sockaddr_in so_mask;
107struct sockaddr_inarp blank_sin, sin_m;
108struct sockaddr_dl blank_sdl, sdl_m;
109int expire_time, flags, doing_proxy, proxy_only, found_entry;
110struct {
111 struct rt_msghdr m_rtm;
112 char m_space[512];
113} m_rtmsg;
114
106/* which function we're supposed to do */
107#define F_GET 1
108#define F_SET 2
109#define F_FILESET 3
110#define F_REPLACE 4
111#define F_DELETE 5
112
113#define ROUNDUP(a) \

--- 29 unchanged lines hidden (view full) ---

143 break;
144 case '?':
145 default:
146 usage();
147 }
148 argc -= optind;
149 argv += optind;
150
115/* which function we're supposed to do */
116#define F_GET 1
117#define F_SET 2
118#define F_FILESET 3
119#define F_REPLACE 4
120#define F_DELETE 5
121
122#define ROUNDUP(a) \

--- 29 unchanged lines hidden (view full) ---

152 break;
153 case '?':
154 default:
155 usage();
156 }
157 argc -= optind;
158 argv += optind;
159
160 bzero(&so_mask, sizeof(so_mask));
161 so_mask.sin_family = 8;
162 so_mask.sin_addr.s_addr = 0xffffffff;
163 bzero(&blank_sin, sizeof(blank_sin));
164 blank_sin.sin_len = sizeof(blank_sin);
165 blank_sin.sin_family = AF_INET;
166 bzero(&blank_sdl, sizeof(blank_sdl));
167 blank_sdl.sdl_len = sizeof(blank_sdl);
168 blank_sdl.sdl_family = AF_LINK;
169
151 if (!func)
152 func = F_GET;
153 switch (func) {
154 case F_GET:
155 if (aflag) {
156 if (argc != 0)
157 usage();
158 search(0, print_entry);

--- 70 unchanged lines hidden (view full) ---

229{
230 if (s < 0) {
231 s = socket(PF_ROUTE, SOCK_RAW, 0);
232 if (s < 0)
233 err(1, "socket");
234 }
235}
236
170 if (!func)
171 func = F_GET;
172 switch (func) {
173 case F_GET:
174 if (aflag) {
175 if (argc != 0)
176 usage();
177 search(0, print_entry);

--- 70 unchanged lines hidden (view full) ---

248{
249 if (s < 0) {
250 s = socket(PF_ROUTE, SOCK_RAW, 0);
251 if (s < 0)
252 err(1, "socket");
253 }
254}
255
237struct sockaddr_in so_mask = {8, 0, 0, { 0xffffffff}};
238struct sockaddr_inarp blank_sin = {sizeof(blank_sin), AF_INET }, sin_m;
239struct sockaddr_dl blank_sdl = {sizeof(blank_sdl), AF_LINK }, sdl_m;
240int expire_time, flags, doing_proxy, proxy_only, found_entry;
241struct {
242 struct rt_msghdr m_rtm;
243 char m_space[512];
244} m_rtmsg;
245
246/*
247 * Set an individual arp entry
248 */
249int
250set(int argc, char **argv)
251{
252 struct hostent *hp;
256/*
257 * Set an individual arp entry
258 */
259int
260set(int argc, char **argv)
261{
262 struct hostent *hp;
253 register struct sockaddr_inarp *sin = &sin_m;
263 register struct sockaddr_inarp *addr = &sin_m;
254 register struct sockaddr_dl *sdl;
255 register struct rt_msghdr *rtm = &(m_rtmsg.m_rtm);
256 u_char *ea;
257 char *host = argv[0], *eaddr = argv[1];
258
259 getsocket();
260 argc -= 2;
261 argv += 2;
262 sdl_m = blank_sdl;
263 sin_m = blank_sin;
264 register struct sockaddr_dl *sdl;
265 register struct rt_msghdr *rtm = &(m_rtmsg.m_rtm);
266 u_char *ea;
267 char *host = argv[0], *eaddr = argv[1];
268
269 getsocket();
270 argc -= 2;
271 argv += 2;
272 sdl_m = blank_sdl;
273 sin_m = blank_sin;
264 sin->sin_addr.s_addr = inet_addr(host);
265 if (sin->sin_addr.s_addr == INADDR_NONE) {
274 addr->sin_addr.s_addr = inet_addr(host);
275 if (addr->sin_addr.s_addr == INADDR_NONE) {
266 if (!(hp = gethostbyname(host))) {
267 warnx("%s: %s", host, hstrerror(h_errno));
268 return (1);
269 }
276 if (!(hp = gethostbyname(host))) {
277 warnx("%s: %s", host, hstrerror(h_errno));
278 return (1);
279 }
270 bcopy((char *)hp->h_addr, (char *)&sin->sin_addr,
271 sizeof sin->sin_addr);
280 bcopy((char *)hp->h_addr, (char *)&addr->sin_addr,
281 sizeof addr->sin_addr);
272 }
273 doing_proxy = flags = proxy_only = expire_time = 0;
274 while (argc-- > 0) {
275 if (strncmp(argv[0], "temp", 4) == 0) {
276 struct timeval tv;
277 gettimeofday(&tv, 0);
278 expire_time = tv.tv_sec + 20 * 60;
279 }

--- 8 unchanged lines hidden (view full) ---

288 } else if (strncmp(argv[0], "trail", 5) == 0) {
289 printf("%s: Sending trailers is no longer supported\n",
290 host);
291 }
292 argv++;
293 }
294 ea = (u_char *)LLADDR(&sdl_m);
295 if (doing_proxy && !strcmp(eaddr, "auto")) {
282 }
283 doing_proxy = flags = proxy_only = expire_time = 0;
284 while (argc-- > 0) {
285 if (strncmp(argv[0], "temp", 4) == 0) {
286 struct timeval tv;
287 gettimeofday(&tv, 0);
288 expire_time = tv.tv_sec + 20 * 60;
289 }

--- 8 unchanged lines hidden (view full) ---

298 } else if (strncmp(argv[0], "trail", 5) == 0) {
299 printf("%s: Sending trailers is no longer supported\n",
300 host);
301 }
302 argv++;
303 }
304 ea = (u_char *)LLADDR(&sdl_m);
305 if (doing_proxy && !strcmp(eaddr, "auto")) {
296 if (!get_ether_addr(sin->sin_addr.s_addr, ea)) {
306 if (!get_ether_addr(addr->sin_addr.s_addr, ea)) {
297 printf("no interface found for %s\n",
307 printf("no interface found for %s\n",
298 inet_ntoa(sin->sin_addr));
308 inet_ntoa(addr->sin_addr));
299 return (1);
300 }
301 sdl_m.sdl_alen = 6;
302 } else {
303 if (my_ether_aton(eaddr, ea) == 0)
304 sdl_m.sdl_alen = 6;
305 }
306tryagain:
307 if (rtmsg(RTM_GET) < 0) {
308 warn("%s", host);
309 return (1);
310 }
309 return (1);
310 }
311 sdl_m.sdl_alen = 6;
312 } else {
313 if (my_ether_aton(eaddr, ea) == 0)
314 sdl_m.sdl_alen = 6;
315 }
316tryagain:
317 if (rtmsg(RTM_GET) < 0) {
318 warn("%s", host);
319 return (1);
320 }
311 sin = (struct sockaddr_inarp *)(rtm + 1);
312 sdl = (struct sockaddr_dl *)(ROUNDUP(sin->sin_len) + (char *)sin);
313 if (sin->sin_addr.s_addr == sin_m.sin_addr.s_addr) {
321 addr = (struct sockaddr_inarp *)(rtm + 1);
322 sdl = (struct sockaddr_dl *)(ROUNDUP(addr->sin_len) + (char *)addr);
323 if (addr->sin_addr.s_addr == sin_m.sin_addr.s_addr) {
314 if (sdl->sdl_family == AF_LINK &&
315 (rtm->rtm_flags & RTF_LLINFO) &&
316 !(rtm->rtm_flags & RTF_GATEWAY)) switch (sdl->sdl_type) {
317 case IFT_ETHER: case IFT_FDDI: case IFT_ISO88023:
318 case IFT_ISO88024: case IFT_ISO88025: case IFT_L2VLAN:
319 goto overwrite;
320 }
321 if (doing_proxy == 0) {

--- 20 unchanged lines hidden (view full) ---

342
343/*
344 * Display an individual arp entry
345 */
346int
347get(char *host)
348{
349 struct hostent *hp;
324 if (sdl->sdl_family == AF_LINK &&
325 (rtm->rtm_flags & RTF_LLINFO) &&
326 !(rtm->rtm_flags & RTF_GATEWAY)) switch (sdl->sdl_type) {
327 case IFT_ETHER: case IFT_FDDI: case IFT_ISO88023:
328 case IFT_ISO88024: case IFT_ISO88025: case IFT_L2VLAN:
329 goto overwrite;
330 }
331 if (doing_proxy == 0) {

--- 20 unchanged lines hidden (view full) ---

352
353/*
354 * Display an individual arp entry
355 */
356int
357get(char *host)
358{
359 struct hostent *hp;
350 struct sockaddr_inarp *sin = &sin_m;
360 struct sockaddr_inarp *addr = &sin_m;
351
352 sin_m = blank_sin;
361
362 sin_m = blank_sin;
353 sin->sin_addr.s_addr = inet_addr(host);
354 if (sin->sin_addr.s_addr == INADDR_NONE) {
363 addr->sin_addr.s_addr = inet_addr(host);
364 if (addr->sin_addr.s_addr == INADDR_NONE) {
355 if (!(hp = gethostbyname(host)))
356 errx(1, "%s: %s", host, hstrerror(h_errno));
365 if (!(hp = gethostbyname(host)))
366 errx(1, "%s: %s", host, hstrerror(h_errno));
357 bcopy((char *)hp->h_addr, (char *)&sin->sin_addr,
358 sizeof sin->sin_addr);
367 bcopy((char *)hp->h_addr, (char *)&addr->sin_addr,
368 sizeof addr->sin_addr);
359 }
369 }
360 search(sin->sin_addr.s_addr, print_entry);
370 search(addr->sin_addr.s_addr, print_entry);
361 if (found_entry == 0) {
362 printf("%s (%s) -- no entry\n",
371 if (found_entry == 0) {
372 printf("%s (%s) -- no entry\n",
363 host, inet_ntoa(sin->sin_addr));
373 host, inet_ntoa(addr->sin_addr));
364 return(1);
365 }
366 return(0);
367}
368
369/*
370 * Delete an arp entry
371 */
372int
373delete(char *host, char *info)
374{
375 struct hostent *hp;
374 return(1);
375 }
376 return(0);
377}
378
379/*
380 * Delete an arp entry
381 */
382int
383delete(char *host, char *info)
384{
385 struct hostent *hp;
376 register struct sockaddr_inarp *sin = &sin_m;
386 register struct sockaddr_inarp *addr = &sin_m;
377 register struct rt_msghdr *rtm = &m_rtmsg.m_rtm;
378 struct sockaddr_dl *sdl;
379
380 getsocket();
381 sin_m = blank_sin;
382 if (info) {
383 if (strncmp(info, "pub", 3) == 0)
384 sin_m.sin_other = SIN_PROXY;
385 else
386 usage();
387 }
387 register struct rt_msghdr *rtm = &m_rtmsg.m_rtm;
388 struct sockaddr_dl *sdl;
389
390 getsocket();
391 sin_m = blank_sin;
392 if (info) {
393 if (strncmp(info, "pub", 3) == 0)
394 sin_m.sin_other = SIN_PROXY;
395 else
396 usage();
397 }
388 sin->sin_addr.s_addr = inet_addr(host);
389 if (sin->sin_addr.s_addr == INADDR_NONE) {
398 addr->sin_addr.s_addr = inet_addr(host);
399 if (addr->sin_addr.s_addr == INADDR_NONE) {
390 if (!(hp = gethostbyname(host))) {
391 warnx("%s: %s", host, hstrerror(h_errno));
392 return (1);
393 }
400 if (!(hp = gethostbyname(host))) {
401 warnx("%s: %s", host, hstrerror(h_errno));
402 return (1);
403 }
394 bcopy((char *)hp->h_addr, (char *)&sin->sin_addr,
395 sizeof sin->sin_addr);
404 bcopy((char *)hp->h_addr, (char *)&addr->sin_addr,
405 sizeof addr->sin_addr);
396 }
397tryagain:
398 if (rtmsg(RTM_GET) < 0) {
399 warn("%s", host);
400 return (1);
401 }
406 }
407tryagain:
408 if (rtmsg(RTM_GET) < 0) {
409 warn("%s", host);
410 return (1);
411 }
402 sin = (struct sockaddr_inarp *)(rtm + 1);
403 sdl = (struct sockaddr_dl *)(ROUNDUP(sin->sin_len) + (char *)sin);
404 if (sin->sin_addr.s_addr == sin_m.sin_addr.s_addr) {
412 addr = (struct sockaddr_inarp *)(rtm + 1);
413 sdl = (struct sockaddr_dl *)(ROUNDUP(addr->sin_len) + (char *)addr);
414 if (addr->sin_addr.s_addr == sin_m.sin_addr.s_addr) {
405 if (sdl->sdl_family == AF_LINK &&
406 (rtm->rtm_flags & RTF_LLINFO) &&
407 !(rtm->rtm_flags & RTF_GATEWAY)) switch (sdl->sdl_type) {
408 case IFT_ETHER: case IFT_FDDI: case IFT_ISO88023:
409 case IFT_ISO88024: case IFT_ISO88025: case IFT_L2VLAN:
410 goto delete;
411 }
412 }

--- 5 unchanged lines hidden (view full) ---

418 goto tryagain;
419 }
420delete:
421 if (sdl->sdl_family != AF_LINK) {
422 printf("cannot locate %s\n", host);
423 return (1);
424 }
425 if (rtmsg(RTM_DELETE) == 0) {
415 if (sdl->sdl_family == AF_LINK &&
416 (rtm->rtm_flags & RTF_LLINFO) &&
417 !(rtm->rtm_flags & RTF_GATEWAY)) switch (sdl->sdl_type) {
418 case IFT_ETHER: case IFT_FDDI: case IFT_ISO88023:
419 case IFT_ISO88024: case IFT_ISO88025: case IFT_L2VLAN:
420 goto delete;
421 }
422 }

--- 5 unchanged lines hidden (view full) ---

428 goto tryagain;
429 }
430delete:
431 if (sdl->sdl_family != AF_LINK) {
432 printf("cannot locate %s\n", host);
433 return (1);
434 }
435 if (rtmsg(RTM_DELETE) == 0) {
426 printf("%s (%s) deleted\n", host, inet_ntoa(sin->sin_addr));
436 printf("%s (%s) deleted\n", host, inet_ntoa(addr->sin_addr));
427 return (0);
428 }
429 return (1);
430}
431
432/*
433 * Search the arp table and do some action on matching entries
434 */
435void
436search(u_long addr, void (*action)(struct sockaddr_dl *sdl,
437 struct sockaddr_inarp *sin, struct rt_msghdr *rtm))
438{
439 int mib[6];
440 size_t needed;
441 char *lim, *buf, *next;
442 struct rt_msghdr *rtm;
437 return (0);
438 }
439 return (1);
440}
441
442/*
443 * Search the arp table and do some action on matching entries
444 */
445void
446search(u_long addr, void (*action)(struct sockaddr_dl *sdl,
447 struct sockaddr_inarp *sin, struct rt_msghdr *rtm))
448{
449 int mib[6];
450 size_t needed;
451 char *lim, *buf, *next;
452 struct rt_msghdr *rtm;
443 struct sockaddr_inarp *sin;
453 struct sockaddr_inarp *sin2;
444 struct sockaddr_dl *sdl;
445
446 mib[0] = CTL_NET;
447 mib[1] = PF_ROUTE;
448 mib[2] = 0;
449 mib[3] = AF_INET;
450 mib[4] = NET_RT_FLAGS;
451 mib[5] = RTF_LLINFO;
452 if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0)
453 errx(1, "route-sysctl-estimate");
454 if ((buf = malloc(needed)) == NULL)
455 errx(1, "malloc");
456 if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0)
457 errx(1, "actual retrieval of routing table");
458 lim = buf + needed;
459 for (next = buf; next < lim; next += rtm->rtm_msglen) {
460 rtm = (struct rt_msghdr *)next;
454 struct sockaddr_dl *sdl;
455
456 mib[0] = CTL_NET;
457 mib[1] = PF_ROUTE;
458 mib[2] = 0;
459 mib[3] = AF_INET;
460 mib[4] = NET_RT_FLAGS;
461 mib[5] = RTF_LLINFO;
462 if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0)
463 errx(1, "route-sysctl-estimate");
464 if ((buf = malloc(needed)) == NULL)
465 errx(1, "malloc");
466 if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0)
467 errx(1, "actual retrieval of routing table");
468 lim = buf + needed;
469 for (next = buf; next < lim; next += rtm->rtm_msglen) {
470 rtm = (struct rt_msghdr *)next;
461 sin = (struct sockaddr_inarp *)(rtm + 1);
462 (char *)sdl = (char *)sin + ROUNDUP(sin->sin_len);
471 sin2 = (struct sockaddr_inarp *)(rtm + 1);
472 (char *)sdl = (char *)sin2 + ROUNDUP(sin2->sin_len);
463 if (addr) {
473 if (addr) {
464 if (addr != sin->sin_addr.s_addr)
474 if (addr != sin2->sin_addr.s_addr)
465 continue;
466 found_entry = 1;
467 }
475 continue;
476 found_entry = 1;
477 }
468 (*action)(sdl, sin, rtm);
478 (*action)(sdl, sin2, rtm);
469 }
470 free(buf);
471}
472
473/*
474 * Display an arp entry
475 */
476void
477print_entry(struct sockaddr_dl *sdl,
479 }
480 free(buf);
481}
482
483/*
484 * Display an arp entry
485 */
486void
487print_entry(struct sockaddr_dl *sdl,
478 struct sockaddr_inarp *sin, struct rt_msghdr *rtm)
488 struct sockaddr_inarp *addr, struct rt_msghdr *rtm)
479{
480 const char *host;
481 struct hostent *hp;
482 char ifname[IF_NAMESIZE];
483 int seg;
484
485 if (nflag == 0)
489{
490 const char *host;
491 struct hostent *hp;
492 char ifname[IF_NAMESIZE];
493 int seg;
494
495 if (nflag == 0)
486 hp = gethostbyaddr((caddr_t)&(sin->sin_addr),
487 sizeof sin->sin_addr, AF_INET);
496 hp = gethostbyaddr((caddr_t)&(addr->sin_addr),
497 sizeof addr->sin_addr, AF_INET);
488 else
489 hp = 0;
490 if (hp)
491 host = hp->h_name;
492 else {
493 host = "?";
494 if (h_errno == TRY_AGAIN)
495 nflag = 1;
496 }
498 else
499 hp = 0;
500 if (hp)
501 host = hp->h_name;
502 else {
503 host = "?";
504 if (h_errno == TRY_AGAIN)
505 nflag = 1;
506 }
497 printf("%s (%s) at ", host, inet_ntoa(sin->sin_addr));
507 printf("%s (%s) at ", host, inet_ntoa(addr->sin_addr));
498 if (sdl->sdl_alen)
499 ether_print(LLADDR(sdl));
500 else
501 printf("(incomplete)");
502 if (if_indextoname(sdl->sdl_index, ifname) != NULL)
503 printf(" on %s", ifname);
504 if (rtm->rtm_rmx.rmx_expire == 0)
505 printf(" permanent");
508 if (sdl->sdl_alen)
509 ether_print(LLADDR(sdl));
510 else
511 printf("(incomplete)");
512 if (if_indextoname(sdl->sdl_index, ifname) != NULL)
513 printf(" on %s", ifname);
514 if (rtm->rtm_rmx.rmx_expire == 0)
515 printf(" permanent");
506 if (sin->sin_other & SIN_PROXY)
516 if (addr->sin_other & SIN_PROXY)
507 printf(" published (proxy only)");
508 if (rtm->rtm_addrs & RTA_NETMASK) {
517 printf(" published (proxy only)");
518 if (rtm->rtm_addrs & RTA_NETMASK) {
509 sin = (struct sockaddr_inarp *)
519 addr = (struct sockaddr_inarp *)
510 (ROUNDUP(sdl->sdl_len) + (char *)sdl);
520 (ROUNDUP(sdl->sdl_len) + (char *)sdl);
511 if (sin->sin_addr.s_addr == 0xffffffff)
521 if (addr->sin_addr.s_addr == 0xffffffff)
512 printf(" published");
522 printf(" published");
513 if (sin->sin_len != 8)
523 if (addr->sin_len != 8)
514 printf("(weird)");
515 }
516 switch(sdl->sdl_type) {
517 case IFT_ETHER:
518 printf(" [ethernet]");
519 break;
520 case IFT_ISO88025:
521 printf(" [token-ring]");

--- 18 unchanged lines hidden (view full) ---

540 printf("\n");
541
542}
543
544/*
545 * Nuke an arp entry
546 */
547void
524 printf("(weird)");
525 }
526 switch(sdl->sdl_type) {
527 case IFT_ETHER:
528 printf(" [ethernet]");
529 break;
530 case IFT_ISO88025:
531 printf(" [token-ring]");

--- 18 unchanged lines hidden (view full) ---

550 printf("\n");
551
552}
553
554/*
555 * Nuke an arp entry
556 */
557void
548nuke_entry(struct sockaddr_dl *sdl,
549 struct sockaddr_inarp *sin, struct rt_msghdr *rtm)
558nuke_entry(struct sockaddr_dl *sdl __unused,
559 struct sockaddr_inarp *addr, struct rt_msghdr *rtm __unused)
550{
551 char ip[20];
552
560{
561 char ip[20];
562
553 snprintf(ip, sizeof(ip), "%s", inet_ntoa(sin->sin_addr));
563 snprintf(ip, sizeof(ip), "%s", inet_ntoa(addr->sin_addr));
554 delete(ip, NULL);
555}
556
557void
558ether_print(u_char *cp)
559{
560 printf("%02x:%02x:%02x:%02x:%02x:%02x", cp[0], cp[1], cp[2], cp[3],
561 cp[4], cp[5]);

--- 103 unchanged lines hidden (view full) ---

665get_ether_addr(u_int32_t ipaddr, u_char *hwaddr)
666{
667 struct ifreq *ifr, *ifend, *ifp;
668 u_int32_t ina, mask;
669 struct sockaddr_dl *dla;
670 struct ifreq ifreq;
671 struct ifconf ifc;
672 struct ifreq ifs[MAX_IFS];
564 delete(ip, NULL);
565}
566
567void
568ether_print(u_char *cp)
569{
570 printf("%02x:%02x:%02x:%02x:%02x:%02x", cp[0], cp[1], cp[2], cp[3],
571 cp[4], cp[5]);

--- 103 unchanged lines hidden (view full) ---

675get_ether_addr(u_int32_t ipaddr, u_char *hwaddr)
676{
677 struct ifreq *ifr, *ifend, *ifp;
678 u_int32_t ina, mask;
679 struct sockaddr_dl *dla;
680 struct ifreq ifreq;
681 struct ifconf ifc;
682 struct ifreq ifs[MAX_IFS];
673 int s;
683 int sock;
674
684
675 s = socket(AF_INET, SOCK_DGRAM, 0);
676 if (s < 0)
685 sock = socket(AF_INET, SOCK_DGRAM, 0);
686 if (sock < 0)
677 err(1, "socket");
678
679 ifc.ifc_len = sizeof(ifs);
680 ifc.ifc_req = ifs;
681 if (ioctl(s, SIOCGIFCONF, &ifc) < 0) {
682 warnx("ioctl(SIOCGIFCONF)");
687 err(1, "socket");
688
689 ifc.ifc_len = sizeof(ifs);
690 ifc.ifc_req = ifs;
691 if (ioctl(s, SIOCGIFCONF, &ifc) < 0) {
692 warnx("ioctl(SIOCGIFCONF)");
683 close(s);
693 close(sock);
684 return 0;
685 }
686
687 /*
688 * Scan through looking for an interface with an Internet
689 * address on the same subnet as `ipaddr'.
690 */
691 ifend = (struct ifreq *) (ifc.ifc_buf + ifc.ifc_len);

--- 27 unchanged lines hidden (view full) ---

719 break;
720 }
721nextif:
722 ifr = (struct ifreq *) ((char *)&ifr->ifr_addr
723 + MAX(ifr->ifr_addr.sa_len, sizeof(ifr->ifr_addr)));
724 }
725
726 if (ifr >= ifend) {
694 return 0;
695 }
696
697 /*
698 * Scan through looking for an interface with an Internet
699 * address on the same subnet as `ipaddr'.
700 */
701 ifend = (struct ifreq *) (ifc.ifc_buf + ifc.ifc_len);

--- 27 unchanged lines hidden (view full) ---

729 break;
730 }
731nextif:
732 ifr = (struct ifreq *) ((char *)&ifr->ifr_addr
733 + MAX(ifr->ifr_addr.sa_len, sizeof(ifr->ifr_addr)));
734 }
735
736 if (ifr >= ifend) {
727 close(s);
737 close(sock);
728 return 0;
729 }
730
731 /*
732 * Now scan through again looking for a link-level address
733 * for this interface.
734 */
735 ifp = ifr;

--- 20 unchanged lines hidden ---
738 return 0;
739 }
740
741 /*
742 * Now scan through again looking for a link-level address
743 * for this interface.
744 */
745 ifp = ifr;

--- 20 unchanged lines hidden ---