Переглянути джерело

Fix port type confusion.

Btpd will now be able to use high ports for itself and trackers again.
master
Richard Nyberg 15 роки тому
джерело
коміт
40077b7f74
3 змінених файлів з 7 додано та 9 видалено
  1. +5
    -7
      btpd/addrinfo.c
  2. +1
    -1
      btpd/btpd.h
  3. +1
    -1
      btpd/net.c

+ 5
- 7
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);


+ 1
- 1
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);



+ 1
- 1
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) {


Завантаження…
Відмінити
Зберегти