From d319f8bf56aa140baacf687f2d63430542ab1694 Mon Sep 17 00:00:00 2001 From: david Date: Sat, 15 Sep 2012 17:56:16 +0000 Subject: [PATCH] Uniformity and style in resolve functions. --- libnetutil/netutil.cc | 13 ++++++++----- libnetutil/netutil.h | 6 ++++-- ncat/ncat_core.c | 5 +++-- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/libnetutil/netutil.cc b/libnetutil/netutil.cc index e2efd9848..d7126d403 100644 --- a/libnetutil/netutil.cc +++ b/libnetutil/netutil.cc @@ -376,12 +376,12 @@ after: /* Internal helper for resolve and resolve_numeric. addl_flags is ored into hints.ai_flags, so you can add AI_NUMERICHOST. */ -static int resolve_internal(const char *hostname, u16 port, +static int resolve_internal(const char *hostname, unsigned short port, struct sockaddr_storage *ss, size_t *sslen, int af, int addl_flags) { struct addrinfo hints; struct addrinfo *result; char portbuf[16]; - size_t rc=0; + int rc; assert(hostname); assert(ss); @@ -394,7 +394,7 @@ static int resolve_internal(const char *hostname, u16 port, /* Make the port number a string to give to getaddrinfo. */ rc = Snprintf(portbuf, sizeof(portbuf), "%hu", port); - assert(rc >= 0 && rc < sizeof(portbuf)); + assert(rc >= 0 && (size_t) rc < sizeof(portbuf)); rc = getaddrinfo(hostname, portbuf, &hints, &result); if (rc != 0) @@ -405,6 +405,7 @@ static int resolve_internal(const char *hostname, u16 port, *sslen = result->ai_addrlen; memcpy(ss, result->ai_addr, *sslen); freeaddrinfo(result); + return 0; } @@ -415,13 +416,15 @@ static int resolve_internal(const char *hostname, u16 port, 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) { +int resolve(const char *hostname, unsigned short port, + struct sockaddr_storage *ss, size_t *sslen, int af) { return resolve_internal(hostname, port, ss, sslen, af, 0); } /* 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) { +int resolve_numeric(const char *ip, unsigned short port, + struct sockaddr_storage *ss, size_t *sslen, int af) { return resolve_internal(ip, port, ss, sslen, af, AI_NUMERICHOST); } diff --git a/libnetutil/netutil.h b/libnetutil/netutil.h index 47eb114fb..76ca95498 100644 --- a/libnetutil/netutil.h +++ b/libnetutil/netutil.h @@ -164,11 +164,13 @@ int parse_ip_options(const char *txt, u8 *data, int datalen, int* firsthopoff, i 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); +int resolve(const char *hostname, unsigned short 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); +int resolve_numeric(const char *ip, unsigned short port, + struct sockaddr_storage *ss, size_t *sslen, int af); /* * Returns 1 if this is a reserved IP address, where "reserved" means diff --git a/ncat/ncat_core.c b/ncat/ncat_core.c index e5afa056a..ae43ee5d7 100644 --- a/ncat/ncat_core.c +++ b/ncat/ncat_core.c @@ -188,7 +188,7 @@ static int resolve_internal(const char *hostname, unsigned short port, struct addrinfo hints; struct addrinfo *result; char portbuf[16]; - size_t rc=0; + int rc; assert(hostname); assert(ss); @@ -201,7 +201,7 @@ static int resolve_internal(const char *hostname, unsigned short port, /* Make the port number a string to give to getaddrinfo. */ rc = Snprintf(portbuf, sizeof(portbuf), "%hu", port); - assert(rc >= 0 && rc < sizeof(portbuf)); + assert(rc >= 0 && (size_t) rc < sizeof(portbuf)); rc = getaddrinfo(hostname, portbuf, &hints, &result); if (rc != 0) @@ -212,6 +212,7 @@ static int resolve_internal(const char *hostname, unsigned short port, *sslen = result->ai_addrlen; memcpy(ss, result->ai_addr, *sslen); freeaddrinfo(result); + return 0; }