-/* $OpenBSD: rarpd.c,v 1.6 1997/01/15 23:44:15 millert Exp $ */
+/* $OpenBSD: rarpd.c,v 1.7 1997/01/22 09:22:01 deraadt Exp $ */
/* $NetBSD: rarpd.c,v 1.12 1996/03/21 18:28:23 jtc Exp $ */
/*
#endif /* not lint */
#ifndef lint
-static char rcsid[] = "$OpenBSD: rarpd.c,v 1.6 1997/01/15 23:44:15 millert Exp $";
+static char rcsid[] = "$OpenBSD: rarpd.c,v 1.7 1997/01/22 09:22:01 deraadt Exp $";
#endif
void
init_all()
{
- char inbuf[8192];
+ char *inbuf = NULL;
struct ifconf ifc;
struct ifreq *ifr;
- int fd;
+ int fd, inlen = 8192;
int i, len;
if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
/* NOTREACHED */
}
- ifc.ifc_len = sizeof(inbuf);
- ifc.ifc_buf = inbuf;
- if (ioctl(fd, SIOCGIFCONF, (caddr_t)&ifc) < 0 ||
- ifc.ifc_len < sizeof(struct ifreq)) {
- err(FATAL, "init_all: SIOCGIFCONF: %s", strerror(errno));
- /* NOTREACHED */
+ while (1) {
+ ifc.ifc_len = inlen;
+ ifc.ifc_buf = inbuf = realloc(inbuf, inlen);
+ if (inbuf == NULL) {
+ close(fd);
+ err(FATAL, "init_all: malloc: %s", strerror(errno));
+ }
+ if (ioctl(fd, SIOCGIFCONF, (char *)&ifc) < 0) {
+ (void) close(fd);
+ free(inbuf);
+ err(FATAL, "init_all: SIOCGIFCONF: %s", strerror(errno));
+ /* NOTREACHED */
+ }
+ if (ifc.ifc_len + sizeof(*ifr) < inlen)
+ break;
+ inlen *= 2;
}
+
ifr = ifc.ifc_req;
for (i = 0; i < ifc.ifc_len;
i += len, ifr = (struct ifreq *)((caddr_t)ifr + len)) {
len = sizeof(ifr->ifr_name) + ifr->ifr_addr.sa_len;
if (ioctl(fd, SIOCGIFFLAGS, (caddr_t)ifr) < 0) {
+ free(inbuf);
err(FATAL, "init_all: SIOCGIFFLAGS: %s",
strerror(errno));
/* NOTREACHED */
continue;
init_one(ifr->ifr_name);
}
+ free(inbuf);
(void) close(fd);
}
#endif /* not lint */
#ifdef sgi
-#ident "$Revision: 1.4 $"
+#ident "$Revision: 1.5 $"
#endif /* sgi */
#define TSPTYPES
int nflag, iflag;
struct timeval ntime;
struct servent *srvp;
- char buf[BUFSIZ], *cp, *cplim;
+ char *inbuf = NULL, *cp, *cplim;
struct ifconf ifc;
struct ifreq ifreq, ifreqf, *ifr;
register struct netinfo *ntp;
struct nets *nt;
struct sockaddr_in server;
u_short port;
+ int inlen = 8192;
int c;
extern char *optarg;
extern int optind, opterr;
if (0 == (nt->net & 0xff000000))
nt->net <<= 8;
}
- ifc.ifc_len = sizeof(buf);
- ifc.ifc_buf = buf;
- if (ioctl(sock, SIOCGIFCONF, (char *)&ifc) < 0) {
- perror("timed: get interface configuration");
- exit(1);
+ while (1) {
+ ifc.ifc_len = inlen;
+ ifc.ifc_buf = inbuf = realloc(inbuf, inlen);
+ if (inbuf == NULL) {
+ close(sock);
+ return (-1);
+ }
+ if (ioctl(sock, SIOCGIFCONF, (char *)&ifc) < 0) {
+ (void) close(sock);
+ free(inbuf);
+ perror("timed: get interface configuration");
+ exit(1);
+ }
+ if (ifc.ifc_len + sizeof(ifreq) < inlen)
+ break;
+ inlen *= 2;
}
+
ntp = NULL;
#ifdef sgi
#define size(p) (sizeof(*ifr) - sizeof(ifr->ifr_name)) /* XXX hack. kludge */
#else
#define size(p) max((p).sa_len, sizeof(p))
#endif
- cplim = buf + ifc.ifc_len; /*skip over if's with big ifr_addr's */
- for (cp = buf; cp < cplim;
+ cplim = inbuf + ifc.ifc_len; /*skip over if's with big ifr_addr's */
+ for (cp = inbuf; cp < cplim;
cp += sizeof (ifr->ifr_name) + size(ifr->ifr_addr)) {
ifr = (struct ifreq *)cp;
if (ifr->ifr_addr.sa_family != AF_INET)
ntip = ntp;
ntp = NULL;
}
+
if (ntp)
(void) free((char *)ntp);
if (nettab == NULL) {
fprintf(stderr, "timed: no network usable\n");
exit(1);
}
-
+ free(inbuf);
#ifdef sgi
(void)schedctl(RENICE,0,10); /* run fast to get good time */