Use err(3). Change exit(-1). Remove unused #include.
This commit is contained in:
parent
8659113475
commit
69036300b2
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=32502
@ -31,30 +31,34 @@
|
|||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
char copyright[] =
|
#ifndef lint
|
||||||
|
static const char copyright[] =
|
||||||
"@(#) Copyright (c) 1982, 1986, 1993\n\
|
"@(#) Copyright (c) 1982, 1986, 1993\n\
|
||||||
The Regents of the University of California. All rights reserved.\n";
|
The Regents of the University of California. All rights reserved.\n";
|
||||||
|
#endif /* not lint */
|
||||||
|
|
||||||
#if !defined(lint) && !defined(sgi) && !defined(__NetBSD__)
|
#ifndef lint
|
||||||
|
#if 0
|
||||||
static char sccsid[] = "@(#)query.c 8.1 (Berkeley) 6/5/93";
|
static char sccsid[] = "@(#)query.c 8.1 (Berkeley) 6/5/93";
|
||||||
#elif defined(__NetBSD__)
|
|
||||||
static char rcsid[] = "$NetBSD$";
|
|
||||||
#endif
|
#endif
|
||||||
|
static const char rcsid[] =
|
||||||
|
"$Id$";
|
||||||
|
#endif /* not lint */
|
||||||
|
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/protosw.h>
|
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#define RIPVERSION RIPv2
|
#define RIPVERSION RIPv2
|
||||||
#include <protocols/routed.h>
|
#include <protocols/routed.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <netdb.h>
|
#include <err.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <unistd.h>
|
#include <netdb.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
#ifdef sgi
|
#ifdef sgi
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
#include <bstring.h>
|
#include <bstring.h>
|
||||||
@ -245,10 +249,8 @@ usage: fprintf(stderr, "%s\n%s\n",
|
|||||||
}
|
}
|
||||||
|
|
||||||
s = socket(AF_INET, SOCK_DGRAM, 0);
|
s = socket(AF_INET, SOCK_DGRAM, 0);
|
||||||
if (s < 0) {
|
if (s < 0)
|
||||||
perror("socket");
|
err(2, "socket");
|
||||||
exit(2);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* be prepared to receive a lot of routes */
|
/* be prepared to receive a lot of routes */
|
||||||
for (bsize = 127*1024; ; bsize -= 1024) {
|
for (bsize = 127*1024; ; bsize -= 1024) {
|
||||||
@ -256,7 +258,7 @@ usage: fprintf(stderr, "%s\n%s\n",
|
|||||||
&bsize, sizeof(bsize)) == 0)
|
&bsize, sizeof(bsize)) == 0)
|
||||||
break;
|
break;
|
||||||
if (bsize <= 4*1024) {
|
if (bsize <= 4*1024) {
|
||||||
perror("setsockopt SO_RCVBUF");
|
warn("setsockopt SO_RCVBUF");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -277,10 +279,8 @@ trace_loop(char *argv[])
|
|||||||
struct sockaddr_in myaddr;
|
struct sockaddr_in myaddr;
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
if (geteuid() != 0) {
|
if (geteuid() != 0)
|
||||||
(void)fprintf(stderr, "-t requires UID 0\n");
|
errx(1, "-t requires UID 0");
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ripv2) {
|
if (ripv2) {
|
||||||
OMSG.rip_vers = RIPv2;
|
OMSG.rip_vers = RIPv2;
|
||||||
@ -295,11 +295,8 @@ trace_loop(char *argv[])
|
|||||||
#endif
|
#endif
|
||||||
myaddr.sin_port = htons(IPPORT_RESERVED-1);
|
myaddr.sin_port = htons(IPPORT_RESERVED-1);
|
||||||
while (bind(s, (struct sockaddr *)&myaddr, sizeof(myaddr)) < 0) {
|
while (bind(s, (struct sockaddr *)&myaddr, sizeof(myaddr)) < 0) {
|
||||||
if (errno != EADDRINUSE
|
if (errno != EADDRINUSE || myaddr.sin_port == 0)
|
||||||
|| myaddr.sin_port == 0) {
|
err(2, "bind");
|
||||||
perror("bind");
|
|
||||||
exit(2);
|
|
||||||
}
|
|
||||||
myaddr.sin_port = htons(ntohs(myaddr.sin_port)-1);
|
myaddr.sin_port = htons(ntohs(myaddr.sin_port)-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -370,7 +367,7 @@ query_loop(char *argv[], int argc)
|
|||||||
seen = 0;
|
seen = 0;
|
||||||
while (0 > out(*argv++)) {
|
while (0 > out(*argv++)) {
|
||||||
if (*argv == 0)
|
if (*argv == 0)
|
||||||
exit(-1);
|
exit(1);
|
||||||
answered++;
|
answered++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -385,10 +382,8 @@ query_loop(char *argv[], int argc)
|
|||||||
cc = recvfrom(s, imsg_buf.packet,
|
cc = recvfrom(s, imsg_buf.packet,
|
||||||
sizeof(imsg_buf.packet), 0,
|
sizeof(imsg_buf.packet), 0,
|
||||||
(struct sockaddr *)&from, &fromlen);
|
(struct sockaddr *)&from, &fromlen);
|
||||||
if (cc < 0) {
|
if (cc < 0)
|
||||||
perror("recvfrom");
|
err(1, "recvfrom");
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
/* count the distinct responding hosts.
|
/* count the distinct responding hosts.
|
||||||
* You cannot match responding hosts with
|
* You cannot match responding hosts with
|
||||||
* addresses to which queries were transmitted,
|
* addresses to which queries were transmitted,
|
||||||
@ -412,10 +407,9 @@ query_loop(char *argv[], int argc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (cc < 0) {
|
if (cc < 0) {
|
||||||
if ( errno == EINTR)
|
if (errno == EINTR)
|
||||||
continue;
|
continue;
|
||||||
perror("select");
|
err(1, "select");
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* After a pause in responses, probe another host.
|
/* After a pause in responses, probe another host.
|
||||||
@ -432,10 +426,8 @@ query_loop(char *argv[], int argc)
|
|||||||
|
|
||||||
/* or until we have waited a long time
|
/* or until we have waited a long time
|
||||||
*/
|
*/
|
||||||
if (gettimeofday(&now, 0) < 0) {
|
if (gettimeofday(&now, 0) < 0)
|
||||||
perror("gettimeofday(now)");
|
err(1, "gettimeofday(now)");
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
if (sent.tv_sec + wtime <= now.tv_sec)
|
if (sent.tv_sec + wtime <= now.tv_sec)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -454,7 +446,7 @@ out(char *host)
|
|||||||
struct hostent *hp;
|
struct hostent *hp;
|
||||||
|
|
||||||
if (gettimeofday(&sent, 0) < 0) {
|
if (gettimeofday(&sent, 0) < 0) {
|
||||||
perror("gettimeofday(sent)");
|
warn("gettimeofday(sent)");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -475,7 +467,7 @@ out(char *host)
|
|||||||
|
|
||||||
if (sendto(s, &omsg_buf, omsg_len, 0,
|
if (sendto(s, &omsg_buf, omsg_len, 0,
|
||||||
(struct sockaddr *)&router, sizeof(router)) < 0) {
|
(struct sockaddr *)&router, sizeof(router)) < 0) {
|
||||||
perror(host);
|
warn("%s", host);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user