From fd5b0a77aec896ba8560ec4f7f6111489605f754 Mon Sep 17 00:00:00 2001 From: Marcel Poul Date: Mon, 5 Dec 2011 23:50:08 +0000 Subject: [PATCH] use user defined port in canl_io_accept() --- emi.canl.canl-c/src/canl.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/emi.canl.canl-c/src/canl.c b/emi.canl.canl-c/src/canl.c index b9e1f42..5af587f 100644 --- a/emi.canl.canl-c/src/canl.c +++ b/emi.canl.canl-c/src/canl.c @@ -211,6 +211,7 @@ end: return err; } +/*TODO select + timeout, EINTR!!!, remember peer IP and other info */ int canl_io_accept(canl_ctx cc, canl_io_handler io, int port, int flags, cred_handler ch, struct timeval *timeout, canl_io_handler *new_io) @@ -219,11 +220,11 @@ int canl_io_accept(canl_ctx cc, canl_io_handler io, int port, io_handler *io_cc = (io_handler*) io; glb_ctx *glb_cc = (glb_ctx*) cc; io_handler **io_new_cc = (io_handler**) new_io; + char str_port[8]; struct addrinfo hints, *servinfo, *p; socklen_t sin_size; int yes=1; - char * PORT = "4321"; //TODO for testing purposes only /*check cc and io*/ if (!glb_cc) @@ -244,7 +245,10 @@ int canl_io_accept(canl_ctx cc, canl_io_handler io, int port, hints.ai_socktype = SOCK_STREAM; hints.ai_flags = AI_PASSIVE; // use my IP - if ((err = getaddrinfo(NULL, PORT, &hints, &servinfo)) != 0) { + if (snprintf(str_port, 8, "%d", port) < 0) + return -1; + + if ((err = getaddrinfo(NULL, str_port, &hints, &servinfo)) != 0) { update_error(glb_cc, "getaddrinfo: %s\n", gai_strerror(err)); /*TODO what kind of error return?, getaddrinfo returns its own error codes*/ -- 1.8.2.3