diff --git a/netcon/NetconEthernetTap.cpp b/netcon/NetconEthernetTap.cpp index 11c877cc0..fc37ee87c 100644 --- a/netcon/NetconEthernetTap.cpp +++ b/netcon/NetconEthernetTap.cpp @@ -628,7 +628,10 @@ err_t NetconEthernetTap::nc_recved(void *arg, struct tcp_pcb *tpcb, struct pbuf void NetconEthernetTap::nc_err(void *arg, err_t err) { Larg *l = (Larg*)arg; - fprintf(stderr, "larg = %x, nc_err() = %d\n", l, err); + //fprintf(stderr, "larg = %x, nc_err() = %d\n", l, err); + + if(!l->conn) + fprintf(stderr, "nc_err(): Connection is NULL!\n"); if(l->conn) { switch(err) @@ -636,38 +639,48 @@ void NetconEthernetTap::nc_err(void *arg, err_t err) // FIXME: Check if connection is pending first? case ERR_MEM: + fprintf(stderr, "nc_err(): ERR_MEM->ENOMEM\n"); l->tap->send_return_value(l->conn, -1, ENOMEM); break; case ERR_BUF: + fprintf(stderr, "nc_err(): ERR_BUF->ENOBUFS\n"); l->tap->send_return_value(l->conn, -1, ENOBUFS); break; case ERR_TIMEOUT: + fprintf(stderr, "nc_err(): ERR_TIMEOUT->ETIMEDOUT\n"); l->tap->send_return_value(l->conn, -1, ETIMEDOUT); break; case ERR_RTE: + fprintf(stderr, "nc_err(): ERR_RTE->ENETUNREACH\n"); l->tap->send_return_value(l->conn, -1, ENETUNREACH); break; case ERR_INPROGRESS: + fprintf(stderr, "nc_err(): ERR_INPROGRESS->EINPROGRESS\n"); l->tap->send_return_value(l->conn, -1, EINPROGRESS); break; case ERR_VAL: + fprintf(stderr, "nc_err(): ERR_VAL->EINVAL\n"); l->tap->send_return_value(l->conn, -1, EINVAL); break; case ERR_WOULDBLOCK: + fprintf(stderr, "nc_err(): ERR_WOULDBLOCK->EWOULDBLOCK\n"); l->tap->send_return_value(l->conn, -1, EWOULDBLOCK); break; case ERR_USE: + fprintf(stderr, "nc_err(): ERR_USE->EADDRINUSE\n"); l->tap->send_return_value(l->conn, -1, EADDRINUSE); break; case ERR_ISCONN: + fprintf(stderr, "nc_err(): ERR_ISCONN->EISCONN\n"); l->tap->send_return_value(l->conn, -1, EISCONN); break; + case ERR_ABRT: + fprintf(stderr, "nc_err(): ERR_ABRT->ETIMEDOUT\n"); // FIXME: Correct? + l->tap->send_return_value(l->conn, -1, ETIMEDOUT); + break; // FIXME: Below are errors which don't have a standard errno correlate - case ERR_ABRT: - l->tap->send_return_value(l->conn, -1, -1); - break; case ERR_RST: l->tap->send_return_value(l->conn, -1, -1); break; diff --git a/netcon/intercept.c b/netcon/intercept.c index a2d6e31a4..daf88f6a2 100755 --- a/netcon/intercept.c +++ b/netcon/intercept.c @@ -514,6 +514,7 @@ void sock_domain_to_str(int domain) int socket(SOCKET_SIG) { + int err; #ifdef CHECKS /* Check that type makes sense */ int flags = socket_type & ~SOCK_TYPE_MASK; @@ -572,13 +573,16 @@ int socket(SOCKET_SIG) } else { // Try to read retval+errno since we RXed a bad fd dwr("Error, service sent bad fd.\n"); - return get_retval(); + err = get_retval(); + pthread_mutex_unlock(&lock); + return err; } } else { dwr("Error while receiving new FD.\n"); + err = get_retval(); pthread_mutex_unlock(&lock); - return get_retval(); + return err; } #endif } @@ -591,7 +595,7 @@ int socket(SOCKET_SIG) connect() intercept function */ int connect(CONNECT_SIG) { - + int err; /* FIXME: Check that address is in user space, return EFAULT ? */ #ifdef DUMMY @@ -635,23 +639,9 @@ int connect(CONNECT_SIG) memcpy(&cmd[1], &rpc_st, sizeof(struct connect_st)); pthread_mutex_lock(&lock); send_command(fdret_sock, cmd); - - if(fdret_sock >= 0) { - int retval; - char mynewbuf[BUF_SZ]; - memset(&mynewbuf, '\0', sizeof(mynewbuf)); - int n_read = read(fdret_sock, &mynewbuf, sizeof(mynewbuf)); - if(n_read > 0) { - memcpy(&retval, &mynewbuf[1], sizeof(int)); - pthread_mutex_unlock(&lock); - return retval; - } - else { - pthread_mutex_unlock(&lock); - dwr("unable to read connect: return value\n"); - } - } - return -1; + err = get_retval(); + pthread_mutex_unlock(&lock); + return err; #endif } @@ -696,6 +686,7 @@ int poll(POLL_SIG) bind() intercept function */ int bind(BIND_SIG) { + int err; #ifdef DUMMY dwr("bind(%d)\n", sockfd); return realbind(sockfd, addr, addrlen); @@ -735,9 +726,10 @@ int bind(BIND_SIG) memcpy(&cmd[1], &rpc_st, sizeof(struct bind_st)); pthread_mutex_lock(&lock); send_command(fdret_sock, cmd); + err = get_retval(); pthread_mutex_unlock(&lock); errno = ERR_OK; - return get_retval(); + return err; #endif } @@ -842,6 +834,7 @@ int accept(ACCEPT_SIG) listen() intercept function */ int listen(LISTEN_SIG) { + int err; /* FIXME: Check that this socket supports listen(), return EOPNOTSUPP */ /* FIXME: Check that the provided fd is a socket, return ENOTSOCK */ @@ -865,8 +858,9 @@ int listen(LISTEN_SIG) memcpy(&cmd[1], &rpc_st, sizeof(struct listen_st)); pthread_mutex_lock(&lock); send_command(fdret_sock, cmd); + err = get_retval(); pthread_mutex_unlock(&lock); errno = ERR_OK; - return get_retval(); + return err; #endif } diff --git a/netcon/libintercept.so.1.0 b/netcon/libintercept.so.1.0 index d0b5ffda6..4d8b2f198 100755 Binary files a/netcon/libintercept.so.1.0 and b/netcon/libintercept.so.1.0 differ