1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-07 21:21:31 +00:00

Minor optimization for name resolution: null servname

This commit is contained in:
dmiller
2021-07-22 17:18:29 +00:00
parent 7bf0a7f016
commit d15747db32

View File

@@ -358,6 +358,7 @@ static int resolve_internal(const char *hostname, unsigned short port,
struct addrinfo hints;
struct addrinfo *result;
char portbuf[16];
char *servname = NULL;
int rc;
assert(hostname);
@@ -370,10 +371,13 @@ static int resolve_internal(const char *hostname, unsigned short port,
hints.ai_flags |= addl_flags;
/* Make the port number a string to give to getaddrinfo. */
rc = Snprintf(portbuf, sizeof(portbuf), "%hu", port);
assert(rc >= 0 && (size_t) rc < sizeof(portbuf));
if (port != 0) {
rc = Snprintf(portbuf, sizeof(portbuf), "%hu", port);
assert(rc >= 0 && (size_t) rc < sizeof(portbuf));
servname = portbuf;
}
rc = getaddrinfo(hostname, portbuf, &hints, &result);
rc = getaddrinfo(hostname, servname, &hints, &result);
if (rc != 0)
return rc;
if (result == NULL)