KNF, bump warns, fix warnings to print the program name.

This commit is contained in:
christos 2014-03-18 00:16:49 +00:00
parent b658434c23
commit 5fe0c59dd8
8 changed files with 147 additions and 175 deletions

View File

@ -1,5 +1,6 @@
# $NetBSD: Makefile,v 1.14 2009/04/22 15:23:08 lukem Exp $
# $NetBSD: Makefile,v 1.15 2014/03/18 00:16:49 christos Exp $
WARNS?=6
USE_FORT?= yes # network client (local server)
PROG= rtsold

View File

@ -1,4 +1,4 @@
/* $NetBSD: dump.c,v 1.9 2009/04/11 07:51:59 lukem Exp $ */
/* $NetBSD: dump.c,v 1.10 2014/03/18 00:16:49 christos Exp $ */
/* $KAME: dump.c,v 1.10 2002/05/31 10:10:03 itojun Exp $ */
/*
@ -48,11 +48,11 @@
static FILE *fp;
extern struct ifinfo *iflist;
static void dump_interface_status __P((void));
static const char *sec2str __P((time_t));
const char *ifstatstr[] = {"IDLE", "DELAY", "PROBE", "DOWN", "TENTATIVE"};
static void dump_interface_status(void);
static const char *sec2str(time_t);
static const char *ifstatstr[] = {
"IDLE", "DELAY", "PROBE", "DOWN", "TENTATIVE"
};
static void
dump_interface_status(void)
@ -115,32 +115,32 @@ sec2str(time_t total)
char *ep = &result[sizeof(result)];
int n;
days = total / 3600 / 24;
hours = (total / 3600) % 24;
mins = (total / 60) % 60;
secs = total % 60;
days = (int)(total / 3600 / 24);
hours = (int)((total / 3600) % 24);
mins = (int)((total / 60) % 60);
secs = (int)(total % 60);
if (days) {
first = 0;
n = snprintf(p, ep - p, "%dd", days);
n = snprintf(p, (size_t)(ep - p), "%dd", days);
if (n < 0 || n >= ep - p)
return "?";
p += n;
}
if (!first || hours) {
first = 0;
n = snprintf(p, ep - p, "%dh", hours);
n = snprintf(p, (size_t)(ep - p), "%dh", hours);
if (n < 0 || n >= ep - p)
return "?";
p += n;
}
if (!first || mins) {
first = 0;
n = snprintf(p, ep - p, "%dm", mins);
n = snprintf(p, (size_t)(ep - p), "%dm", mins);
if (n < 0 || n >= ep - p)
return "?";
p += n;
}
snprintf(p, ep - p, "%ds", secs);
return(result);
snprintf(p, (size_t)(ep - p), "%ds", secs);
return result;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: if.c,v 1.15 2006/03/18 21:41:23 dan Exp $ */
/* $NetBSD: if.c,v 1.16 2014/03/18 00:16:49 christos Exp $ */
/* $KAME: if.c,v 1.18 2002/05/31 10:10:03 itojun Exp $ */
/*
@ -59,18 +59,17 @@
#include "rtsold.h"
extern int rssock;
static int ifsock;
static int get_llflag __P((const char *));
static void get_rtaddrs __P((int, struct sockaddr *, struct sockaddr **));
static int get_llflag(const char *);
static void get_rtaddrs(int, struct sockaddr *, struct sockaddr **);
int
ifinit(void)
{
ifsock = rssock;
return(0);
return 0;
}
int
@ -81,17 +80,17 @@ interface_up(char *name)
strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
if (ioctl(ifsock, SIOCGIFFLAGS, (caddr_t)&ifr) < 0) {
if (ioctl(ifsock, SIOCGIFFLAGS, &ifr) < 0) {
warnmsg(LOG_WARNING, __func__, "ioctl(SIOCGIFFLAGS): %s",
strerror(errno));
return(-1);
return -1;
}
if (!(ifr.ifr_flags & IFF_UP)) {
ifr.ifr_flags |= IFF_UP;
if (ioctl(ifsock, SIOCSIFFLAGS, (caddr_t)&ifr) < 0)
if (ioctl(ifsock, SIOCSIFFLAGS, &ifr) < 0)
warnmsg(LOG_ERR, __func__,
"ioctl(SIOCSIFFLAGS): %s", strerror(errno));
return(-1);
return -1;
}
warnmsg(LOG_DEBUG, __func__, "checking if %s is ready...", name);
@ -105,7 +104,7 @@ interface_up(char *name)
if (!(llflag & IN6_IFF_NOTREADY)) {
warnmsg(LOG_DEBUG, __func__, "%s is ready", name);
return(0);
return 0;
} else {
if (llflag & IN6_IFF_TENTATIVE) {
warnmsg(LOG_DEBUG, __func__, "%s is tentative",
@ -132,7 +131,7 @@ interface_status(struct ifinfo *ifinfo)
if (ioctl(ifsock, SIOCGIFFLAGS, &ifr) < 0) {
warnmsg(LOG_ERR, __func__, "ioctl(SIOCGIFFLAGS) on %s: %s",
ifname, strerror(errno));
return(-1);
return -1;
}
/*
* if one of UP and RUNNING flags is dropped,
@ -148,12 +147,12 @@ interface_status(struct ifinfo *ifinfo)
memset(&ifmr, 0, sizeof(ifmr));
strncpy(ifmr.ifm_name, ifname, sizeof(ifmr.ifm_name));
if (ioctl(ifsock, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0) {
if (ioctl(ifsock, SIOCGIFMEDIA, &ifmr) < 0) {
if (errno != EINVAL) {
warnmsg(LOG_DEBUG, __func__,
"ioctl(SIOCGIFMEDIA) on %s: %s",
ifname, strerror(errno));
return(-1);
return -1;
}
/*
* EINVAL simply means that the interface does not support
@ -177,21 +176,21 @@ interface_status(struct ifinfo *ifinfo)
}
inactive:
return(0);
return 0;
active:
return(1);
return 1;
}
#define ROUNDUP(a, size) \
(((a) & ((size)-1)) ? (1 + ((a) | ((size)-1))) : (a))
#define NEXT_SA(ap) (ap) = (struct sockaddr *) \
((caddr_t)(ap) + ((ap)->sa_len ? ROUNDUP((ap)->sa_len,\
((char *)(ap) + ((ap)->sa_len ? ROUNDUP((ap)->sa_len,\
sizeof(u_long)) : sizeof(u_long)))
#define ROUNDUP8(a) (1 + (((a) - 1) | 7))
int
size_t
lladdropt_length(struct sockaddr_dl *sdl)
{
switch (sdl->sdl_type) {
@ -199,9 +198,9 @@ lladdropt_length(struct sockaddr_dl *sdl)
#ifdef IFT_IEEE80211
case IFT_IEEE80211:
#endif
return(ROUNDUP8(ETHER_ADDR_LEN + 2));
return ROUNDUP8(ETHER_ADDR_LEN + 2);
default:
return(0);
return 0;
}
}
@ -241,12 +240,12 @@ if_nametosdl(char *name)
struct sockaddr_dl *sdl = NULL, *ret_sdl;
if (sysctl(mib, 6, NULL, &len, NULL, 0) < 0)
return(NULL);
return NULL;
if ((buf = malloc(len)) == NULL)
return(NULL);
return NULL;
if (sysctl(mib, 6, buf, &len, NULL, 0) < 0) {
free(buf);
return(NULL);
return NULL;
}
lim = buf + len;
@ -272,14 +271,14 @@ if_nametosdl(char *name)
if (next == lim || sdl == NULL) {
/* search failed */
free(buf);
return(NULL);
return NULL;
}
if ((ret_sdl = malloc(sdl->sdl_len)) == NULL) {
free(buf);
return(NULL);
return NULL;
}
memcpy((caddr_t)ret_sdl, (caddr_t)sdl, sdl->sdl_len);
memcpy(ret_sdl, sdl, sdl->sdl_len);
free(buf);
return(ret_sdl);

