diff options
author | Otto Moerbeek <otto@cvs.openbsd.org> | 2004-03-11 08:39:49 +0000 |
---|---|---|
committer | Otto Moerbeek <otto@cvs.openbsd.org> | 2004-03-11 08:39:49 +0000 |
commit | a48dcf67a504240076be33fc70da196743e4f49a (patch) | |
tree | 334ecc8fb25e7d31058f09cd832d865d15775391 /sbin/routed | |
parent | ca96bd82e5cfc3747d90a44e90d1819badff6d2e (diff) |
Fix byte ordering problems with network info read from /etc/gateways
or -P and -F options. Based on NetBSD. Resolves PR 3704.
ok deraadt@
Diffstat (limited to 'sbin/routed')
-rw-r--r-- | sbin/routed/main.c | 6 | ||||
-rw-r--r-- | sbin/routed/parms.c | 31 |
2 files changed, 14 insertions, 23 deletions
diff --git a/sbin/routed/main.c b/sbin/routed/main.c index 513a90a3a6a..9110a5f10a1 100644 --- a/sbin/routed/main.c +++ b/sbin/routed/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.16 2003/06/02 20:06:17 millert Exp $ */ +/* $OpenBSD: main.c,v 1.17 2004/03/11 08:39:48 otto Exp $ */ /* * Copyright (c) 1983, 1988, 1993 @@ -35,7 +35,7 @@ char copyright[] = #if !defined(lint) static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/5/93"; #else -static char rcsid[] = "$OpenBSD: main.c,v 1.16 2003/06/02 20:06:17 millert Exp $"; +static char rcsid[] = "$OpenBSD: main.c,v 1.17 2004/03/11 08:39:48 otto Exp $"; #endif #include "defs.h" @@ -182,7 +182,7 @@ main(int argc, break; } bzero(&parm, sizeof(parm)); - parm.parm_addr_h = ntohl(p_addr); + parm.parm_addr_h = p_addr; parm.parm_mask = p_mask; parm.parm_d_metric = n; p = check_parms(&parm); diff --git a/sbin/routed/parms.c b/sbin/routed/parms.c index ffba6645595..c8674543dac 100644 --- a/sbin/routed/parms.c +++ b/sbin/routed/parms.c @@ -1,4 +1,4 @@ -/* $OpenBSD: parms.c,v 1.10 2003/06/02 20:06:17 millert Exp $ */ +/* $OpenBSD: parms.c,v 1.11 2004/03/11 08:39:48 otto Exp $ */ /* * Copyright (c) 1983, 1993 @@ -139,8 +139,6 @@ gwkludge(void) int metric, n; u_int state; char *type; - struct parm *parmp; - fp = fopen(_PATH_GATEWAYS, "r"); if (fp == 0) @@ -202,6 +200,7 @@ gwkludge(void) " entry \"%s\"", dname, lptr); continue; } + HTONL(dst); /* make network # into IP address */ } else { msglog("bad \"%s\" in "_PATH_GATEWAYS " entry \"%s\"", lptr); @@ -271,15 +270,6 @@ gwkludge(void) == (IS_NO_RIP|IS_NO_RDISC)) state |= IS_PASSIVE; - parmp = (struct parm*)malloc(sizeof(*parmp)); - bzero(parmp, sizeof(*parmp)); - parmp->parm_next = parms; - parms = parmp; - parmp->parm_addr_h = ntohl(dst); - parmp->parm_mask = -1; - parmp->parm_d_metric = 0; - parmp->parm_int_state = state; - /* See if this new interface duplicates an existing * interface. */ @@ -367,6 +357,7 @@ parse_parms(char *line) free(intnetp); return line; } + HTONL(intnetp->intnet_addr); intnetp->intnet_next = intnets; intnets = intnetp; return 0; @@ -544,13 +535,13 @@ check_parms(struct parm *new) */ int /* 0=bad */ getnet(char *name, - naddr *addrp, /* host byte order */ - naddr *maskp) + naddr *addrp, /* network in host byte order */ + naddr *maskp) /* masks are always in host order */ { int i; struct netent *np; - naddr mask; - struct in_addr in; + naddr mask; /* in host byte order */ + struct in_addr in; /* a network and so host byte order */ char hname[MAXHOSTNAMELEN+1]; char *mname, *p; @@ -571,7 +562,7 @@ getnet(char *name, if (np != 0) { in.s_addr = (naddr)np->n_net; } else if (inet_aton(name, &in) == 1) { - HTONL(in.s_addr); + NTOHL(in.s_addr); } else { return 0; } @@ -580,8 +571,8 @@ getnet(char *name, /* we cannot use the interfaces here because we have not * looked at them yet. */ - mask = std_mask(in.s_addr); - if ((~mask & ntohl(in.s_addr)) != 0) + mask = std_mask(htonl(in.s_addr)); + if ((~mask & in.s_addr) != 0) mask = HOST_MASK; } else { mask = (naddr)strtoul(mname, &p, 0); @@ -591,7 +582,7 @@ getnet(char *name, } if (mask != 0 && in.s_addr == RIP_DEFAULT) return 0; - if ((~mask & ntohl(in.s_addr)) != 0) + if ((~mask & in.s_addr) != 0) return 0; *addrp = in.s_addr; |