1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-30 11:29:01 +00:00

Break out resolve and resolve_numeric.

Besides the confusingness of the nodns argument being negatively
phrased, it had the value 0 in every existing call. Split out the nodns
special case into a separate function resolve_numeric.

This also has the side effect of changing the number of parameters to
the resolve function, which will cause a compile error for any calls I
might have missed changing when I changed the return code meaning in the
previous commit.

Ncat has its own copy of resolve, which obeys the global o.nodns rather
than a parameter. I'm leaving that alone for now. But give it the same
resolve_internal function, and make resolve call it with different flags
depending on the value of o.nodns.
This commit is contained in:
david
2012-09-15 17:56:11 +00:00
parent 0e738370ee
commit 113e0b975f
8 changed files with 81 additions and 41 deletions

View File

@@ -157,15 +157,18 @@ int netutil_error(const char *str, ...)
contain a newline character at the end. */
int parse_ip_options(const char *txt, u8 *data, int datalen, int* firsthopoff, int* lasthopoff, char *errstr, size_t errstrlen);
/* Tries to resolve the given name (or literal IP) into a sockaddr structure.
- Parameter "hostname" is the name to be resolved.
- Parameter "port" sets the port in each returned address structure
(you can safely pass 0 for the port if you don't care)
- Parameter "nodns": If set, it means that the supplied hostname is actually a
numeric IP address. The flag prevents any type of name resolution service
from being called. In 99% of the cases this should be 0.
Returns 0 on success, or a getaddrinfo return code on failure. */
int resolve(const char *hostname, u16 port, int nodns, struct sockaddr_storage *ss, size_t *sslen, int af);
/* Resolves the given hostname or IP address with getaddrinfo, and stores the
first result (if any) in *ss and *sslen. The value of port will be set in the
appropriate place in *ss; set to 0 if you don't care. af may be AF_UNSPEC, in
which case getaddrinfo may return e.g. both IPv4 and IPv6 results; which one
is first depends on the system configuration. Returns 0 on success, or a
getaddrinfo return code (suitable for passing to gai_strerror) on failure.
*ss and *sslen are always defined when this function returns 0. */
int resolve(const char *hostname, u16 port, struct sockaddr_storage *ss, size_t *sslen, int af);
/* As resolve, but do not do DNS resolution of hostnames; the first argument
must be the string representation of a numeric IP address. */
int resolve_numeric(const char *ip, u16 port, struct sockaddr_storage *ss, size_t *sslen, int af);
/*
* Returns 1 if this is a reserved IP address, where "reserved" means