route: remove write-only struct hostent from getaddr()

Under some INET/INET6 src.conf configurations sbin/route previously
failed to build due to an unused variable warning.  It was functionally
write-only anyway, so just remove it.

Reported by:	melifaro
Reviewed by:	melifaro
MFC after:	3 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D33717
This commit is contained in:
Ed Maste 2022-01-01 19:16:43 -05:00
parent 0197ba465f
commit f567fcb2ff

View File

@ -117,7 +117,7 @@ static TAILQ_HEAD(fibl_head_t, fibl) fibl_head;
static void printb(int, const char *); static void printb(int, const char *);
static void flushroutes(int argc, char *argv[]); static void flushroutes(int argc, char *argv[]);
static int flushroutes_fib(int); static int flushroutes_fib(int);
static int getaddr(int, char *, struct hostent **, int); static int getaddr(int, char *, int);
static int keyword(const char *); static int keyword(const char *);
#ifdef INET #ifdef INET
static void inet_makemask(struct sockaddr_in *, u_long); static void inet_makemask(struct sockaddr_in *, u_long);
@ -790,7 +790,6 @@ static void
newroute(int argc, char **argv) newroute(int argc, char **argv)
{ {
struct sigaction sa; struct sigaction sa;
struct hostent *hp;
struct fibl *fl; struct fibl *fl;
char *cmd; char *cmd;
const char *dest, *gateway, *errmsg; const char *dest, *gateway, *errmsg;
@ -802,7 +801,6 @@ newroute(int argc, char **argv)
gateway = NULL; gateway = NULL;
flags = RTF_STATIC; flags = RTF_STATIC;
nrflags = 0; nrflags = 0;
hp = NULL;
TAILQ_INIT(&fibl_head); TAILQ_INIT(&fibl_head);
sigemptyset(&sa.sa_mask); sigemptyset(&sa.sa_mask);
@ -893,35 +891,35 @@ newroute(int argc, char **argv)
case K_IFA: case K_IFA:
if (!--argc) if (!--argc)
usage(NULL); usage(NULL);
getaddr(RTAX_IFA, *++argv, NULL, nrflags); getaddr(RTAX_IFA, *++argv, nrflags);
break; break;
case K_IFP: case K_IFP:
if (!--argc) if (!--argc)
usage(NULL); usage(NULL);
getaddr(RTAX_IFP, *++argv, NULL, nrflags); getaddr(RTAX_IFP, *++argv, nrflags);
break; break;
case K_GENMASK: case K_GENMASK:
if (!--argc) if (!--argc)
usage(NULL); usage(NULL);
getaddr(RTAX_GENMASK, *++argv, NULL, nrflags); getaddr(RTAX_GENMASK, *++argv, nrflags);
break; break;
case K_GATEWAY: case K_GATEWAY:
if (!--argc) if (!--argc)
usage(NULL); usage(NULL);
getaddr(RTAX_GATEWAY, *++argv, NULL, nrflags); getaddr(RTAX_GATEWAY, *++argv, nrflags);
gateway = *argv; gateway = *argv;
break; break;
case K_DST: case K_DST:
if (!--argc) if (!--argc)
usage(NULL); usage(NULL);
if (getaddr(RTAX_DST, *++argv, &hp, nrflags)) if (getaddr(RTAX_DST, *++argv, nrflags))
nrflags |= F_ISHOST; nrflags |= F_ISHOST;
dest = *argv; dest = *argv;
break; break;
case K_NETMASK: case K_NETMASK:
if (!--argc) if (!--argc)
usage(NULL); usage(NULL);
getaddr(RTAX_NETMASK, *++argv, NULL, nrflags); getaddr(RTAX_NETMASK, *++argv, nrflags);
/* FALLTHROUGH */ /* FALLTHROUGH */
case K_NET: case K_NET:
nrflags |= F_FORCENET; nrflags |= F_FORCENET;
@ -956,13 +954,13 @@ newroute(int argc, char **argv)
} else { } else {
if ((rtm_addrs & RTA_DST) == 0) { if ((rtm_addrs & RTA_DST) == 0) {
dest = *argv; dest = *argv;
if (getaddr(RTAX_DST, *argv, &hp, nrflags)) if (getaddr(RTAX_DST, *argv, nrflags))
nrflags |= F_ISHOST; nrflags |= F_ISHOST;
} else if ((rtm_addrs & RTA_GATEWAY) == 0) { } else if ((rtm_addrs & RTA_GATEWAY) == 0) {
gateway = *argv; gateway = *argv;
getaddr(RTAX_GATEWAY, *argv, &hp, nrflags); getaddr(RTAX_GATEWAY, *argv, nrflags);
} else { } else {
getaddr(RTAX_NETMASK, *argv, NULL, nrflags); getaddr(RTAX_NETMASK, *argv, nrflags);
nrflags |= F_FORCENET; nrflags |= F_FORCENET;
} }
} }
@ -1154,7 +1152,7 @@ inet6_makenetandmask(struct sockaddr_in6 *sin6, const char *plen)
* returning 1 if a host address, 0 if a network address. * returning 1 if a host address, 0 if a network address.
*/ */
static int static int
getaddr(int idx, char *str, struct hostent **hpp, int nrflags) getaddr(int idx, char *str, int nrflags)
{ {
struct sockaddr *sa; struct sockaddr *sa;
#if defined(INET) #if defined(INET)
@ -1179,9 +1177,6 @@ getaddr(int idx, char *str, struct hostent **hpp, int nrflags)
aflen = sizeof(struct sockaddr_dl); aflen = sizeof(struct sockaddr_dl);
#endif #endif
} }
#ifndef INET
hpp = NULL;
#endif
rtm_addrs |= (1 << idx); rtm_addrs |= (1 << idx);
sa = (struct sockaddr *)&so[idx]; sa = (struct sockaddr *)&so[idx];
sa->sa_family = af; sa->sa_family = af;
@ -1233,7 +1228,7 @@ getaddr(int idx, char *str, struct hostent **hpp, int nrflags)
switch (idx) { switch (idx) {
case RTAX_DST: case RTAX_DST:
nrflags |= F_FORCENET; nrflags |= F_FORCENET;
getaddr(RTAX_NETMASK, str, NULL, nrflags); getaddr(RTAX_NETMASK, str, nrflags);
break; break;
} }
return (0); return (0);
@ -1280,9 +1275,6 @@ getaddr(int idx, char *str, struct hostent **hpp, int nrflags)
#ifdef INET #ifdef INET
sin = (struct sockaddr_in *)(void *)sa; sin = (struct sockaddr_in *)(void *)sa;
if (hpp == NULL)
hpp = &hp;
*hpp = NULL;
q = strchr(str,'/'); q = strchr(str,'/');
if (q != NULL && idx == RTAX_DST) { if (q != NULL && idx == RTAX_DST) {
@ -1303,7 +1295,6 @@ getaddr(int idx, char *str, struct hostent **hpp, int nrflags)
hp = gethostbyname(str); hp = gethostbyname(str);
if (hp != NULL) { if (hp != NULL) {
*hpp = hp;
sin->sin_family = hp->h_addrtype; sin->sin_family = hp->h_addrtype;
memmove((char *)&sin->sin_addr, hp->h_addr, memmove((char *)&sin->sin_addr, hp->h_addr,
MIN((size_t)hp->h_length, sizeof(sin->sin_addr))); MIN((size_t)hp->h_length, sizeof(sin->sin_addr)));