routed(8): use NULL instead of zero for pointers.

This commit is contained in:
Pedro F. Giffuni 2016-05-14 22:40:08 +00:00
parent 19ffd5ecda
commit 562c5a82cb
10 changed files with 230 additions and 227 deletions

View File

@ -110,14 +110,14 @@ if_link(struct interface *ifp)
hifp = AHASH(ifp->int_addr);
ifp->int_ahash_prev = hifp;
if ((ifp->int_ahash = *hifp) != 0)
if ((ifp->int_ahash = *hifp) != NULL)
(*hifp)->int_ahash_prev = &ifp->int_ahash;
*hifp = ifp;
if (ifp->int_if_flags & IFF_BROADCAST) {
hifp = BHASH(ifp->int_brdaddr);
ifp->int_bhash_prev = hifp;
if ((ifp->int_bhash = *hifp) != 0)
if ((ifp->int_bhash = *hifp) != NULL)
(*hifp)->int_bhash_prev = &ifp->int_bhash;
*hifp = ifp;
}
@ -128,11 +128,11 @@ if_link(struct interface *ifp)
hifp = nhash(ifp->int_name);
if (ifp->int_state & IS_ALIAS) {
/* put aliases on the end of the hash chain */
while (*hifp != 0)
while (*hifp != NULL)
hifp = &(*hifp)->int_nhash;
}
ifp->int_nhash_prev = hifp;
if ((ifp->int_nhash = *hifp) != 0)
if ((ifp->int_nhash = *hifp) != NULL)
(*hifp)->int_nhash_prev = &ifp->int_nhash;
*hifp = ifp;
}
@ -145,7 +145,7 @@ ifwithaddr(naddr addr,
int bcast, /* notice IFF_BROADCAST address */
int remote) /* include IS_REMOTE interfaces */
{
struct interface *ifp, *possible = 0;
struct interface *ifp, *possible = NULL;
remote = (remote == 0) ? IS_REMOTE : 0;
@ -185,7 +185,7 @@ ifwithname(char *name, /* "ec0" or whatever */
struct interface *ifp;
for (;;) {
for (ifp = *nhash(name); ifp != 0; ifp = ifp->int_nhash) {
for (ifp = *nhash(name); ifp != NULL; ifp = ifp->int_nhash) {
/* If the network address is not specified,
* ignore any alias interfaces. Otherwise, look
* for the interface with the target name and address.
@ -239,7 +239,7 @@ iflookup(naddr addr)
struct interface *ifp, *maybe;
int once = 0;
maybe = 0;
maybe = NULL;
for (;;) {
LIST_FOREACH(ifp, &ifnet, int_list) {
if (ifp->int_if_flags & IFF_POINTOPOINT) {
@ -255,13 +255,13 @@ iflookup(naddr addr)
/* Look for the longest approximate match.
*/
if (on_net(addr, ifp->int_net, ifp->int_mask)
&& (maybe == 0
&& (maybe == NULL
|| ifp->int_mask > maybe->int_mask))
maybe = ifp;
}
}
if (maybe != 0 || once || IF_RESCAN_DELAY())
if (maybe != NULL || once || IF_RESCAN_DELAY())
return maybe;
once = 1;
@ -304,7 +304,7 @@ ripv1_mask_net(naddr addr, /* in network byte order */
if (addr == 0) /* default always has 0 mask */
return mask;
if (ifp != 0 && ifp->int_ripv1_mask != HOST_MASK) {
if (ifp != NULL && ifp->int_ripv1_mask != HOST_MASK) {
/* If the target network is that of the associated interface
* on which it arrived, then use the netmask of the interface.
*/
@ -329,7 +329,7 @@ ripv1_mask_net(naddr addr, /* in network byte order */
/* check special definitions */
if (mask == 0) {
for (r1p = r1nets; r1p != 0; r1p = r1p->r1net_next) {
for (r1p = r1nets; r1p != NULL; r1p = r1p->r1net_next) {
if (on_net(addr, r1p->r1net_net, r1p->r1net_match)
&& r1p->r1net_mask > mask)
mask = r1p->r1net_mask;
@ -425,7 +425,7 @@ check_remote(struct interface *ifp)
return 1;
rt = rtfind(ifp->int_addr);
if (rt != 0
if (rt != NULL
&& rt->rt_ifp != 0
&&on_net(ifp->int_addr,
rt->rt_ifp->int_net, rt->rt_ifp->int_mask))
@ -497,7 +497,7 @@ ifdel(struct interface *ifp)
&& !TRACEACTIONS)
LOGERR("setsockopt(MCAST_LEAVE_GROUP RIP)");
if (rip_sock_mcast == ifp)
rip_sock_mcast = 0;
rip_sock_mcast = NULL;
}
if (ifp->int_rip_sock >= 0) {
(void)close(ifp->int_rip_sock);
@ -906,7 +906,7 @@ ifinit(void)
ifp = ifwithname(ifs.int_name, ((ifs.int_state & IS_ALIAS)
? ifs.int_addr
: 0));
if (ifp != 0) {
if (ifp != NULL) {
ifp->int_state |= IS_CHECKED;
if (0 != ((ifp->int_if_flags ^ ifs.int_if_flags)
@ -927,11 +927,11 @@ ifinit(void)
trace_act("interface %s has changed",
ifp->int_name);
ifdel(ifp);
ifp = 0;
ifp = NULL;
}
}
if (ifp != 0) {
if (ifp != NULL) {
/* The primary representative of an alias worries
* about how things are working.
*/
@ -1051,7 +1051,7 @@ ifinit(void)
*/
ifp = check_dup(ifs.int_addr,ifs.int_dstaddr,ifs.int_mask,
ifs.int_if_flags);
if (ifp != 0) {
if (ifp != NULL) {
/* Ignore duplicates of itself, caused by having
* IP aliases on the same network.
*/
@ -1154,15 +1154,15 @@ ifinit(void)
if (advertise_mhome
|| (tot_interfaces > 1
&& mhome
&& (ifp = ifwithaddr(myaddr, 0, 0)) != 0
&& (ifp = ifwithaddr(myaddr, 0, 0)) != NULL
&& foundloopback)) {
advertise_mhome = 1;
rt = rtget(myaddr, HOST_MASK);
if (rt != 0) {
if (rt != NULL) {
if (rt->rt_ifp != ifp
|| rt->rt_router != loopaddr) {
rtdelete(rt);
rt = 0;
rt = NULL;
} else {
loop_rts.rts_ifp = ifp;
loop_rts.rts_metric = 0;
@ -1171,7 +1171,7 @@ ifinit(void)
&loop_rts, 0);
}
}
if (rt == 0) {
if (rt == NULL) {
loop_rts.rts_ifp = ifp;
loop_rts.rts_metric = 0;
rtadd(myaddr, HOST_MASK, RS_MHOME, &loop_rts);
@ -1220,11 +1220,11 @@ ifinit(void)
*/
del_static(ifp->int_addr, HOST_MASK, 0, 0);
rt = rtget(ifp->int_addr, HOST_MASK);
if (rt != 0 && rt->rt_router != loopaddr) {
if (rt != NULL && rt->rt_router != loopaddr) {
rtdelete(rt);
rt = 0;
rt = NULL;
}
if (rt != 0) {
if (rt != NULL) {
if (!(rt->rt_state & RS_LOCAL)
|| rt->rt_metric > ifp->int_metric) {
ifp1 = ifp;
@ -1247,16 +1247,17 @@ ifinit(void)
}
/* add the authority routes */
for (intnetp = intnets; intnetp!=0; intnetp = intnetp->intnet_next) {
for (intnetp = intnets; intnetp != NULL;
intnetp = intnetp->intnet_next) {
rt = rtget(intnetp->intnet_addr, intnetp->intnet_mask);
if (rt != 0
if (rt != NULL
&& !(rt->rt_state & RS_NO_NET_SYN)
&& !(rt->rt_state & RS_NET_INT)) {
rtdelete(rt);
rt = 0;
rt = NULL;
}
if (rt == 0) {
loop_rts.rts_ifp = 0;
if (rt == NULL) {
loop_rts.rts_ifp = NULL;
loop_rts.rts_metric = intnetp->intnet_metric-1;
rtadd(intnetp->intnet_addr, intnetp->intnet_mask,
RS_NET_SYN | RS_NET_INT, &loop_rts);
@ -1281,14 +1282,14 @@ check_net_syn(struct interface *ifp)
if (have_ripv1_out || have_ripv1_in) {
ifp->int_state |= IS_NEED_NET_SYN;
rt = rtget(ifp->int_std_addr, ifp->int_std_mask);
if (rt != 0
if (rt != NULL
&& 0 == (rt->rt_state & RS_NO_NET_SYN)
&& (!(rt->rt_state & RS_NET_SYN)
|| rt->rt_metric > ifp->int_metric)) {
rtdelete(rt);
rt = 0;
rt = NULL;
}
if (rt == 0) {
if (rt == NULL) {
new.rts_ifp = ifp;
new.rts_gate = ifp->int_addr;
new.rts_router = ifp->int_addr;
@ -1302,7 +1303,7 @@ check_net_syn(struct interface *ifp)
rt = rtget(ifp->int_std_addr,
ifp->int_std_mask);
if (rt != 0
if (rt != NULL
&& (rt->rt_state & RS_NET_SYN)
&& rt->rt_ifp == ifp)
rtbad_sub(rt);
@ -1357,21 +1358,21 @@ addrouteforif(struct interface *ifp)
*/
del_static(dst, ifp->int_mask, 0, 0);
rt = rtget(dst, ifp->int_mask);
if (rt != 0) {
if (rt != NULL) {
if ((rt->rt_ifp != ifp
|| rt->rt_router != ifp->int_addr)
&& (!(ifp->int_state & IS_DUP)
|| rt->rt_ifp == 0
|| (rt->rt_ifp->int_state & IS_BROKE))) {
rtdelete(rt);
rt = 0;
rt = NULL;
} else {
rtchange(rt, ((rt->rt_state | RS_IF)
& ~(RS_NET_SYN | RS_LOCAL)),
&new, 0);
}
}
if (rt == 0) {
if (rt == NULL) {
if (ifp->int_transitions++ > 0)
trace_act("re-install interface %s",
ifp->int_name);

View File

@ -100,9 +100,9 @@ read_rip(int sock,
if (aifp->int_addr == from.sin_addr.s_addr)
break;
}
if (aifp == 0) {
if (aifp == NULL) {
aifp = ifwithname(inbuf.ifname, 0);
if (aifp == 0) {
if (aifp == NULL) {
msglim(&bad_name, from.sin_addr.s_addr,
"impossible interface name %.*s",
IFNAMSIZ, inbuf.ifname);
@ -115,13 +115,13 @@ read_rip(int sock,
/* If it came via the wrong interface, do not
* trust it.
*/
aifp = 0;
aifp = NULL;
}
}
#else
aifp = iflookup(from.sin_addr.s_addr);
#endif
if (sifp == 0)
if (sifp == NULL)
sifp = aifp;
input(&from, sifp, aifp, &inbuf.pbuf.rip, cc);
@ -148,19 +148,19 @@ input(struct sockaddr_in *from, /* received from this IP address */
struct interface *ifp1;
naddr gate, mask, v1_mask, dst, ddst_h = 0;
struct auth *ap;
struct tgate *tg = 0;
struct tgate *tg = NULL;
struct tgate_net *tn;
int i, j;
/* Notice when we hear from a remote gateway
*/
if (aifp != 0
if (aifp != NULL
&& (aifp->int_state & IS_REMOTE))
aifp->int_act_time = now.tv_sec;
trace_rip("Recv", "from", from, sifp, rip, cc);
if (sifp == 0) {
if (sifp == NULL) {
trace_pkt(" discard a request from an indirect router"
" (possibly an attack)");
return;
@ -206,7 +206,7 @@ input(struct sockaddr_in *from, /* received from this IP address */
case RIPCMD_REQUEST:
/* For mere requests, be a little sloppy about the source
*/
if (aifp == 0)
if (aifp == NULL)
aifp = sifp;
/* Are we talking to ourself or a remote gateway?
@ -233,7 +233,7 @@ input(struct sockaddr_in *from, /* received from this IP address */
* the router does not depend on us.
*/
if (rip_sock < 0
|| (aifp != 0
|| (aifp != NULL
&& IS_RIP_OUT_OFF(aifp->int_state))) {
trace_pkt(" discard request while RIP off");
return;
@ -263,20 +263,20 @@ input(struct sockaddr_in *from, /* received from this IP address */
}
if (rip->rip_vers == RIPv2
&& (aifp == 0 || (aifp->int_state & IS_NO_RIPV1_OUT))) {
&& (aifp == NULL || (aifp->int_state & IS_NO_RIPV1_OUT))) {
v12buf.buf->rip_vers = RIPv2;
/* If we have a secret but it is a cleartext secret,
* do not disclose our secret unless the other guy
* already knows it.
*/
ap = find_auth(aifp);
if (ap != 0 && ap->type == RIP_AUTH_PW
if (ap != NULL && ap->type == RIP_AUTH_PW
&& n->n_family == RIP_AF_AUTH
&& !ck_passwd(aifp,rip,lim,FROM_NADDR,&use_auth))
ap = 0;
ap = NULL;
} else {
v12buf.buf->rip_vers = RIPv1;
ap = 0;
ap = NULL;
}
clr_ws_buf(&v12buf, ap);
@ -308,7 +308,8 @@ input(struct sockaddr_in *from, /* received from this IP address */
if ((aifp != NULL && insecure > 0) ||
(aifp == NULL && insecure > 1))
supply(from, aifp, OUT_QUERY, 0,
rip->rip_vers, ap != 0);
rip->rip_vers,
ap != NULL);
else
trace_pkt("Warning: "
"possible attack detected");
@ -323,7 +324,7 @@ input(struct sockaddr_in *from, /* received from this IP address */
* to keep an unwary host that is just starting
* from picking us as a router.
*/
if (aifp == 0) {
if (aifp == NULL) {
trace_pkt("ignore distant router");
return;
}
@ -347,7 +348,7 @@ input(struct sockaddr_in *from, /* received from this IP address */
v12buf.n->n_family = RIP_AF_INET;
v12buf.n->n_dst = RIP_DEFAULT;
i = aifp->int_d_metric;
if (0 != (rt = rtget(RIP_DEFAULT, 0))) {
if (NULL != (rt = rtget(RIP_DEFAULT, 0))) {
j = (rt->rt_metric
+aifp->int_metric
+aifp->int_adj_outmetric
@ -369,7 +370,7 @@ input(struct sockaddr_in *from, /* received from this IP address */
supply(from, aifp, OUT_UNICAST, 0,
(aifp->int_state & IS_NO_RIPV1_OUT)
? RIPv2 : RIPv1,
ap != 0);
ap != NULL);
return;
}
@ -411,7 +412,7 @@ input(struct sockaddr_in *from, /* received from this IP address */
if (v12buf.buf->rip_vers != RIPv1)
v12buf.n->n_mask = mask;
if (rt == 0) {
if (rt == NULL) {
/* we do not have the answer */
v12buf.n->n_metric = HOPCNT_INFINITY;
} else {
@ -433,7 +434,7 @@ input(struct sockaddr_in *from, /* received from this IP address */
if (v12buf.buf->rip_vers != RIPv1) {
v12buf.n->n_tag = rt->rt_tag;
v12buf.n->n_mask = mask;
if (aifp != 0
if (aifp != NULL
&& on_net(rt->rt_gate,
aifp->int_net,
aifp->int_mask)
@ -451,7 +452,7 @@ input(struct sockaddr_in *from, /* received from this IP address */
/* Send the answer about specific routes.
*/
if (ap != 0 && ap->type == RIP_AUTH_MD5)
if (ap != NULL && ap->type == RIP_AUTH_MD5)
end_md5_auth(&v12buf, ap);
if (from->sin_port != htons(RIP_PORT)) {
@ -486,7 +487,7 @@ input(struct sockaddr_in *from, /* received from this IP address */
naddr_ntoa(FROM_NADDR));
return;
}
if (aifp == 0) {
if (aifp == NULL) {
msglog("trace command from unknown router %s",
naddr_ntoa(FROM_NADDR));
return;
@ -543,7 +544,7 @@ input(struct sockaddr_in *from, /* received from this IP address */
* via broadcast or point-to-point networks, and from
* those listed in /etc/gateways.
*/
if (aifp == 0) {
if (aifp == NULL) {
msglim(&unk_router, FROM_NADDR,
" discard response from %s"
" via unexpected interface",
@ -588,7 +589,7 @@ input(struct sockaddr_in *from, /* received from this IP address */
tg = tgates;
while (tg->tgate_addr != FROM_NADDR) {
tg = tg->tgate_next;
if (tg == 0) {
if (tg == NULL) {
trace_pkt(" discard RIP response"
" from untrusted router %s",
naddr_ntoa(FROM_NADDR));
@ -733,7 +734,7 @@ input(struct sockaddr_in *from, /* received from this IP address */
* of the defense against RS_NET_SYN.
*/
if (have_ripv1_out
&& (((rt = rtget(dst,mask)) == 0
&& (((rt = rtget(dst,mask)) == NULL
|| !(rt->rt_state & RS_NET_SYN)))
&& (v1_mask = ripv1_mask_net(dst,0)) > mask) {
ddst_h = v1_mask & -v1_mask;
@ -798,7 +799,7 @@ input_route(naddr dst, /* network order */
* If our interface is broken, switch to using the other guy.
*/
ifp1 = ifwithaddr(dst, 1, 1);
if (ifp1 != 0
if (ifp1 != NULL
&& (!(ifp1->int_state & IS_BROKE)
|| (ifp1->int_state & IS_PASSIVE)))
return;
@ -809,7 +810,7 @@ input_route(naddr dst, /* network order */
/* Consider adding the route if we do not already have it.
*/
if (rt == 0) {
if (rt == NULL) {
/* Ignore unknown routes being poisoned.
*/
if (new->rts_metric == HOPCNT_INFINITY)
@ -817,7 +818,7 @@ input_route(naddr dst, /* network order */
/* Ignore the route if it points to us */
if (n->n_nhop != 0
&& 0 != ifwithaddr(n->n_nhop, 1, 0))
&& ifwithaddr(n->n_nhop, 1, 0) != NULL)
return;
/* If something has not gone crazy and tried to fill
@ -915,7 +916,7 @@ input_route(naddr dst, /* network order */
* Ignore the route if it points to us.
*/
if (n->n_nhop != 0
&& 0 != ifwithaddr(n->n_nhop, 1, 0))
&& NULL != ifwithaddr(n->n_nhop, 1, 0))
return;
/* the loop above set rts0=worst spare */

View File

@ -752,7 +752,7 @@ rip_on(struct interface *ifp)
* multicasts for this interface.
*/
if (rip_sock >= 0) {
if (ifp != 0)
if (ifp != NULL)
rip_mcast_on(ifp);
return;
}
@ -778,7 +778,7 @@ rip_on(struct interface *ifp)
}
rip_sock = get_rip_sock(INADDR_ANY, 1);
rip_sock_mcast = 0;
rip_sock_mcast = NULL;
/* Do not advertise anything until we have heard something
*/
@ -791,7 +791,7 @@ rip_on(struct interface *ifp)
}
ifinit_timer.tv_sec = now.tv_sec;
} else if (ifp != 0
} else if (ifp != NULL
&& !(ifp->int_state & IS_REMOTE)
&& ifp->int_rip_sock < 0) {
/* RIP is off, so ensure there are sockets on which
@ -811,7 +811,7 @@ rtmalloc(size_t size,
const char *msg)
{
void *p = malloc(size);
if (p == 0)
if (p == NULL)
logbad(1,"malloc(%lu) failed in %s", (u_long)size, msg);
return p;
}
@ -871,7 +871,7 @@ msglog(const char *p, ...)
va_start(args, p);
vsyslog(LOG_ERR, p, args);
va_end(args);
if (ftrace != 0) {
if (ftrace != NULL) {
if (ftrace == stdout)
(void)fputs("routed: ", ftrace);
va_start(args, p);
@ -906,7 +906,7 @@ msglim(struct msg_limit *lim, naddr addr, const char *p, ...)
/* Reuse a slot at most once every 10 minutes.
*/
if (lim->reuse > now.tv_sec) {
ms = 0;
ms = NULL;
} else {
ms = ms1;
lim->reuse = now.tv_sec + 10*60;
@ -918,13 +918,13 @@ msglim(struct msg_limit *lim, naddr addr, const char *p, ...)
* most once an hour.
*/
if (ms->until > now.tv_sec)
ms = 0;
ms = NULL;
break;
}
if (ms->until < ms1->until)
ms = ms1;
}
if (ms != 0) {
if (ms != NULL) {
ms->addr = addr;
ms->until = now.tv_sec + 60*60; /* 60 minutes */
@ -937,7 +937,7 @@ msglim(struct msg_limit *lim, naddr addr, const char *p, ...)
}
/* always display the message if tracing */
if (ftrace != 0) {
if (ftrace != NULL) {
va_start(args, p);
(void)vfprintf(ftrace, p, args);
va_end(args);

View File

@ -164,7 +164,7 @@ output(enum output_type type,
LOGERR("setsockopt(rip_sock, "
"IP_MULTICAST_IF)");
errno = serrno;
ifp = 0;
ifp = NULL;
return -1;
}
rip_sock_mcast = ifp;
@ -187,11 +187,11 @@ output(enum output_type type,
res = sendto(soc, buf, size, flags,
(struct sockaddr *)&osin, sizeof(osin));
if (res < 0
&& (ifp == 0 || !(ifp->int_state & IS_BROKE))) {
&& (ifp == NULL || !(ifp->int_state & IS_BROKE))) {
serrno = errno;
msglog("%s sendto(%s%s%s.%d): %s", msg,
ifp != 0 ? ifp->int_name : "",
ifp != 0 ? ", " : "",
ifp != NULL ? ifp->int_name : "",
ifp != NULL ? ", " : "",
inet_ntoa(osin.sin_addr),
ntohs(osin.sin_port),
strerror(errno));
@ -214,10 +214,10 @@ find_auth(struct interface *ifp)
int i;
if (ifp == 0)
if (ifp == NULL)
return 0;
res = 0;
res = NULL;
ap = ifp->int_auth;
for (i = 0; i < MAX_AUTH_KEYS; i++, ap++) {
/* stop looking after the last key */
@ -230,13 +230,13 @@ find_auth(struct interface *ifp)
if ((u_long)ap->end < (u_long)clk.tv_sec) {
/* note best expired password as a fall-back */
if (res == 0 || (u_long)ap->end > (u_long)res->end)
if (res == NULL || (u_long)ap->end > (u_long)res->end)
res = ap;
continue;
}
/* note key with the best future */
if (res == 0 || (u_long)res->end < (u_long)ap->end)
if (res == NULL || (u_long)res->end < (u_long)ap->end)
res = ap;
}
return res;
@ -255,7 +255,7 @@ clr_ws_buf(struct ws_buf *wb,
/* (start to) install authentication if appropriate
*/
if (ap == 0)
if (ap == NULL)
return;
na = (struct netauth*)wb->n;
@ -317,11 +317,11 @@ supply_write(struct ws_buf *wb)
case NO_OUT_RIPV2:
break;
default:
if (ws.a != 0 && ws.a->type == RIP_AUTH_MD5)
if (ws.a != NULL && ws.a->type == RIP_AUTH_MD5)
end_md5_auth(wb,ws.a);
if (output(wb->type, &ws.to, ws.ifp, wb->buf,
((char *)wb->n - (char*)wb->buf)) < 0
&& ws.ifp != 0)
&& ws.ifp != NULL)
if_sick(ws.ifp);
ws.npackets++;
break;
@ -587,7 +587,7 @@ walk_supply(struct radix_node *rn,
* to say every 30 seconds to help detect broken Ethernets or
* other interfaces where one packet every 30 seconds costs nothing.
*/
if (ws.ifp != 0
if (ws.ifp != NULL
&& !(ws.state & WS_ST_QUERY)
&& (ws.state & WS_ST_TO_ON_NET)
&& (!(RT->rt_state & RS_IF)
@ -680,7 +680,7 @@ supply(struct sockaddr_in *dst,
ws.to_std_mask = std_mask(ws.to.sin_addr.s_addr);
ws.to_std_net = ntohl(ws.to.sin_addr.s_addr) & ws.to_std_mask;
if (ifp != 0) {
if (ifp != NULL) {
ws.to_mask = ifp->int_mask;
ws.to_net = ifp->int_net;
if (on_net(ws.to.sin_addr.s_addr, ws.to_net, ws.to_mask))
@ -698,7 +698,7 @@ supply(struct sockaddr_in *dst,
if (flash)
ws.state |= WS_ST_FLASH;
if ((ws.ifp = ifp) == 0) {
if ((ws.ifp = ifp) == NULL) {
ws.metric = 1;
} else {
/* Adjust the advertised metric by the outgoing interface
@ -739,18 +739,18 @@ supply(struct sockaddr_in *dst,
if ((ws.state & WS_ST_QUERY)
|| !(ws.state & WS_ST_TO_ON_NET)) {
ws.state |= (WS_ST_AG | WS_ST_SUPER_AG);
} else if (ifp == 0 || !(ifp->int_state & IS_NO_AG)) {
} else if (ifp == NULL || !(ifp->int_state & IS_NO_AG)) {
ws.state |= WS_ST_AG;
if (type != OUT_BROADCAST
&& (ifp == 0
&& (ifp == NULL
|| !(ifp->int_state & IS_NO_SUPER_AG)))
ws.state |= WS_ST_SUPER_AG;
}
}
ws.a = (vers == RIPv2) ? find_auth(ifp) : 0;
if (!passwd_ok && ws.a != 0 && ws.a->type == RIP_AUTH_PW)
ws.a = 0;
if (!passwd_ok && ws.a != NULL && ws.a->type == RIP_AUTH_PW)
ws.a = NULL;
clr_ws_buf(&v12buf,ws.a);
clr_ws_buf(&v2buf,ws.a);
@ -758,7 +758,7 @@ supply(struct sockaddr_in *dst,
* a better, real default route.
*/
if (supplier && (def_metric = ifp->int_d_metric) != 0) {
if (0 == (rt = rtget(RIP_DEFAULT, 0))
if ((rt = rtget(RIP_DEFAULT, 0)) == NULL
|| rt->rt_metric+ws.metric >= def_metric) {
ws.state |= WS_ST_DEFAULT;
ag_check(0, 0, 0, 0, def_metric, def_metric,

View File

@ -60,7 +60,7 @@ get_parms(struct interface *ifp)
/* get all relevant parameters
*/
for (parmp = parms; parmp != 0; parmp = parmp->parm_next) {
for (parmp = parms; parmp != NULL; parmp = parmp->parm_next) {
if (parmp->parm_name[0] == '\0'
|| !strcmp(ifp->int_name, parmp->parm_name)
|| (parmp->parm_name[0] == '\n'
@ -178,7 +178,7 @@ gwkludge(void)
fp = fopen(_PATH_GATEWAYS, "r");
if (fp == 0)
if (fp == NULL)
return;
if (0 > fstat(fileno(fp), &sb)) {
@ -208,7 +208,7 @@ gwkludge(void)
cp = parse_parms(lptr,
(sb.st_uid == 0
&& !(sb.st_mode&(S_IRWXG|S_IRWXO))));
if (cp != 0)
if (cp != NULL)
msglog("%s in line %d of "_PATH_GATEWAYS,
cp, lnum);
continue;
@ -315,7 +315,7 @@ gwkludge(void)
state |= IS_NO_RIP;
ifp = check_dup(gate,dst,netmask,state);
if (ifp != 0) {
if (ifp != NULL) {
msglog("duplicate "_PATH_GATEWAYS" entry \"%s\"",lptr);
continue;
}
@ -419,7 +419,7 @@ parse_quote(char **linep, /* look here */
return -1;
*buf = '\0'; /* terminate copy of token */
if (delimp != 0)
if (delimp != NULL)
*delimp = c; /* return delimiter */
*linep = pc-1; /* say where we ended */
return 0;
@ -521,14 +521,14 @@ get_passwd(char *tgt,
if (delim == '|') {
val0 = ++val;
if (0 != (p = parse_ts(&k.start,&val,val0,&delim,
buf,sizeof(buf))))
if (NULL != (p = parse_ts(&k.start,&val,val0,&delim,
buf,sizeof(buf))))
return p;
if (delim != '|')
return "missing second timestamp";
val0 = ++val;
if (0 != (p = parse_ts(&k.end,&val,val0,&delim,
buf,sizeof(buf))))
if (NULL != (p = parse_ts(&k.end,&val,val0,&delim,
buf,sizeof(buf))))
return p;
if ((u_long)k.start > (u_long)k.end) {
sprintf(buf,"out of order timestamp %.30s",
@ -570,7 +570,7 @@ parse_parms(char *line,
struct r1net *r1netp;
struct tgate *tg;
naddr addr, mask;
char delim, *val0 = 0, *tgt, *val, *p;
char delim, *val0 = NULL, *tgt, *val, *p;
const char *msg;
char buf[BUFSIZ], buf2[BUFSIZ];
int i;
@ -856,7 +856,7 @@ check_parms(struct parm *new)
/* compare with existing sets of parameters
*/
for (parmpp = &parms;
(parmp = *parmpp) != 0;
(parmp = *parmpp) != NULL;
parmpp = &parmp->parm_next) {
if (strcmp(new->parm_name, parmp->parm_name))
continue;
@ -943,7 +943,7 @@ getnet(char *name,
/* Detect and separate "1.2.3.4/24"
*/
if (0 != (mname = strrchr(name,'/'))) {
if (NULL != (mname = strrchr(name,'/'))) {
i = (int)(mname - name);
if (i > (int)sizeof(hname)-1) /* name too long */
return 0;
@ -954,7 +954,7 @@ getnet(char *name,
}
np = getnetbyname(name);
if (np != 0) {
if (np != NULL) {
in.s_addr = (naddr)np->n_net;
if (0 == (in.s_addr & 0xff000000))
in.s_addr <<= 8;

View File

@ -169,7 +169,8 @@ rn_lookup(void *v_arg, void *m_arg, struct radix_node_head *head)
caddr_t netmask = 0;
if (m_arg) {
if ((x = rn_addmask(m_arg, 1, head->rnh_treetop->rn_off)) == 0)
if ((x = rn_addmask(m_arg, 1,
head->rnh_treetop->rn_off)) == NULL)
return (0);
netmask = x->rn_key;
}
@ -190,7 +191,7 @@ rn_satisfies_leaf(char *trial,
char *cplim;
int length = min(*(u_char *)cp, *(u_char *)cp2);
if (cp3 == 0)
if (cp3 == NULL)
cp3 = rn_ones;
else
length = min(length, *(u_char *)cp3);
@ -445,7 +446,7 @@ rn_addmask(void *n_arg, int search, int skip)
*addmask_key = last_zeroed = mlen;
x = rn_search(addmask_key, rn_masktop);
if (Bcmp(addmask_key, x->rn_key, mlen) != 0)
x = 0;
x = NULL;
if (x || search)
return (x);
x = (struct radix_node *)rtmalloc(max_keylen + 2*sizeof(*x),
@ -500,7 +501,7 @@ rn_new_radix_mask(struct radix_node *tt,
struct radix_mask *m;
MKGet(m);
if (m == 0) {
if (m == NULL) {
log(LOG_ERR, "Mask for route not entered\n");
return (0);
}
@ -523,7 +524,7 @@ rn_addroute(void *v_arg,
struct radix_node treenodes[2])
{
caddr_t v = (caddr_t)v_arg, netmask = (caddr_t)n_arg;
struct radix_node *t, *x = 0, *tt;
struct radix_node *t, *x = NULL, *tt;
struct radix_node *saved_tt, *top = head->rnh_treetop;
short b = 0, b_leaf = 0;
int keyduplicated;
@ -538,7 +539,7 @@ rn_addroute(void *v_arg,
* nodes and possibly save time in calculating indices.
*/
if (netmask) {
if ((x = rn_addmask(netmask, 0, top->rn_off)) == 0)
if ((x = rn_addmask(netmask, 0, top->rn_off)) == NULL)
return (0);
b_leaf = x->rn_b;
b = -1 - x->rn_b;
@ -616,7 +617,7 @@ rn_addroute(void *v_arg,
for (mp = &x->rn_mklist; (m = *mp); mp = &m->rm_mklist)
if (m->rm_b >= b_leaf)
break;
t->rn_mklist = m; *mp = 0;
t->rn_mklist = m; *mp = NULL;
}
on2:
/* Add new route to highest possible ancestor's list */
@ -678,21 +679,21 @@ rn_delete(void *v_arg,
vlen = *(u_char *)v;
saved_tt = tt;
top = x;
if (tt == 0 ||
if (tt == NULL ||
Bcmp(v + head_off, tt->rn_key + head_off, vlen - head_off))
return (0);
/*
* Delete our route from mask lists.
*/
if (netmask) {
if ((x = rn_addmask(netmask, 1, head_off)) == 0)
if ((x = rn_addmask(netmask, 1, head_off)) == NULL)
return (0);
netmask = x->rn_key;
while (tt->rn_mask != netmask)
if ((tt = tt->rn_dupedkey) == 0)
if ((tt = tt->rn_dupedkey) == NULL)
return (0);
}
if (tt->rn_mask == 0 || (saved_m = m = tt->rn_mklist) == 0)
if (tt->rn_mask == 0 || (saved_m = m = tt->rn_mklist) == NULL)
goto on1;
if (tt->rn_flags & RNF_NORMAL) {
if (m->rm_leaf != tt || m->rm_refs > 0) {
@ -721,7 +722,7 @@ rn_delete(void *v_arg,
MKFree(m);
break;
}
if (m == 0) {
if (m == NULL) {
log(LOG_ERR, "rn_delete: couldn't find our annotation\n");
if (tt->rn_flags & RNF_NORMAL)
return (0); /* Dangling ref to us */

View File

@ -118,7 +118,7 @@ trace_rdisc(const char *act,
n_long *wp, *lim;
if (!TRACEPACKETS || ftrace == 0)
if (!TRACEPACKETS || ftrace == NULL)
return;
lastlog();
@ -310,7 +310,7 @@ rdisc_age(naddr bad_gate)
/* If switching from client to server, get rid of old
* default routes.
*/
if (cur_drp != 0)
if (cur_drp != NULL)
rdisc_sort();
rdisc_adv();
return;
@ -462,7 +462,7 @@ rdisc_sort(void)
/* Find the best discovered route.
*/
new_drp = 0;
new_drp = NULL;
for (drp = drs; drp < &drs[MAX_ADS]; drp++) {
if (drp->dr_ts == 0)
continue;
@ -487,7 +487,7 @@ rdisc_sort(void)
* bad routers.
* Avoid sick interfaces.
*/
if (new_drp == 0
if (new_drp == NULL
|| (!((new_st ^ drp->dr_ifp->int_state) & IS_SICK)
&& (new_pref < drp->dr_pref
|| (new_pref == drp->dr_pref
@ -509,11 +509,11 @@ rdisc_sort(void)
/* Stop using discovered routes if they are all bad
*/
if (new_drp == 0) {
if (new_drp == NULL) {
trace_act("turn off Router Discovery client");
rdisc_ok = 0;
if (rt != 0
if (rt != NULL
&& (rt->rt_state & RS_RDISC)) {
new = rt->rt_spares[0];
new.rts_metric = HOPCNT_INFINITY;
@ -524,7 +524,7 @@ rdisc_sort(void)
}
} else {
if (cur_drp == 0) {
if (cur_drp == NULL) {
trace_act("turn on Router Discovery client"
" using %s via %s",
naddr_ntoa(new_drp->dr_gate),
@ -546,7 +546,7 @@ rdisc_sort(void)
new.rts_router = new_drp->dr_gate;
new.rts_metric = HOPCNT_INFINITY-1;
new.rts_time = now.tv_sec;
if (rt != 0) {
if (rt != NULL) {
rtchange(rt, rt->rt_state | RS_RDISC, &new, 0);
} else {
rtadd(RIP_DEFAULT, 0, RS_RDISC, &new);
@ -588,7 +588,7 @@ parse_ad(naddr from,
/* ignore pointers to ourself and routes via unreachable networks
*/
if (ifwithaddr(gate, 1, 0) != 0) {
if (ifwithaddr(gate, 1, 0) != NULL) {
trace_pkt(" discard Router Discovery Ad pointing at us");
return;
}
@ -608,7 +608,7 @@ parse_ad(naddr from,
life = 0;
}
for (new_drp = 0, drp = drs; drp < &drs[MAX_ADS]; drp++) {
for (new_drp = NULL, drp = drs; drp < &drs[MAX_ADS]; drp++) {
/* accept new info for a familiar entry
*/
if (drp->dr_gate == gate) {
@ -622,7 +622,7 @@ parse_ad(naddr from,
if (drp->dr_ts == 0) {
new_drp = drp; /* use unused entry */
} else if (new_drp == 0) {
} else if (new_drp == NULL) {
/* look for an entry worse than the new one to
* reuse.
*/
@ -647,7 +647,7 @@ parse_ad(naddr from,
}
/* forget it if all of the current entries are better */
if (new_drp == 0)
if (new_drp == NULL)
return;
new_drp->dr_ifp = ifp;
@ -746,7 +746,7 @@ send_rdisc(union ad_u *p,
sizeof(mreqn))) {
LOGERR("setsockopt(rdisc_sock,"
"IP_MULTICAST_IF)");
rdisc_sock_mcast = 0;
rdisc_sock_mcast = NULL;
return;
}
rdisc_sock_mcast = ifp;
@ -763,13 +763,13 @@ send_rdisc(union ad_u *p,
if (0 > sendto(rdisc_sock, p, p_size, flags,
(struct sockaddr *)&rsin, sizeof(rsin))) {
if (ifp == 0 || !(ifp->int_state & IS_BROKE))
if (ifp == NULL || !(ifp->int_state & IS_BROKE))
msglog("sendto(%s%s%s): %s",
ifp != 0 ? ifp->int_name : "",
ifp != 0 ? ", " : "",
ifp != NULL ? ifp->int_name : "",
ifp != NULL ? ", " : "",
inet_ntoa(rsin.sin_addr),
strerror(errno));
if (ifp != 0)
if (ifp != NULL)
if_sick(ifp);
}
}
@ -920,7 +920,7 @@ ck_icmp(const char *act,
trace_rdisc(act, from, to, ifp, p, len);
if (ifp == 0)
if (ifp == NULL)
trace_pkt("unknown interface for router-discovery %s"
" from %s to %s",
type, naddr_ntoa(from), naddr_ntoa(to));
@ -981,7 +981,7 @@ read_d(void)
#ifdef USE_PASSIFNAME
ifp = ifwithname(buf.ifname, 0);
if (ifp == 0)
if (ifp == NULL)
msglim(&bad_name, from.sin_addr.s_addr,
"impossible rdisc if_ name %.*s",
IFNAMSIZ, buf.ifname);
@ -994,7 +994,7 @@ read_d(void)
#endif
ifp = ck_icmp("Recv", from.sin_addr.s_addr, ifp,
buf.pkt.ip.ip_dst.s_addr, p, cc);
if (ifp == 0)
if (ifp == NULL)
continue;
if (ifwithaddr(from.sin_addr.s_addr, 0, 0)) {
trace_pkt(" "

View File

@ -176,7 +176,7 @@ main(int argc,
rflag = getnet(optarg, &OMSG.rip_nets[0]);
if (!rflag) {
struct hostent *hp = gethostbyname(optarg);
if (hp == 0) {
if (hp == NULL) {
fprintf(stderr, "%s: %s:",
pgmname, optarg);
herror(0);
@ -353,7 +353,7 @@ trace_loop(char *argv[])
}
res = 1;
while (*argv != 0) {
while (*argv != NULL) {
if (out(*argv++) <= 0)
res = 0;
}
@ -417,9 +417,9 @@ query_loop(char *argv[], int argc)
}
/* ask the first (valid) host */
seen = 0;
seen = NULL;
while (0 > out(*argv++)) {
if (*argv == 0)
if (*argv == NULL)
exit(1);
answered++;
}
@ -445,13 +445,13 @@ query_loop(char *argv[], int argc)
* because a router might respond with a
* different source address.
*/
for (sp = seen; sp != 0; sp = sp->next) {
for (sp = seen; sp != NULL; sp = sp->next) {
if (sp->addr.s_addr == from.sin_addr.s_addr)
break;
}
if (sp == 0) {
if (sp == NULL) {
sp = malloc(sizeof(*sp));
if (sp == 0) {
if (sp == NULL) {
fprintf(stderr,
"rtquery: malloc failed\n");
exit(1);
@ -476,7 +476,7 @@ query_loop(char *argv[], int argc)
/* After a pause in responses, probe another host.
* This reduces the intermingling of answers.
*/
while (*argv != 0 && 0 > out(*argv++))
while (*argv != NULL && out(*argv++) < 0)
answered++;
/* continue until no more packets arrive
@ -520,7 +520,7 @@ out(const char *host)
#endif
if (!inet_aton(host, &router.sin_addr)) {
hp = gethostbyname(host);
if (hp == 0) {
if (hp == NULL) {
herror(host);
return -1;
}
@ -619,7 +619,7 @@ rip_input(struct sockaddr_in *from,
} else {
hp = gethostbyaddr((char*)&from->sin_addr,
sizeof(struct in_addr), AF_INET);
if (hp == 0) {
if (hp == NULL) {
printf("%s:",
inet_ntoa(from->sin_addr));
} else {
@ -691,7 +691,7 @@ rip_input(struct sockaddr_in *from,
if ((in.s_addr & ~mask) == 0) {
np = getnetbyaddr((long)in.s_addr,
AF_INET);
if (np != 0)
if (np != NULL)
name = np->n_name;
else if (in.s_addr == 0)
name = "default";
@ -702,7 +702,7 @@ rip_input(struct sockaddr_in *from,
hp = gethostbyaddr((char*)&in,
sizeof(in),
AF_INET);
if (hp != 0)
if (hp != NULL)
name = hp->h_name;
}
}
@ -770,12 +770,12 @@ rip_input(struct sockaddr_in *from,
if (n->n_nhop != 0) {
in.s_addr = n->n_nhop;
if (nflag)
hp = 0;
hp = NULL;
else
hp = gethostbyaddr((char*)&in, sizeof(in),
AF_INET);
(void)printf(" nhop=%-15s%s",
(hp != 0) ? hp->h_name : inet_ntoa(in),
(hp != NULL) ? hp->h_name : inet_ntoa(in),
(IMSG.rip_vers == RIPv1) ? " ?" : "");
}
if (n->n_tag != 0)
@ -820,7 +820,7 @@ getnet(char *name,
/* Detect and separate "1.2.3.4/24"
*/
if (0 != (mname = strrchr(name,'/'))) {
if (NULL != (mname = strrchr(name,'/'))) {
i = (int)(mname - name);
if (i > (int)sizeof(hname)-1) /* name too long */
return 0;
@ -831,7 +831,7 @@ getnet(char *name,
}
nentp = getnetbyname(name);
if (nentp != 0) {
if (nentp != NULL) {
in.s_addr = nentp->n_net;
} else if (inet_aton(name, &in) == 1) {
in.s_addr = ntohl(in.s_addr);
@ -839,7 +839,7 @@ getnet(char *name,
return 0;
}
if (mname == 0) {
if (mname == NULL) {
mask = std_mask(in.s_addr);
if ((~mask & in.s_addr) != 0)
mask = 0xffffffff;
@ -910,7 +910,7 @@ parse_quote(char **linep,
--lim;
}
exit:
if (delimp != 0)
if (delimp != NULL)
*delimp = c;
*linep = pc-1;
if (lim != 0)

View File

@ -99,9 +99,9 @@ static struct ag_info ag_slots[NUM_AG_SLOTS], *ag_avail, *ag_corsest, *ag_finest
/* #define DEBUG_AG */
#ifdef DEBUG_AG
#define CHECK_AG() {int acnt = 0; struct ag_info *cag; \
for (cag = ag_avail; cag != 0; cag = cag->ag_fine) \
for (cag = ag_avail; cag != NULL; cag = cag->ag_fine) \
acnt++; \
for (cag = ag_corsest; cag != 0; cag = cag->ag_fine) \
for (cag = ag_corsest; cag != NULL; cag = cag->ag_fine) \
acnt++; \
if (acnt != NUM_AG_SLOTS) { \
(void)fflush(stderr); \
@ -139,7 +139,7 @@ ag_out(struct ag_info *ag,
* ensures that the twins are seen before the parent is emitted.
*/
ag_cors = ag->ag_cors;
if (ag_cors != 0
if (ag_cors != NULL
&& ag_cors->ag_mask == ag->ag_mask<<1
&& ag_cors->ag_dst_h == (ag->ag_dst_h & ag_cors->ag_mask)) {
ag_cors->ag_state |= ((ag_cors->ag_dst_h == ag->ag_dst_h)
@ -174,12 +174,12 @@ ag_del(struct ag_info *ag)
{
CHECK_AG();
if (ag->ag_cors == 0)
if (ag->ag_cors == NULL)
ag_corsest = ag->ag_fine;
else
ag->ag_cors->ag_fine = ag->ag_fine;
if (ag->ag_fine == 0)
if (ag->ag_fine == NULL)
ag_finest = ag->ag_cors;
else
ag->ag_fine->ag_cors = ag->ag_cors;
@ -208,7 +208,7 @@ ag_flush(naddr lim_dst_h, /* flush routes to here */
for (ag = ag_finest;
ag != 0 && ag->ag_mask >= lim_mask;
ag != NULL && ag->ag_mask >= lim_mask;
ag = ag_cors) {
ag_cors = ag->ag_cors;
@ -223,7 +223,7 @@ ag_flush(naddr lim_dst_h, /* flush routes to here */
else for ( ; ; ag_cors = ag_cors->ag_cors) {
/* Look for a route that can suppress the
* current route */
if (ag_cors == 0) {
if (ag_cors == NULL) {
/* failed, so output it and look for
* another route to work on
*/
@ -320,9 +320,9 @@ ag_check(naddr dst,
/* Search for the right slot in the aggregation table.
*/
ag_cors = 0;
ag_cors = NULL;
ag = ag_corsest;
while (ag != 0) {
while (ag != NULL) {
if (ag->ag_mask >= mask)
break;
@ -335,7 +335,7 @@ ag_check(naddr dst,
* This check keeps poor routes (e.g. with large hop counts)
* from preventing suppression of finer routes.
*/
if (ag_cors != 0
if (ag_cors != NULL
&& ag->ag_dst_h < dst
&& (ag->ag_state & AGS_SUPPRESS)
&& ag_cors->ag_pref <= ag->ag_pref
@ -374,7 +374,7 @@ ag_check(naddr dst,
* times around this loop, it could be the even twin promoted
* from the even/odd pair of twins of the finer route.
*/
while (ag != 0
while (ag != NULL
&& ag->ag_mask == mask
&& ((ag->ag_dst_h ^ dst) & (mask<<1)) == 0) {
@ -537,7 +537,7 @@ ag_check(naddr dst,
mask <<= 1;
dst &= mask;
if (ag_cors == 0) {
if (ag_cors == NULL) {
ag = ag_corsest;
break;
}
@ -553,7 +553,7 @@ ag_check(naddr dst,
* In case we moved toward coarser masks,
* get back where we belong
*/
if (ag != 0
if (ag != NULL
&& ag->ag_mask < mask) {
ag_cors = ag;
ag = ag->ag_fine;
@ -561,20 +561,20 @@ ag_check(naddr dst,
/* Empty the target slot
*/
if (ag != 0 && ag->ag_mask == mask) {
if (ag != NULL && ag->ag_mask == mask) {
ag_flush(ag->ag_dst_h, ag->ag_mask, out);
ag = (ag_cors == 0) ? ag_corsest : ag_cors->ag_fine;
ag = (ag_cors == NULL) ? ag_corsest : ag_cors->ag_fine;
}
#ifdef DEBUG_AG
(void)fflush(stderr);
if (ag == 0 && ag_cors != ag_finest)
if (ag == NULL && ag_cors != ag_finest)
abort();
if (ag_cors == 0 && ag != ag_corsest)
if (ag_cors == NULL && ag != ag_corsest)
abort();
if (ag != 0 && ag->ag_cors != ag_cors)
if (ag != NULL && ag->ag_cors != ag_cors)
abort();
if (ag_cors != 0 && ag_cors->ag_fine != ag)
if (ag_cors != NULL && ag_cors->ag_fine != ag)
abort();
CHECK_AG();
#endif
@ -595,12 +595,12 @@ ag_check(naddr dst,
nag->ag_seqno = new_seqno;
nag->ag_fine = ag;
if (ag != 0)
if (ag != NULL)
ag->ag_cors = nag;
else
ag_finest = nag;
nag->ag_cors = ag_cors;
if (ag_cors == 0)
if (ag_cors == NULL)
ag_corsest = nag;
else
ag_cors->ag_fine = nag;
@ -785,11 +785,11 @@ kern_find(naddr dst, naddr mask, struct khash ***ppk)
{
struct khash *k, **pk;
for (pk = &KHASH(dst,mask); (k = *pk) != 0; pk = &k->k_next) {
for (pk = &KHASH(dst,mask); (k = *pk) != NULL; pk = &k->k_next) {
if (k->k_dst == dst && k->k_mask == mask)
break;
}
if (ppk != 0)
if (ppk != NULL)
*ppk = pk;
return k;
}
@ -801,7 +801,7 @@ kern_add(naddr dst, naddr mask)
struct khash *k, **pk;
k = kern_find(dst, mask, &pk);
if (k != 0)
if (k != NULL)
return k;
k = (struct khash *)rtmalloc(sizeof(*k), "kern_add");
@ -833,12 +833,12 @@ kern_check_static(struct khash *k,
memset(&new, 0, sizeof(new));
new.rts_ifp = ifp;
new.rts_gate = k->k_gate;
new.rts_router = (ifp != 0) ? ifp->int_addr : loopaddr;
new.rts_router = (ifp != NULL) ? ifp->int_addr : loopaddr;
new.rts_metric = k->k_metric;
new.rts_time = now.tv_sec;
rt = rtget(k->k_dst, k->k_mask);
if (rt != 0) {
if (rt != NULL) {
if (!(rt->rt_state & RS_STATIC))
rtchange(rt, rt->rt_state | RS_STATIC, &new, 0);
} else {
@ -931,9 +931,9 @@ rtm_add(struct rt_msghdr *rtm,
&& INFO_AUTHOR(info)->sa_family == AF_INET)
ifp = iflookup(S_ADDR(INFO_AUTHOR(info)));
else
ifp = 0;
ifp = NULL;
if (supplier
&& (ifp == 0 || !(ifp->int_state & IS_REDIRECT_OK))) {
&& (ifp == NULL || !(ifp->int_state & IS_REDIRECT_OK))) {
/* Routers are not supposed to listen to redirects,
* so delete it if it came via an unknown interface
* or the interface does not have special permission.
@ -972,7 +972,7 @@ rtm_add(struct rt_msghdr *rtm,
* Find the interface toward the gateway.
*/
ifp = iflookup(k->k_gate);
if (ifp == 0)
if (ifp == NULL)
msglog("static route %s --> %s impossibly lacks ifp",
addrname(S_ADDR(INFO_DST(info)), mask, 0),
naddr_ntoa(k->k_gate));
@ -1011,7 +1011,7 @@ get_info_gate(struct sockaddr **sap,
struct sockaddr_dl *sdl = (struct sockaddr_dl *)*sap;
struct interface *ifp;
if (sdl == 0)
if (sdl == NULL)
return 0;
if ((sdl)->sdl_family == AF_INET)
return 1;
@ -1019,7 +1019,7 @@ get_info_gate(struct sockaddr **sap,
return 0;
ifp = ifwithindex(sdl->sdl_index, 1);
if (ifp == 0)
if (ifp == NULL)
return 0;
rsin->sin_addr.s_addr = ifp->int_addr;
@ -1052,7 +1052,7 @@ flush_kern(void)
for (i = 0; i < KHASH_SIZE; i++) {
for (k = khash_bins[i]; k != 0; k = k->k_next) {
for (k = khash_bins[i]; k != NULL; k = k->k_next) {
k->k_state |= KS_CHECK;
}
}
@ -1135,7 +1135,7 @@ flush_kern(void)
}
for (i = 0; i < KHASH_SIZE; i++) {
for (k = khash_bins[i]; k != 0; k = k->k_next) {
for (k = khash_bins[i]; k != NULL; k = k->k_next) {
if (k->k_state & KS_CHECK) {
msglog("%s --> %s disappeared from kernel",
addrname(k->k_dst, k->k_mask, 0),
@ -1198,7 +1198,7 @@ read_rt(void)
|| m.r.rtm.rtm_type == RTM_DELADDR) {
ifp = ifwithindex(m.ifm.ifm_index,
m.r.rtm.rtm_type != RTM_DELADDR);
if (ifp == 0)
if (ifp == NULL)
trace_act("note %s with flags %#x"
" for unknown interface index #%d",
rtm_type_name(m.r.rtm.rtm_type),
@ -1217,7 +1217,7 @@ read_rt(void)
* off or on.
*/
if (ifinit_timer.tv_sec-now.tv_sec>=CHECK_BAD_INTERVAL
|| ifp == 0
|| ifp == NULL
|| ((ifp->int_if_flags ^ m.ifm.ifm_flags)
& IFF_UP) != 0)
ifinit_timer.tv_sec = now.tv_sec;
@ -1338,7 +1338,7 @@ kern_out(struct ag_info *ag)
*/
if (ag->ag_metric == HOPCNT_INFINITY) {
k = kern_find(htonl(ag->ag_dst_h), ag->ag_mask, 0);
if (k == 0)
if (k == NULL)
return;
} else {
k = kern_add(htonl(ag->ag_dst_h), ag->ag_mask);
@ -1495,7 +1495,7 @@ fix_kern(void)
ag_flush(0,0,kern_out);
for (i = 0; i < KHASH_SIZE; i++) {
for (pk = &khash_bins[i]; (k = *pk) != 0; ) {
for (pk = &khash_bins[i]; (k = *pk) != NULL; ) {
/* Do not touch static routes */
if (k->k_state & KS_STATIC) {
kern_check_static(k,0);
@ -1569,7 +1569,7 @@ del_static(naddr dst,
* and add a replacement.
*/
k = kern_find(dst, mask, 0);
if (k != 0 && (gate == 0 || k->k_gate == gate)) {
if (k != NULL && (gate == 0 || k->k_gate == gate)) {
k->k_state &= ~(KS_STATIC | KS_DYNAMIC | KS_CHECK);
k->k_state |= KS_DELETE;
if (gone) {
@ -1579,7 +1579,7 @@ del_static(naddr dst,
}
rt = rtget(dst, mask);
if (rt != 0 && (rt->rt_state & RS_STATIC))
if (rt != NULL && (rt->rt_state & RS_STATIC))
rtbad(rt);
}
@ -1596,7 +1596,7 @@ del_redirects(naddr bad_gate,
for (i = 0; i < KHASH_SIZE; i++) {
for (k = khash_bins[i]; k != 0; k = k->k_next) {
for (k = khash_bins[i]; k != NULL; k = k->k_next) {
if (!(k->k_state & KS_DYNAMIC)
|| (k->k_state & KS_STATIC))
continue;
@ -1827,7 +1827,7 @@ rtswitch(struct rt_entry *rt,
return;
/* find the best alternative among the spares */
if (rts == 0)
if (rts == NULL)
rts = rts_better(rt);
/* Do not bother if it is not worthwhile.
@ -1856,7 +1856,7 @@ rtdelete(struct rt_entry *rt)
trace_add_del("Del", rt);
k = kern_find(rt->rt_dst, rt->rt_mask, 0);
if (k != 0) {
if (k != NULL) {
k->k_state |= KS_DELETE;
need_kern.tv_sec = now.tv_sec;
}
@ -1909,7 +1909,7 @@ rtbad_sub(struct rt_entry *rt)
u_int state;
ifp1 = 0;
ifp1 = NULL;
state = 0;
if (rt->rt_state & RS_LOCAL) {
@ -1947,7 +1947,7 @@ rtbad_sub(struct rt_entry *rt)
/* or if there is an authority route that needs it. */
for (intnetp = intnets;
intnetp != 0;
intnetp != NULL;
intnetp = intnetp->intnet_next) {
if (intnetp->intnet_addr == rt->rt_dst
&& intnetp->intnet_mask == rt->rt_mask) {
@ -1957,7 +1957,7 @@ rtbad_sub(struct rt_entry *rt)
}
}
if (ifp1 != 0 || (state & RS_NET_SYN)) {
if (ifp1 != NULL || (state & RS_NET_SYN)) {
struct rt_spare new = rt->rt_spares[0];
new.rts_ifp = ifp1;
rtchange(rt, ((rt->rt_state & ~(RS_NET_SYN|RS_LOCAL)) | state),
@ -1987,7 +1987,7 @@ walk_bad(struct radix_node *rn,
for (i = NUM_SPARES; i != 1; i--) {
rts++;
if (rts->rts_metric < HOPCNT_INFINITY
&& (rts->rts_ifp == 0
&& (rts->rts_ifp == NULL
|| (rts->rts_ifp->int_state & IS_BROKE)))
rts_delete(RT, rts);
}

View File

@ -139,7 +139,7 @@ naddr_ntoa(naddr a)
const char *
saddr_ntoa(struct sockaddr *sa)
{
return (sa == 0) ? "?" : naddr_ntoa(S_ADDR(sa));
return (sa == NULL) ? "?" : naddr_ntoa(S_ADDR(sa));
}
@ -180,7 +180,7 @@ tmsg(const char *p, ...)
{
va_list args;
if (ftrace != 0) {
if (ftrace != NULL) {
lastlog();
va_start(args, p);
vfprintf(ftrace, p, args);
@ -200,10 +200,10 @@ trace_close(int zap_stdio)
fflush(stdout);
fflush(stderr);
if (ftrace != 0 && zap_stdio) {
if (ftrace != NULL && zap_stdio) {
if (ftrace != stdout)
fclose(ftrace);
ftrace = 0;
ftrace = NULL;
fd = open(_PATH_DEVNULL, O_RDWR);
if (isatty(STDIN_FILENO))
(void)dup2(fd, STDIN_FILENO);
@ -220,7 +220,7 @@ trace_close(int zap_stdio)
void
trace_flush(void)
{
if (ftrace != 0) {
if (ftrace != NULL) {
fflush(ftrace);
if (ferror(ftrace))
trace_off("tracing off: %s", strerror(ferror(ftrace)));
@ -234,7 +234,7 @@ trace_off(const char *p, ...)
va_list args;
if (ftrace != 0) {
if (ftrace != NULL) {
lastlog();
va_start(args, p);
vfprintf(ftrace, p, args);
@ -307,16 +307,16 @@ set_tracefile(const char *filename,
* is already open or if coming from a trusted source, such as
* a signal or the command line.
*/
if (filename == 0 || filename[0] == '\0') {
filename = 0;
if (ftrace == 0) {
if (filename == NULL || filename[0] == '\0') {
filename = NULL;
if (ftrace == NULL) {
if (inittracename[0] == '\0') {
msglog("missing trace file name");
return;
}
fn = inittracename;
} else {
fn = 0;
fn = NULL;
}
} else if (!strcmp(filename,"dump/../table")) {
@ -351,9 +351,9 @@ set_tracefile(const char *filename,
fn = filename;
}
if (fn != 0) {
if (fn != NULL) {
n_ftrace = fopen(fn, "a");
if (n_ftrace == 0) {
if (n_ftrace == NULL) {
msglog("failed to open trace file \"%s\" %s",
fn, strerror(errno));
if (fn == inittracename)
@ -375,9 +375,9 @@ set_tracefile(const char *filename,
dup2(fileno(ftrace), STDERR_FILENO);
}
if (new_tracelevel == 0 || filename == 0)
if (new_tracelevel == 0 || filename == NULL)
new_tracelevel++;
tracelevel_msg(pat, dump != 0 ? dump : (filename != 0));
tracelevel_msg(pat, dump != 0 ? dump : (filename != NULL));
}
@ -410,7 +410,7 @@ set_tracelevel(void)
/* If tracing entirely off, and there was no tracefile specified
* on the command line, then leave it off.
*/
if (new_tracelevel > tracelevel && ftrace == 0) {
if (new_tracelevel > tracelevel && ftrace == NULL) {
if (savetracename[0] != '\0') {
set_tracefile(savetracename,sigtrace_pat,0);
} else if (inittracename[0] != '\0') {
@ -563,7 +563,7 @@ trace_bits(const struct bits *tbl,
}
tbl++;
}
if (field != 0 && tbl->bits_name != 0) {
if (field != 0 && tbl->bits_name != NULL) {
if (c)
(void)putc(c, ftrace);
(void)fprintf(ftrace, tbl->bits_name, field);
@ -604,7 +604,7 @@ print_rts(struct rt_spare *rts,
if (force_metric >= 0)
(void)fprintf(ftrace, "metric=%-2d ", rts->rts_metric);
if (force_ifp >= 0)
(void)fprintf(ftrace, "%s ", (rts->rts_ifp == 0 ?
(void)fprintf(ftrace, "%s ", (rts->rts_ifp == NULL ?
"if?" : rts->rts_ifp->int_name));
if (force_router > 0
|| (force_router == 0 && rts->rts_router != rts->rts_gate))
@ -628,7 +628,7 @@ void
trace_if(const char *act,
struct interface *ifp)
{
if (!TRACEACTIONS || ftrace == 0)
if (!TRACEACTIONS || ftrace == NULL)
return;
lastlog();
@ -661,7 +661,7 @@ trace_upslot(struct rt_entry *rt,
struct rt_spare *rts,
struct rt_spare *new)
{
if (!TRACEACTIONS || ftrace == 0)
if (!TRACEACTIONS || ftrace == NULL)
return;
if (rts->rts_gate == new->rts_gate
@ -721,7 +721,7 @@ trace_misc(const char *p, ...)
{
va_list args;
if (ftrace == 0)
if (ftrace == NULL)
return;
lastlog();
@ -739,7 +739,7 @@ trace_act(const char *p, ...)
{
va_list args;
if (!TRACEACTIONS || ftrace == 0)
if (!TRACEACTIONS || ftrace == NULL)
return;
lastlog();
@ -757,7 +757,7 @@ trace_pkt(const char *p, ...)
{
va_list args;
if (!TRACEPACKETS || ftrace == 0)
if (!TRACEPACKETS || ftrace == NULL)
return;
lastlog();
@ -774,7 +774,7 @@ trace_change(struct rt_entry *rt,
struct rt_spare *new,
const char *label)
{
if (ftrace == 0)
if (ftrace == NULL)
return;
if (rt->rt_metric == new->rts_metric
@ -813,7 +813,7 @@ trace_change(struct rt_entry *rt,
void
trace_add_del(const char * action, struct rt_entry *rt)
{
if (ftrace == 0)
if (ftrace == NULL)
return;
lastlog();
@ -863,7 +863,7 @@ trace_dump(void)
{
struct interface *ifp;
if (ftrace == 0)
if (ftrace == NULL)
return;
lastlog();
@ -885,7 +885,7 @@ trace_rip(const char *dir1, const char *dir2,
# define NA ((struct netauth*)n)
int i, seen_route;
if (!TRACEPACKETS || ftrace == 0)
if (!TRACEPACKETS || ftrace == NULL)
return;
lastlog();