diff options
author | Ian Dowse <iedowse@FreeBSD.org> | 2001-04-23 10:12:31 +0000 |
---|---|---|
committer | Ian Dowse <iedowse@FreeBSD.org> | 2001-04-23 10:12:31 +0000 |
commit | 931c04f1a8c451ca83dbaa4bcb457cf8476cf3e9 (patch) | |
tree | 90bf368f821b6353fd038d0095544ca657152f1b | |
parent | b2bcd87e4fdfd70088e70a2afd0aa24d7025b24c (diff) |
Notes
-rw-r--r-- | sbin/mountd/mountd.c | 35 | ||||
-rw-r--r-- | usr.sbin/mountd/mountd.c | 35 |
2 files changed, 40 insertions, 30 deletions
diff --git a/sbin/mountd/mountd.c b/sbin/mountd/mountd.c index 3726cba0e5105..cab8bc0263817 100644 --- a/sbin/mountd/mountd.c +++ b/sbin/mountd/mountd.c @@ -1866,10 +1866,10 @@ get_net(cp, net, maskflg) struct netmsk *net; int maskflg; { - struct netent *np; + struct netent *np = NULL; char *name, *p, *prefp; struct sockaddr_in sin; - struct sockaddr *sa; + struct sockaddr *sa = NULL; struct addrinfo hints, *ai = NULL; char netname[NI_MAXHOST]; long preflen; @@ -1881,13 +1881,11 @@ get_net(cp, net, maskflg) prefp = p + 1; } - if ((np = getnetbyname(cp)) != NULL) { - bzero(&sin, sizeof sin); - sin.sin_family = AF_INET; - sin.sin_len = sizeof sin; - sin.sin_addr = inet_makeaddr(np->n_net, 0); - sa = (struct sockaddr *)&sin; - } else if (isxdigit(*cp) || *cp == ':') { + /* + * Check for a numeric address first. We wish to avoid + * possible DNS lookups in getnetbyname(). + */ + if (isxdigit(*cp) || *cp == ':') { memset(&hints, 0, sizeof hints); /* Ensure the mask and the network have the same family. */ if (maskflg && (opt_flags & OP_NET)) @@ -1897,9 +1895,9 @@ get_net(cp, net, maskflg) else hints.ai_family = AF_UNSPEC; hints.ai_flags = AI_NUMERICHOST; - if (getaddrinfo(cp, NULL, &hints, &ai) != 0) - goto fail; - if (ai->ai_family == AF_INET) { + if (getaddrinfo(cp, NULL, &hints, &ai) == 0) + sa = ai->ai_addr; + if (sa != NULL && ai->ai_family == AF_INET) { /* * The address in `cp' is really a network address, so * use inet_network() to re-interpret this correctly. @@ -1913,9 +1911,16 @@ get_net(cp, net, maskflg) fprintf(stderr, "get_net: v4 addr %s\n", inet_ntoa(sin.sin_addr)); sa = (struct sockaddr *)&sin; - } else - sa = ai->ai_addr; - } else + } + } + if (sa == NULL && (np = getnetbyname(cp)) != NULL) { + bzero(&sin, sizeof sin); + sin.sin_family = AF_INET; + sin.sin_len = sizeof sin; + sin.sin_addr = inet_makeaddr(np->n_net, 0); + sa = (struct sockaddr *)&sin; + } + if (sa == NULL) goto fail; if (maskflg) { diff --git a/usr.sbin/mountd/mountd.c b/usr.sbin/mountd/mountd.c index 3726cba0e5105..cab8bc0263817 100644 --- a/usr.sbin/mountd/mountd.c +++ b/usr.sbin/mountd/mountd.c @@ -1866,10 +1866,10 @@ get_net(cp, net, maskflg) struct netmsk *net; int maskflg; { - struct netent *np; + struct netent *np = NULL; char *name, *p, *prefp; struct sockaddr_in sin; - struct sockaddr *sa; + struct sockaddr *sa = NULL; struct addrinfo hints, *ai = NULL; char netname[NI_MAXHOST]; long preflen; @@ -1881,13 +1881,11 @@ get_net(cp, net, maskflg) prefp = p + 1; } - if ((np = getnetbyname(cp)) != NULL) { - bzero(&sin, sizeof sin); - sin.sin_family = AF_INET; - sin.sin_len = sizeof sin; - sin.sin_addr = inet_makeaddr(np->n_net, 0); - sa = (struct sockaddr *)&sin; - } else if (isxdigit(*cp) || *cp == ':') { + /* + * Check for a numeric address first. We wish to avoid + * possible DNS lookups in getnetbyname(). + */ + if (isxdigit(*cp) || *cp == ':') { memset(&hints, 0, sizeof hints); /* Ensure the mask and the network have the same family. */ if (maskflg && (opt_flags & OP_NET)) @@ -1897,9 +1895,9 @@ get_net(cp, net, maskflg) else hints.ai_family = AF_UNSPEC; hints.ai_flags = AI_NUMERICHOST; - if (getaddrinfo(cp, NULL, &hints, &ai) != 0) - goto fail; - if (ai->ai_family == AF_INET) { + if (getaddrinfo(cp, NULL, &hints, &ai) == 0) + sa = ai->ai_addr; + if (sa != NULL && ai->ai_family == AF_INET) { /* * The address in `cp' is really a network address, so * use inet_network() to re-interpret this correctly. @@ -1913,9 +1911,16 @@ get_net(cp, net, maskflg) fprintf(stderr, "get_net: v4 addr %s\n", inet_ntoa(sin.sin_addr)); sa = (struct sockaddr *)&sin; - } else - sa = ai->ai_addr; - } else + } + } + if (sa == NULL && (np = getnetbyname(cp)) != NULL) { + bzero(&sin, sizeof sin); + sin.sin_family = AF_INET; + sin.sin_len = sizeof sin; + sin.sin_addr = inet_makeaddr(np->n_net, 0); + sa = (struct sockaddr *)&sin; + } + if (sa == NULL) goto fail; if (maskflg) { |