mirror of
https://github.com/nmap/nmap.git
synced 2025-12-09 22:21:29 +00:00
Minor optimization for name resolution: null servname
This commit is contained in:
@@ -358,6 +358,7 @@ static int resolve_internal(const char *hostname, unsigned short port,
|
|||||||
struct addrinfo hints;
|
struct addrinfo hints;
|
||||||
struct addrinfo *result;
|
struct addrinfo *result;
|
||||||
char portbuf[16];
|
char portbuf[16];
|
||||||
|
char *servname = NULL;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
assert(hostname);
|
assert(hostname);
|
||||||
@@ -370,10 +371,13 @@ static int resolve_internal(const char *hostname, unsigned short port,
|
|||||||
hints.ai_flags |= addl_flags;
|
hints.ai_flags |= addl_flags;
|
||||||
|
|
||||||
/* Make the port number a string to give to getaddrinfo. */
|
/* Make the port number a string to give to getaddrinfo. */
|
||||||
|
if (port != 0) {
|
||||||
rc = Snprintf(portbuf, sizeof(portbuf), "%hu", port);
|
rc = Snprintf(portbuf, sizeof(portbuf), "%hu", port);
|
||||||
assert(rc >= 0 && (size_t) rc < sizeof(portbuf));
|
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)
|
if (rc != 0)
|
||||||
return rc;
|
return rc;
|
||||||
if (result == NULL)
|
if (result == NULL)
|
||||||
|
|||||||
Reference in New Issue
Block a user