Skip to content

Commit

Permalink
Fix port type confusion.
Browse files Browse the repository at this point in the history
Btpd will now be able to use high ports for itself and trackers again.
  • Loading branch information
rmn64k committed Feb 3, 2009
1 parent 747c80f commit 40077b7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
12 changes: 5 additions & 7 deletions btpd/addrinfo.c
Expand Up @@ -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);
Expand All @@ -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));
Expand All @@ -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);
Expand Down Expand Up @@ -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))
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion btpd/btpd.h
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion btpd/net.c
Expand Up @@ -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) {
Expand Down

0 comments on commit 40077b7

Please sign in to comment.