Skip to content

Commit

Permalink
WARNS=1 clean (netbsd). take hexadecimal/octal as "type" args.
Browse files Browse the repository at this point in the history
don't install it setuid'ed.
  • Loading branch information
itojun committed Nov 24, 2000
1 parent db0280d commit af257e5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
5 changes: 2 additions & 3 deletions kame/kame/icmp6dump/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,19 @@
BINDIR= ${PREFIX}/bin
PROG= icmp6dump

BINOWN = root
BINGRP = bin
BINMODE = 4555
CFLAGS+=-g
.if (${OPSYS} != "NetBSD")
CFLAGS+=-DINET6
.else
CPPFLAGS+=-DINET6
.endif
.if exists(/usr/local/v6/lib/libinet6.a)
LDADD+= -L${.OBJDIR}/../libinet6 -L${.OBJDIR}/../libinet6/obj \
-L/usr/local/v6/lib -linet6
DPADD+= ${.OBJDIR}/../libinet6/libinet6.a \
${.OBJDIR}/../libinet6/obj/libinet6.a \
/usr/local/v6/lib/libinet6.a
.endif

.if (${OPSYS} != "NetBSD")
MAN8= icmp6dump.8
Expand Down
37 changes: 27 additions & 10 deletions kame/kame/icmp6dump/icmp6dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@
#include <arpa/inet.h>

int sock;
void sock_open(void);
void dump(void);
int main __P((int, char **));
void sock_open __P((void));
void dump __P((void));

int
main(argc, argv)
int argc;
char *argv[];
char **argv;
{
fd_set *fdsetp;
size_t nfdset;
Expand All @@ -62,26 +63,38 @@ main(argc, argv)
if (argc == 1)
ICMP6_FILTER_SETPASSALL(&filt);
else {
int type;
unsigned long type;
char *p;

ICMP6_FILTER_SETBLOCKALL(&filt);
argc--; argv++;
while (argc-- > 0) {
type = atoi(*argv);
p = NULL;
type = strtoul(*argv, &p, 0);
if (!**argv || *p) {
errx(1, "invalid argument");
/*NOTREACHED*/
}
if (type < 0 || type > 255) {
errx(1, "invalid argument");
/*NOTREACHED*/
}
ICMP6_FILTER_SETPASS(type, &filt);
argv++;
}
}
if (setsockopt(sock, IPPROTO_ICMPV6, ICMP6_FILTER, &filt,
sizeof(filt)) < 0) {
perror("setsockopt(ICMP6_FILTER)");
exit(-1);
err(1, "setsockopt(ICMP6_FILTER)");
/*NOTREACHED*/
}
#endif /*ICMP6_FILTER*/

nfdset = howmany(sock, NFDBITS);
if ((fdsetp = malloc(nfdset)) == NULL)
if ((fdsetp = malloc(nfdset)) == NULL) {
err(1, "malloc");
/*NOTREACHED*/
}
memset(fdsetp, 0, nfdset);
for (;;) {
FD_SET(sock, fdsetp);
Expand Down Expand Up @@ -231,13 +244,17 @@ sock_open()
{
struct sockaddr_in6 me;

if ((sock = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6)) < 0)
if ((sock = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6)) < 0) {
err(1, "socket");
/*NOTREACHED*/
}

memset(&me, 0, sizeof(struct sockaddr_in6));
me.sin6_len = sizeof(struct sockaddr_in6);
me.sin6_family = AF_INET6;

if (bind(sock, (struct sockaddr *)&me, sizeof(me)) < 0)
if (bind(sock, (struct sockaddr *)&me, sizeof(me)) < 0) {
err(1, "bind");
/*NOTREACHED*/
}
}

0 comments on commit af257e5

Please sign in to comment.