View File

@ -1,4 +1,4 @@
/* $NetBSD: probe.c,v 1.11 2010/01/18 04:53:10 christos Exp $ */
/* $NetBSD: probe.c,v 1.12 2014/03/18 00:16:49 christos Exp $ */
/* $KAME: probe.c,v 1.15 2002/05/31 21:22:08 itojun Exp $ */
/*
@ -58,39 +58,39 @@
static struct msghdr sndmhdr;
static struct iovec sndiov[2];
static int probesock;
static void sendprobe __P((struct in6_addr *, struct ifinfo *));
static void sendprobe(struct in6_addr *, struct ifinfo *);
int
probe_init(void)
{
int scmsglen = CMSG_SPACE(sizeof(struct in6_pktinfo)) +
size_t scmsglen = CMSG_SPACE(sizeof(struct in6_pktinfo)) +
CMSG_SPACE(sizeof(int));
static u_char *sndcmsgbuf = NULL;
if (sndcmsgbuf == NULL &&
(sndcmsgbuf = (u_char *)malloc(scmsglen)) == NULL) {
(sndcmsgbuf = malloc(scmsglen)) == NULL) {
warnmsg(LOG_ERR, __func__, "malloc failed");
return(-1);
return -1;
}
if ((probesock = socket(AF_INET6, SOCK_RAW, IPPROTO_NONE)) < 0) {
warnmsg(LOG_ERR, __func__, "socket: %s", strerror(errno));
return(-1);
return -1;
}
/* make the socket send-only */
if (shutdown(probesock, 0)) {
warnmsg(LOG_ERR, __func__, "shutdown: %s", strerror(errno));
return(-1);
return -1;
}
/* initialize msghdr for sending packets */
sndmhdr.msg_namelen = sizeof(struct sockaddr_in6);
sndmhdr.msg_iov = sndiov;
sndmhdr.msg_iovlen = 1;
sndmhdr.msg_control = (caddr_t)sndcmsgbuf;
sndmhdr.msg_controllen = scmsglen;
return(0);
sndmhdr.msg_control = sndcmsgbuf;
sndmhdr.msg_controllen = (socklen_t)scmsglen;
return 0;
}
/*
@ -110,7 +110,7 @@ defrouter_probe(struct ifinfo *ifinfo)
}
memset(&dr, 0, sizeof(dr));
strlcpy(dr.ifname, "lo0", sizeof dr.ifname); /* dummy interface */
if (ioctl(s, SIOCGDRLST_IN6, (caddr_t)&dr) < 0) {
if (ioctl(s, SIOCGDRLST_IN6, &dr) < 0) {
warnmsg(LOG_ERR, __func__, "ioctl(SIOCGDRLST_IN6): %s",
strerror(errno));
goto closeandend;
@ -152,7 +152,7 @@ sendprobe(struct in6_addr *addr, struct ifinfo *ifinfo)
sa6_probe.sin6_addr = *addr;
sa6_probe.sin6_scope_id = ifinfo->linkid;
sndmhdr.msg_name = (caddr_t)&sa6_probe;
sndmhdr.msg_name = &sa6_probe;
sndmhdr.msg_iov[0].iov_base = NULL;
sndmhdr.msg_iov[0].iov_len = 0;

View File

@ -1,4 +1,4 @@
/* $NetBSD: rtsock.c,v 1.6 2009/04/11 07:51:59 lukem Exp $ */
/* $NetBSD: rtsock.c,v 1.7 2014/03/18 00:16:49 christos Exp $ */
/* $KAME: rtsock.c,v 1.4 2001/09/19 06:59:41 sakane Exp $ */
/*
@ -59,12 +59,12 @@
(((a) & ((size)-1)) ? (1 + ((a) | ((size)-1))) : (a))
#define NEXT_SA(ap) (ap) = (struct sockaddr *) \
((caddr_t)(ap) + \
((char *)(ap) + \
((ap)->sa_len ? ROUNDUP((ap)->sa_len, sizeof(u_long)) \
: sizeof(u_long)))
#ifdef RTM_IFANNOUNCE /*NetBSD 1.5 or later*/
static int rtsock_input_ifannounce __P((int, struct rt_msghdr *, char *));
static int rtsock_input_ifannounce(int, struct rt_msghdr *, char *);
#endif
static struct {

View File

@ -1,4 +1,4 @@
/* $NetBSD: rtsol.c,v 1.15 2009/04/11 07:51:59 lukem Exp $ */
/* $NetBSD: rtsol.c,v 1.16 2014/03/18 00:16:49 christos Exp $ */
/* $KAME: rtsol.c,v 1.15 2002/05/31 10:10:03 itojun Exp $ */
/*
@ -76,7 +76,8 @@ int
sockopen(void)
{
static u_char *rcvcmsgbuf = NULL, *sndcmsgbuf = NULL;
int rcvcmsglen, sndcmsglen, on;
size_t rcvcmsglen, sndcmsglen;
int on;
static u_char answer[1500];
struct icmp6_filter filt;
@ -85,12 +86,12 @@ sockopen(void)
if (rcvcmsgbuf == NULL && (rcvcmsgbuf = malloc(rcvcmsglen)) == NULL) {
warnmsg(LOG_ERR, __func__,
"malloc for receive msghdr failed");
return(-1);
return -1;
}
if (sndcmsgbuf == NULL && (sndcmsgbuf = malloc(sndcmsglen)) == NULL) {
warnmsg(LOG_ERR, __func__,
"malloc for send msghdr failed");
return(-1);
return -1;
}
memset(&sin6_allrouters, 0, sizeof(struct sockaddr_in6));
sin6_allrouters.sin6_family = AF_INET6;
@ -99,12 +100,12 @@ sockopen(void)
&sin6_allrouters.sin6_addr.s6_addr) != 1) {
warnmsg(LOG_ERR, __func__, "inet_pton failed for %s",
ALLROUTER);
return(-1);
return -1;
}
if ((rssock = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6)) < 0) {
warnmsg(LOG_ERR, __func__, "socket: %s", strerror(errno));
return(-1);
return -1;
}
/* specify to tell receiving interface */
@ -150,27 +151,27 @@ sockopen(void)
sizeof(filt)) == -1) {
warnmsg(LOG_ERR, __func__, "setsockopt(ICMP6_FILTER): %s",
strerror(errno));
return(-1);
return -1;
}
/* initialize msghdr for receiving packets */
rcviov[0].iov_base = (caddr_t)answer;
rcviov[0].iov_base = answer;
rcviov[0].iov_len = sizeof(answer);
rcvmhdr.msg_name = (caddr_t)&from;
rcvmhdr.msg_name = &from;
rcvmhdr.msg_namelen = sizeof(from);
rcvmhdr.msg_iov = rcviov;
rcvmhdr.msg_iovlen = 1;
rcvmhdr.msg_control = (caddr_t) rcvcmsgbuf;
rcvmhdr.msg_controllen = rcvcmsglen;
rcvmhdr.msg_control = rcvcmsgbuf;
rcvmhdr.msg_controllen = (socklen_t)rcvcmsglen;
/* initialize msghdr for sending packets */
sndmhdr.msg_namelen = sizeof(struct sockaddr_in6);
sndmhdr.msg_iov = sndiov;
sndmhdr.msg_iovlen = 1;
sndmhdr.msg_control = (caddr_t)sndcmsgbuf;
sndmhdr.msg_controllen = sndcmsglen;
sndmhdr.msg_control = sndcmsgbuf;
sndmhdr.msg_controllen = (socklen_t)sndcmsglen;
return(rssock);
return rssock;
}
void
@ -185,8 +186,8 @@ sendpacket(struct ifinfo *ifinfo)
dst = sin6_allrouters;
dst.sin6_scope_id = ifinfo->linkid;
sndmhdr.msg_name = (caddr_t)&dst;
sndmhdr.msg_iov[0].iov_base = (caddr_t)ifinfo->rs_data;
sndmhdr.msg_name = &dst;
sndmhdr.msg_iov[0].iov_base = ifinfo->rs_data;
sndmhdr.msg_iov[0].iov_len = ifinfo->rs_datalen;
cm = CMSG_FIRSTHDR(&sndmhdr);
@ -229,8 +230,9 @@ void
rtsol_input(int s)
{
char ntopbuf[INET6_ADDRSTRLEN], ifnamebuf[IFNAMSIZ];
int ifindex = 0, *hlimp = NULL;
int *hlimp = NULL;
ssize_t i;
size_t ifindex = 0;
struct in6_pktinfo *pi = NULL;
struct ifinfo *ifi = NULL;
struct icmp6_hdr *icp;

View File

@ -1,4 +1,4 @@
/* $NetBSD: rtsold.c,v 1.37 2013/10/19 17:16:38 christos Exp $ */
/* $NetBSD: rtsold.c,v 1.38 2014/03/18 00:16:49 christos Exp $ */
/* $KAME: rtsold.c,v 1.77 2004/01/03 01:35:13 itojun Exp $ */
/*
@ -56,31 +56,11 @@
#include "rtsold.h"
#ifdef __bsdi__
#define timeradd(tvp, uvp, vvp) \
do { \
(vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \
(vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \
if ((vvp)->tv_usec >= 1000000) { \
(vvp)->tv_sec++; \
(vvp)->tv_usec -= 1000000; \
} \
} while (/* CONSTCOND */ 0)
#define timersub(tvp, uvp, vvp) \
do { \
(vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \
(vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \
if ((vvp)->tv_usec < 0) { \
(vvp)->tv_sec--; \
(vvp)->tv_usec += 1000000; \
} \
} while (/* CONSTCOND */ 0)
#endif
struct ifinfo *iflist;
struct timeval tm_max = {0x7fffffff, 0x7fffffff};
static int log_upto = 999;
static int fflag = 0;
static int isdaemon = 0;
int aflag = 0;
int dflag = 0;
@ -96,8 +76,6 @@ int dflag = 0;
*/
#define PROBE_INTERVAL 60
int main __P((int, char **));
/* static variables and functions */
static int mobile_node = 0;
#ifndef SMALL
@ -106,22 +84,22 @@ static const char *dumpfilename = "/var/run/rtsold.dump"; /* XXX: should be conf
#endif
#if 0
static int ifreconfig __P((char *));
static int ifreconfig(char *);
#endif
static int make_packet __P((struct ifinfo *));
static struct timeval *rtsol_check_timer __P((void));
static int make_packet(struct ifinfo *);
static struct timeval *rtsol_check_timer(void);
#ifndef SMALL
static void rtsold_set_dump_file __P((int));
static void rtsold_set_dump_file(int);
#endif
__dead static void usage(char *);
__dead static void usage(void);
int
main(int argc, char **argv)
{
int s, ch, once = 0;
struct timeval *timeout;
char *argv0;
const char *ident;
const char *opts;
struct pollfd set[2];
#ifdef USE_RTSOCK
@ -131,10 +109,11 @@ main(int argc, char **argv)
/*
* Initialization
*/
argv0 = argv[0];
ident = getprogname();
isdaemon = ident[strlen(ident) - 1] == 'd';
/* get option */
if (argv0 && argv0[strlen(argv0) - 1] != 'd') {
if (!isdaemon) {
fflag = 1;
once = 1;
opts = "adD";
@ -162,7 +141,7 @@ main(int argc, char **argv)
once = 1;
break;
default:
usage(argv0);
usage();
/*NOTREACHED*/
}
}
@ -170,7 +149,7 @@ main(int argc, char **argv)
argv += optind;
if ((!aflag && argc == 0) || (aflag && argc != 0)) {
usage(argv0);
usage();
/*NOTREACHED*/
}
@ -178,13 +157,6 @@ main(int argc, char **argv)
if (dflag == 0)
log_upto = LOG_NOTICE;
if (!fflag) {
char *ident;
ident = strrchr(argv0, '/');
if (!ident)
ident = argv0;
else
ident++;
openlog(ident, LOG_NDELAY|LOG_PID, LOG_DAEMON);
if (log_upto >= 0)
setlogmask(LOG_UPTO(log_upto));
@ -293,7 +265,9 @@ main(int argc, char **argv)
if (ifi == NULL)
break;
}
e = poll(set, 2, timeout ? (timeout->tv_sec * 1000 + timeout->tv_usec / 1000) : INFTIM);
e = poll(set, 2, (int)(timeout ?
(timeout->tv_sec * 1000 + timeout->tv_usec / 1000) :
INFTIM));
if (e < 1) {
if (e < 0 && errno != EINTR) {
warnmsg(LOG_ERR, __func__, "poll: %s",
@ -325,19 +299,19 @@ ifconfig(char *ifname)
if ((sdl = if_nametosdl(ifname)) == NULL) {
warnmsg(LOG_ERR, __func__,
"failed to get link layer information for %s", ifname);
return(-1);
return -1;
}
if (find_ifinfo(sdl->sdl_index)) {
warnmsg(LOG_ERR, __func__,
"interface %s was already configured", ifname);
free(sdl);
return(-1);
return -1;
}
if ((ifinfo = malloc(sizeof(*ifinfo))) == NULL) {
warnmsg(LOG_ERR, __func__, "memory allocation failed");
free(sdl);
return(-1);
return -1;
}
memset(ifinfo, 0, sizeof(*ifinfo));
ifinfo->sdl = sdl;
@ -387,12 +361,12 @@ ifconfig(char *ifname)
ifinfo->next = iflist;
iflist = ifinfo;
return(0);
return 0;
bad:
free(ifinfo->sdl);
free(ifinfo);
return(-1);
return -1;
}
void
@ -438,20 +412,20 @@ ifreconfig(char *ifname)
#endif
struct ifinfo *
find_ifinfo(int ifindex)
find_ifinfo(size_t ifindex)
{
struct ifinfo *ifi;
for (ifi = iflist; ifi; ifi = ifi->next)
if (ifi->sdl->sdl_index == ifindex)
return(ifi);
return(NULL);
return ifi;
return NULL;
}
static int
make_packet(struct ifinfo *ifinfo)
{
size_t packlen = sizeof(struct nd_router_solicit), lladdroptlen = 0;
size_t packlen = sizeof(struct nd_router_solicit), lladdroptlen;
struct nd_router_solicit *rs;
u_char *buf;
@ -467,7 +441,7 @@ make_packet(struct ifinfo *ifinfo)
if ((buf = malloc(packlen)) == NULL) {
warnmsg(LOG_ERR, __func__,
"memory allocation failed for %s", ifinfo->ifname);
return(-1);
return -1;
}
ifinfo->rs_data = buf;
@ -483,7 +457,7 @@ make_packet(struct ifinfo *ifinfo)
if (lladdroptlen)
lladdropt_fill(ifinfo->sdl, (struct nd_opt_hdr *)buf);
return(0);
return 0;
}
static struct timeval *
@ -534,7 +508,7 @@ rtsol_check_timer(void)
probe = 1;
ifinfo->state = IFS_DELAY;
} else if (ifinfo->probeinterval &&
(ifinfo->probetimer -=
(ifinfo->probetimer -= (int)
ifinfo->timer.tv_sec) <= 0) {
/* probe timer expired */
ifinfo->probetimer =
@ -572,7 +546,7 @@ rtsol_check_timer(void)
if (timercmp(&rtsol_timer, &tm_max, ==)) {
warnmsg(LOG_DEBUG, __func__, "there is no timer");
return(NULL);
return NULL;
} else if (timercmp(&rtsol_timer, &now, <))
/* this may occur when the interval is too small */
returnval.tv_sec = returnval.tv_usec = 0;
@ -583,7 +557,7 @@ rtsol_check_timer(void)
warnmsg(LOG_DEBUG, __func__, "New timer is %ld:%08ld",
(long)returnval.tv_sec, (long)returnval.tv_usec);
return(&returnval);
return &returnval;
}
void
@ -615,7 +589,7 @@ rtsol_timer_update(struct ifinfo *ifinfo)
case IFS_DELAY:
interval = arc4random() % (MAX_RTR_SOLICITATION_DELAY * MILLION);
ifinfo->timer.tv_sec = interval / MILLION;
ifinfo->timer.tv_usec = interval % MILLION;
ifinfo->timer.tv_usec = (suseconds_t)(interval % MILLION);
break;
case IFS_PROBE:
if (ifinfo->probes < MAX_RTR_SOLICITATIONS)
@ -669,15 +643,11 @@ rtsold_set_dump_file(int sig)
#endif
static void
usage(char *progname)
usage(void)
{
if (progname && progname[strlen(progname) - 1] != 'd') {
fprintf(stderr, "usage: rtsol [-Dd] interface ...\n");
fprintf(stderr, "usage: rtsol [-Dd] -a\n");
} else {
fprintf(stderr, "usage: rtsold [-1Ddfm] interface ...\n");
fprintf(stderr, "usage: rtsold [-1Ddfm] -a\n");
}
const char *opts = isdaemon ? "-1Ddfm" : "Dd";
fprintf(stderr, "Usage: %s [%s] interface ...\n", getprogname(), opts);
fprintf(stderr, "\t%s [%s] -a\n", getprogname(), opts);
exit(1);
}
@ -685,18 +655,15 @@ void
warnmsg(int priority, const char *func, const char *msg, ...)
{
va_list ap;
char buf[BUFSIZ];
va_start(ap, msg);
if (fflag) {
if (priority <= log_upto) {
(void)vfprintf(stderr, msg, ap);
(void)fprintf(stderr, "\n");
}
if (priority <= log_upto)
vwarnx(msg, ap);
} else {
char buf[BUFSIZ];
snprintf(buf, sizeof(buf), "<%s> %s", func, msg);
msg = buf;
vsyslog(priority, msg, ap);
vsyslog(priority, buf, ap);
}
va_end(ap);
}
@ -708,9 +675,10 @@ char **
autoifprobe(void)
{
static char **argv = NULL;
static int n = 0;
static size_t n = 0;
char **a;
int i, found;
size_t i;
int found;
struct ifaddrs *ifap, *ifa;
/* initialize */
@ -753,20 +721,20 @@ autoifprobe(void)
if (n != 0 && dflag > 1)
warnx("multiple interfaces found");
a = (char **)realloc(argv, (n + 1) * sizeof(char **));
a = realloc(argv, (n + 1) * sizeof(char **));
if (a == NULL)
err(1, "realloc");
err(EXIT_FAILURE, "realloc");
argv = a;
argv[n] = strdup(ifa->ifa_name);
if (!argv[n])
err(1, "strdup");
err(EXIT_FAILURE, "strdup");
n++;
}
if (n) {
a = (char **)realloc(argv, (n + 1) * sizeof(char **));
a = realloc(argv, (n + 1) * sizeof(char **));
if (a == NULL)
err(1, "realloc");
err(EXIT_FAILURE, "realloc");
argv = a;
argv[n] = NULL;

View File

@ -1,4 +1,4 @@
/* $NetBSD: rtsold.h,v 1.10 2011/10/17 16:31:14 mbalmer Exp $ */
/* $NetBSD: rtsold.h,v 1.11 2014/03/18 00:16:49 christos Exp $ */
/* $KAME: rtsold.h,v 1.14 2002/05/31 10:10:03 itojun Exp $ */
/*
@ -64,35 +64,37 @@ struct ifinfo {
extern struct timeval tm_max;
extern int dflag;
extern int aflag;
extern int ifconfig __P((char *));
extern void iflist_init __P((void));
struct ifinfo *find_ifinfo __P((int));
void rtsol_timer_update __P((struct ifinfo *));
extern void warnmsg __P((int, const char *, const char *, ...))
__attribute__((__format__(__printf__, 3, 4)));
extern char **autoifprobe __P((void));
extern struct ifinfo *iflist;
extern int rssock;
int ifconfig(char *);
void iflist_init(void);
struct ifinfo *find_ifinfo(size_t);
void rtsol_timer_update(struct ifinfo *);
void warnmsg(int, const char *, const char *, ...) __printflike(3, 4);
char **autoifprobe(void);
/* if.c */
extern int ifinit __P((void));
extern int interface_up __P((char *));
extern int interface_status __P((struct ifinfo *));
extern int lladdropt_length __P((struct sockaddr_dl *));
extern void lladdropt_fill __P((struct sockaddr_dl *, struct nd_opt_hdr *));
extern struct sockaddr_dl *if_nametosdl __P((char *));
extern int getinet6sysctl __P((int));
int ifinit(void);
int interface_up(char *);
int interface_status(struct ifinfo *);
size_t lladdropt_length(struct sockaddr_dl *);
void lladdropt_fill(struct sockaddr_dl *, struct nd_opt_hdr *);
struct sockaddr_dl *if_nametosdl(char *);
int getinet6sysctl(int);
/* rtsol.c */
extern int sockopen __P((void));
extern void sendpacket __P((struct ifinfo *));
extern void rtsol_input __P((int));
int sockopen(void);
void sendpacket(struct ifinfo *);
void rtsol_input(int);
/* probe.c */
extern int probe_init __P((void));
extern void defrouter_probe __P((struct ifinfo *));
int probe_init(void);
void defrouter_probe(struct ifinfo *);
/* dump.c */
extern void rtsold_dump_file __P((const char *));
void rtsold_dump_file(const char *);
/* rtsock.c */
extern int rtsock_open __P((void));
extern int rtsock_input __P((int));
int rtsock_open(void);
int rtsock_input(int);