mirror of
https://github.com/nmap/nmap.git
synced 2026-08-04 06:40:48 +00:00
Show gai_strerror in some error messages.
This commit is contained in:
parent
113e0b975f
commit
40eb708922
5 changed files with 57 additions and 31 deletions
|
|
@ -339,8 +339,9 @@ static void initialize_idleproxy(struct idle_proxy_info *proxy, char *proxyName,
|
|||
}
|
||||
|
||||
proxy->host.setHostName(name);
|
||||
if (resolve(name, 0, &ss, &sslen, o.pf()) != 0) {
|
||||
fatal("Could not resolve idle scan zombie host: %s", name);
|
||||
int rc = resolve(name, 0, &ss, &sslen, o.pf());
|
||||
if (rc != 0) {
|
||||
fatal("Could not resolve idle scan zombie host \"%s\": %s", name, gai_strerror(rc));
|
||||
}
|
||||
proxy->host.setTargetSockAddr(&ss, sslen);
|
||||
|
||||
|
|
|
|||
|
|
@ -125,6 +125,7 @@ static void parseproxy(char *str, struct sockaddr_storage *ss, unsigned short de
|
|||
int httpproxy = (defport == DEFAULT_PROXY_PORT);
|
||||
unsigned short portno;
|
||||
size_t sslen;
|
||||
int rc;
|
||||
|
||||
ptr = str;
|
||||
|
||||
|
|
@ -136,8 +137,9 @@ static void parseproxy(char *str, struct sockaddr_storage *ss, unsigned short de
|
|||
else
|
||||
portno = defport;
|
||||
|
||||
if (resolve(ptr, portno, ss, &sslen, o.af) != 0) {
|
||||
loguser("Could not resolve proxy \"%s\".\n", ptr);
|
||||
rc = resolve(ptr, portno, ss, &sslen, o.af);
|
||||
if (rc != 0) {
|
||||
loguser("Could not resolve proxy \"%s\": %s.\n", ptr, gai_strerror(rc));
|
||||
if (o.af == AF_INET6 && httpproxy)
|
||||
loguser("Did you specify the port number? It's required for IPv6.\n");
|
||||
exit(EXIT_FAILURE);
|
||||
|
|
@ -317,8 +319,13 @@ int main(int argc, char *argv[])
|
|||
do {
|
||||
union sockaddr_u addr;
|
||||
size_t sslen;
|
||||
if (resolve(a, 0, &addr.storage, &sslen, AF_INET) != 0)
|
||||
bye("Sorry, could not resolve source route hop %s.", a);
|
||||
int rc;
|
||||
|
||||
rc = resolve(a, 0, &addr.storage, &sslen, AF_INET);
|
||||
if (rc != 0) {
|
||||
bye("Sorry, could not resolve source route hop \"%s\": %s.",
|
||||
a, gai_strerror(rc));
|
||||
}
|
||||
o.srcrtes[o.numsrcrtes] = addr.in.sin_addr;
|
||||
} while (o.numsrcrtes++ <= 8 && (a = strtok(NULL, ",")));
|
||||
if (o.numsrcrtes > 8)
|
||||
|
|
@ -575,11 +582,14 @@ int main(int argc, char *argv[])
|
|||
|
||||
/* Resolve the given source address */
|
||||
if (source) {
|
||||
int rc;
|
||||
|
||||
if (o.listen)
|
||||
bye("-l and -s are incompatible. Specify the address and port to bind to like you would a host to connect to.");
|
||||
|
||||
if (resolve(source, 0, &srcaddr.storage, &srcaddrlen, o.af) != 0)
|
||||
bye("Could not resolve source address %s.", source);
|
||||
rc = resolve(source, 0, &srcaddr.storage, &srcaddrlen, o.af);
|
||||
if (rc != 0)
|
||||
bye("Could not resolve source address \"%s\": %s.", source, gai_strerror(rc));
|
||||
}
|
||||
|
||||
host_list_to_set(&o.allowset, allow_host_list);
|
||||
|
|
@ -594,10 +604,13 @@ int main(int argc, char *argv[])
|
|||
} else {
|
||||
/* Resolve hostname if we're given one */
|
||||
if (strspn(argv[optind], "0123456789") != strlen(argv[optind])) {
|
||||
int rc;
|
||||
|
||||
o.target = argv[optind];
|
||||
/* resolve hostname */
|
||||
if (resolve(o.target, 0, &targetss.storage, &targetsslen, o.af) != 0)
|
||||
bye("Could not resolve hostname %s.", o.target);
|
||||
rc = resolve(o.target, 0, &targetss.storage, &targetsslen, o.af);
|
||||
if (rc != 0)
|
||||
bye("Could not resolve hostname \"%s\": %s.", o.target, gai_strerror(rc));
|
||||
optind++;
|
||||
} else {
|
||||
if (!o.listen)
|
||||
|
|
@ -759,7 +772,7 @@ static int ncat_listen_mode(void)
|
|||
ss_len = sizeof(listenaddrs[num_listenaddrs]);
|
||||
rc = resolve("::", o.portno, &listenaddrs[num_listenaddrs].storage, &ss_len, AF_INET6);
|
||||
if (rc != 0)
|
||||
bye("Failed to resolve default IPv6 address.");
|
||||
bye("Failed to resolve default IPv6 address: %s.", gai_strerror(rc));
|
||||
num_listenaddrs++;
|
||||
}
|
||||
#endif
|
||||
|
|
@ -767,7 +780,7 @@ static int ncat_listen_mode(void)
|
|||
ss_len = sizeof(listenaddrs[num_listenaddrs]);
|
||||
rc = resolve("0.0.0.0", o.portno, &listenaddrs[num_listenaddrs].storage, &ss_len, AF_INET);
|
||||
if (rc != 0)
|
||||
bye("Failed to resolve default IPv4 address.");
|
||||
bye("Failed to resolve default IPv4 address: %s.", gai_strerror(rc));
|
||||
num_listenaddrs++;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -425,7 +425,7 @@ static int handle_connect(struct socket_buffer *client_sock,
|
|||
{
|
||||
union sockaddr_u su;
|
||||
size_t sslen = sizeof(su.storage);
|
||||
int maxfd, s;
|
||||
int maxfd, s, rc;
|
||||
char *line;
|
||||
size_t len;
|
||||
fd_set m, r;
|
||||
|
|
@ -438,9 +438,12 @@ static int handle_connect(struct socket_buffer *client_sock,
|
|||
if (o.debug > 1)
|
||||
logdebug("CONNECT to %s:%hu.\n", request->uri.host, request->uri.port);
|
||||
|
||||
if (resolve(request->uri.host, request->uri.port, &su.storage, &sslen, o.af) != 0) {
|
||||
if (o.debug)
|
||||
logdebug("Can't resolve name %s.\n", request->uri.host);
|
||||
rc = resolve(request->uri.host, request->uri.port, &su.storage, &sslen, o.af);
|
||||
if (rc != 0) {
|
||||
if (o.debug) {
|
||||
logdebug("Can't resolve name \"%s\": %s.\n",
|
||||
request->uri.host, gai_strerror(rc));
|
||||
}
|
||||
return 504;
|
||||
}
|
||||
|
||||
|
|
@ -530,7 +533,7 @@ static int handle_method(struct socket_buffer *client_sock,
|
|||
union sockaddr_u su;
|
||||
size_t sslen = sizeof(su.storage);
|
||||
int code;
|
||||
int s;
|
||||
int s, rc;
|
||||
|
||||
if (strcmp(request->uri.scheme, "http") != 0) {
|
||||
if (o.verbose)
|
||||
|
|
@ -543,9 +546,12 @@ static int handle_method(struct socket_buffer *client_sock,
|
|||
return 400;
|
||||
}
|
||||
|
||||
if (resolve(request->uri.host, request->uri.port, &su.storage, &sslen, o.af) != 0) {
|
||||
if (o.debug)
|
||||
logdebug("Can't resolve name %s:%d.\n", request->uri.host, request->uri.port);
|
||||
rc = resolve(request->uri.host, request->uri.port, &su.storage, &sslen, o.af);
|
||||
if (rc != 0) {
|
||||
if (o.debug) {
|
||||
logdebug("Can't resolve name %s:%d: %s.\n",
|
||||
request->uri.host, request->uri.port, gai_strerror(rc));
|
||||
}
|
||||
return 504;
|
||||
}
|
||||
|
||||
|
|
|
|||
25
nmap.cc
25
nmap.cc
|
|
@ -996,12 +996,11 @@ void parse_options(int argc, char **argv) {
|
|||
/* Try to resolve it */
|
||||
struct sockaddr_in decoytemp;
|
||||
size_t decoytemplen = sizeof(struct sockaddr_in);
|
||||
if (resolve(p, 0, (sockaddr_storage*)&decoytemp, &decoytemplen, AF_INET) == 0) {
|
||||
o.decoys[o.numdecoys] = decoytemp.sin_addr;
|
||||
o.numdecoys++;
|
||||
} else {
|
||||
fatal("Failed to resolve decoy host: %s (must be hostname or IP address)", p);
|
||||
}
|
||||
int rc = resolve(p, 0, (sockaddr_storage*)&decoytemp, &decoytemplen, AF_INET);
|
||||
if (rc != 0)
|
||||
fatal("Failed to resolve decoy host \"%s\": %s", p, gai_strerror(rc));
|
||||
o.decoys[o.numdecoys] = decoytemp.sin_addr;
|
||||
o.numdecoys++;
|
||||
}
|
||||
if (q) {
|
||||
*q = ',';
|
||||
|
|
@ -1338,8 +1337,12 @@ void apply_delayed_options() {
|
|||
size_t sslen;
|
||||
|
||||
if (o.spoofsource) {
|
||||
if (resolve(delayed_options.spoofSource, 0, &ss, &sslen, o.af()) != 0)
|
||||
fatal("Failed to resolve/decode supposed %s source address %s.", (o.af() == AF_INET) ? "IPv4" : "IPv6", delayed_options.spoofSource);
|
||||
int rc = resolve(delayed_options.spoofSource, 0, &ss, &sslen, o.af());
|
||||
if (rc != 0) {
|
||||
fatal("Failed to resolve/decode supposed %s source address \"%s\": %s",
|
||||
(o.af() == AF_INET) ? "IPv4" : "IPv6", delayed_options.spoofSource,
|
||||
gai_strerror(rc));
|
||||
}
|
||||
o.setSourceSockAddr(&ss, sslen);
|
||||
}
|
||||
// After the arguments are fully processed we now make any of the timing
|
||||
|
|
@ -1631,10 +1634,12 @@ int nmap_main(int argc, char *argv[]) {
|
|||
struct sockaddr_storage ss;
|
||||
struct route_nfo rnfo;
|
||||
size_t sslen;
|
||||
int rc;
|
||||
|
||||
dst = route_dst_hosts[i].c_str();
|
||||
if (resolve(dst, 0, &ss, &sslen, o.af()) != 0)
|
||||
fatal("Can't resolve %s.", dst);
|
||||
rc = resolve(dst, 0, &ss, &sslen, o.af());
|
||||
if (rc != 0)
|
||||
fatal("Can't resolve %s: %s.", dst, gai_strerror(rc));
|
||||
|
||||
printf("%s\n", inet_ntop_ez(&ss, sslen));
|
||||
|
||||
|
|
|
|||
|
|
@ -820,7 +820,8 @@ static void add_dns_server(char *ipaddrs) {
|
|||
|
||||
for (hostname = strtok(ipaddrs, " ,"); hostname != NULL; hostname = strtok(NULL, " ,")) {
|
||||
|
||||
if (resolve(hostname, 0, (struct sockaddr_storage *) &addr, &addr_len, PF_UNSPEC) != 0) continue;
|
||||
if (resolve(hostname, 0, (struct sockaddr_storage *) &addr, &addr_len, PF_UNSPEC) != 0)
|
||||
continue;
|
||||
|
||||
for(servI = servs.begin(); servI != servs.end(); servI++) {
|
||||
tpserv = *servI;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue