diff options
| -rw-r--r-- | btpd/addrinfo.c | 12 | ||||
| -rw-r--r-- | btpd/btpd.h | 2 | ||||
| -rw-r--r-- | btpd/net.c | 2 |
3 files changed, 7 insertions, 9 deletions
diff --git a/btpd/addrinfo.c b/btpd/addrinfo.c index 8bff8b2..1ea3614 100644 --- a/btpd/addrinfo.c +++ b/btpd/addrinfo.c @@ -11,7 +11,7 @@ struct ai_ctx { void *arg; int cancel; int error; - short port; + uint16_t port; }; BTPDQ_HEAD(ai_ctx_tq, ai_ctx); @@ -21,7 +21,7 @@ static pthread_mutex_t m_aiq_lock; static pthread_cond_t m_aiq_cond; struct ai_ctx * -btpd_addrinfo(const char *node, short port, struct addrinfo *hints, +btpd_addrinfo(const char *node, uint16_t port, struct addrinfo *hints, void (*cb)(void *, int, struct addrinfo *), void *arg) { struct ai_ctx *ctx = btpd_calloc(1, sizeof(*ctx)); @@ -30,8 +30,7 @@ btpd_addrinfo(const char *node, short port, struct addrinfo *hints, ctx->arg = arg; snprintf(ctx->node, sizeof(ctx->node), "%s", node); ctx->port = port; - if (port > 0) - snprintf(ctx->service, sizeof(ctx->service), "%hd", port); + snprintf(ctx->service, sizeof(ctx->service), "%hu", port); pthread_mutex_lock(&m_aiq_lock); BTPDQ_INSERT_TAIL(&m_aiq, ctx, entry); @@ -62,7 +61,6 @@ static void * addrinfo_td(void *arg) { struct ai_ctx *ctx; - char *service; while (1) { pthread_mutex_lock(&m_aiq_lock); while (BTPDQ_EMPTY(&m_aiq)) @@ -71,8 +69,8 @@ addrinfo_td(void *arg) BTPDQ_REMOVE(&m_aiq, ctx, entry); pthread_mutex_unlock(&m_aiq_lock); - service = ctx->port > 0 ? ctx->service : NULL; - ctx->error = getaddrinfo(ctx->node, service, &ctx->hints, &ctx->res); + ctx->error = + getaddrinfo(ctx->node, ctx->service, &ctx->hints, &ctx->res); td_post_begin(); td_post(addrinfo_td_cb, ctx); diff --git a/btpd/btpd.h b/btpd/btpd.h index f28591d..3b7ecc7 100644 --- a/btpd/btpd.h +++ b/btpd/btpd.h @@ -95,7 +95,7 @@ void td_post_end(); #define td_post_begin td_acquire_lock typedef struct ai_ctx * aictx_t; -aictx_t btpd_addrinfo(const char *node, short port, struct addrinfo *hints, +aictx_t btpd_addrinfo(const char *node, uint16_t port, struct addrinfo *hints, void (*cb)(void *, int, struct addrinfo *), void *arg); void btpd_addrinfo_cancel(aictx_t ctx); diff --git a/btpd/net.c b/btpd/net.c index b6f5135..85739b3 100644 --- a/btpd/net.c +++ b/btpd/net.c @@ -695,7 +695,7 @@ net_init(void) hints.ai_flags = AI_ADDRCONFIG | AI_PASSIVE; hints.ai_family = net_af_spec(); hints.ai_socktype = SOCK_STREAM; - snprintf(portstr, sizeof(portstr), "%hd", net_port); + snprintf(portstr, sizeof(portstr), "%hu", net_port); if ((errno = getaddrinfo(NULL, portstr, &hints, &res)) != 0) btpd_err("getaddrinfo failed (%s).\n", gai_strerror(errno)); for (ai = res; ai != NULL; ai = ai->ai_next) { |