X-Git-Url: https://git.saurik.com/apple/network_cmds.git/blobdiff_plain/2b484d24084b903459c5b416c06cd77b48c748b9..7af5ce03cf81eb8cf0c6e1bfd903b52fcc7c224a:/rarpd.tproj/rarpd.c?ds=sidebyside diff --git a/rarpd.tproj/rarpd.c b/rarpd.tproj/rarpd.c index 890be78..fcea9bc 100644 --- a/rarpd.tproj/rarpd.c +++ b/rarpd.tproj/rarpd.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * Copyright (c) 1999-2009 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -41,15 +41,16 @@ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ +#include #ifndef lint -char copyright[] = +__unused char copyright[] = "@(#) Copyright (c) 1990 The Regents of the University of California.\n\ All rights reserved.\n"; #endif /* not lint */ #ifndef lint -static char rcsid[] = -"@(#) $Id: rarpd.c,v 1.1.1.1 1999/05/02 03:57:59 wsanchez Exp $"; +__unused static char rcsid[] = +"@(#) $Id: rarpd.c,v 1.3 2006/04/05 03:13:14 lindak Exp $"; #endif @@ -91,8 +92,8 @@ static char rcsid[] = struct if_info { int ii_fd; /* BPF file descriptor */ u_char ii_eaddr[6]; /* Ethernet address of this interface */ - u_long ii_ipaddr; /* IP address of this interface */ - u_long ii_netmask; /* subnet or net mask */ + in_addr_t ii_ipaddr; /* IP address of this interface */ + in_addr_t ii_netmask; /* subnet or net mask */ struct if_info *ii_next; }; /* @@ -102,25 +103,25 @@ struct if_info { struct if_info *iflist; int rarp_open __P((char *)); -int rarp_bootable __P((u_long)); +int rarp_bootable __P((in_addr_t)); void init_one __P((char *)); void init_all __P((void)); void rarp_loop __P((void)); void lookup_eaddr __P((char *, u_char *)); -void lookup_ipaddr __P((char *, u_long *, u_long *)); +void lookup_ipaddr __P((char *, in_addr_t *, in_addr_t *)); void usage __P((void)); void rarp_process __P((struct if_info *, u_char *)); -void rarp_reply __P((struct if_info *, struct ether_header *, u_long)); -void update_arptab __P((u_char *, u_long)); +void rarp_reply __P((struct if_info *, struct ether_header *, in_addr_t)); +void update_arptab __P((u_char *, in_addr_t)); void err __P((int, const char *,...)); void debug __P((const char *,...)); -u_long ipaddrtonetmask __P((u_long)); +in_addr_t ipaddrtonetmask __P((in_addr_t)); int aflag = 0; /* listen on "all" interfaces */ int dflag = 0; /* print debugging messages */ int fflag = 0; /* don't fork */ -void +int main(argc, argv) int argc; char **argv; @@ -128,10 +129,9 @@ main(argc, argv) int op, pid, devnull, f; char *ifname, *hostname, *name; - extern char *optarg; extern int optind, opterr; - if (name = strrchr(argv[0], '/')) + if ((name = strrchr(argv[0], '/')) != NULL) ++name; else name = argv[0]; @@ -191,7 +191,7 @@ main(argc, argv) (void) close(f); } (void) chdir("/"); - (void) setpgrp(0, getpid()); + (void) setpgid(0, getpid()); devnull = open("/dev/null", O_RDWR); if (devnull >= 0) { (void) dup2(devnull, 0); @@ -202,6 +202,8 @@ main(argc, argv) } } rarp_loop(); + /* NOTREACHED */ + return 0; } /* * Add 'ifname' to the interface list. Lookup its IP address and network @@ -285,7 +287,7 @@ bpf_open() /* Go through all the minors and find one that isn't in use. */ do { - (void) sprintf(device, "/dev/bpf%d", n++); + (void) snprintf(device, sizeof(device), "/dev/bpf%d", n++); fd = open(device, O_RDWR); } while (fd < 0 && errno == EBUSY); @@ -481,16 +483,16 @@ rarp_loop() */ int rarp_bootable(addr) - u_long addr; + in_addr_t addr; { register struct dirent *dent; register DIR *d; char ipname[9]; static DIR *dd = 0; - (void) sprintf(ipname, "%08X", addr); + (void) snprintf(ipname, sizeof(ipname), "%08X", addr); /* If directory is already open, rewind it. Otherwise, open it. */ - if (d = dd) + if ((d = dd) != NULL) rewinddir(d); else { if (chdir(TFTP_DIR) == -1) { @@ -504,7 +506,7 @@ rarp_bootable(addr) } dd = d; } - while (dent = readdir(d)) + while ((dent = readdir(d)) != NULL) if (strncmp(dent->d_name, ipname, 8) == 0) return 1; return 0; @@ -514,11 +516,11 @@ rarp_bootable(addr) * is on network 'net'; 'netmask' is a mask indicating the network portion * of the address. */ -u_long +in_addr_t choose_ipaddr(alist, net, netmask) - u_long **alist; - u_long net; - u_long netmask; + in_addr_t **alist; + in_addr_t net; + in_addr_t netmask; { for (; *alist; ++alist) { if ((**alist & netmask) == net) @@ -537,13 +539,13 @@ rarp_process(ii, pkt) { struct ether_header *ep; struct hostent *hp; - u_long target_ipaddr; + in_addr_t target_ipaddr; char ename[256]; struct in_addr in; ep = (struct ether_header *) pkt; - if (ether_ntohost(ename, &ep->ether_shost) != 0 || + if (ether_ntohost(ename, (struct ether_addr *)&ep->ether_shost) != 0 || (hp = gethostbyname(ename)) == 0) return; @@ -552,7 +554,7 @@ rarp_process(ii, pkt) err(FATAL, "cannot handle non IP addresses"); /* NOTREACHED */ } - target_ipaddr = choose_ipaddr((u_long **) hp->h_addr_list, + target_ipaddr = choose_ipaddr((in_addr_t **) hp->h_addr_list, ii->ii_ipaddr & ii->ii_netmask, ii->ii_netmask); if (target_ipaddr == 0) { @@ -623,8 +625,8 @@ lookup_eaddr(ifname, eaddr) void lookup_ipaddr(ifname, addrp, netmaskp) char *ifname; - u_long *addrp; - u_long *netmaskp; + in_addr_t *addrp; + in_addr_t *netmaskp; { int fd; struct ifreq ifr; @@ -661,9 +663,9 @@ lookup_ipaddr(ifname, addrp, netmaskp) void update_arptab(ep, ipaddr) u_char *ep; - u_long ipaddr; + in_addr_t ipaddr; { - int s; + //int s; struct arpreq request; struct sockaddr_in *sin; @@ -723,7 +725,7 @@ void rarp_reply(ii, ep, ipaddr) struct if_info *ii; struct ether_header *ep; - u_long ipaddr; + in_addr_t ipaddr; { int n; struct ether_arp *ap = (struct ether_arp *) (ep + 1); @@ -755,9 +757,9 @@ rarp_reply(ii, ep, ipaddr) * Get the netmask of an IP address. This routine is used if * SIOCGIFNETMASK doesn't work. */ -u_long +in_addr_t ipaddrtonetmask(addr) - u_long addr; + in_addr_t addr; { if (IN_CLASSA(addr)) return IN_CLASSA_NET; @@ -767,6 +769,7 @@ ipaddrtonetmask(addr) return IN_CLASSC_NET; err(FATAL, "unknown IP address class: %08X", addr); /* NOTREACHED */ + return 0; } #if __STDC__