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