From: t3sserakt Date: Fri, 24 Apr 2020 12:21:22 +0000 (+0200) Subject: fixed warnings X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=bd08a7d71ff2bd2c424869dedceb2af2215d3ef2;p=oweals%2Fgnunet.git fixed warnings --- diff --git a/src/transport/gnunet-communicator-tcp.c b/src/transport/gnunet-communicator-tcp.c index b9d023e54..bf1effe3d 100644 --- a/src/transport/gnunet-communicator-tcp.c +++ b/src/transport/gnunet-communicator-tcp.c @@ -43,7 +43,7 @@ #include "gnunet_ats_transport_service.h" #include "transport.h" #include "gnunet_transport_communication_service.h" - +#include "gnunet_resolver_service.h" /** * How long do we believe our addresses to remain up (before * the other peer should revalidate). @@ -1103,13 +1103,13 @@ queue_read (void *cls) } static struct sockaddr * -tcp_address_to_sockaddr_port_only (const char *bindto, unsigned int port, socklen_t *sock_len) +tcp_address_to_sockaddr_port_only (const char *bindto, unsigned int *port, socklen_t *sock_len) { struct sockaddr *in; /* interpreting value as just a PORT number */ - if (port > UINT16_MAX) + if (*port > UINT16_MAX) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "BINDTO specification `%s' invalid: value too large for port\n", @@ -1126,7 +1126,7 @@ tcp_address_to_sockaddr_port_only (const char *bindto, unsigned int port, sockle i4 = GNUNET_malloc (sizeof(struct sockaddr_in)); i4->sin_family = AF_INET; - i4->sin_port = htons ((uint16_t) port); + i4->sin_port = htons ((uint16_t) *port); #if HAVE_SOCKADDR_IN_SIN_LEN i4->sin_len = sizeof(sizeof(struct sockaddr_in)); #endif @@ -1139,7 +1139,7 @@ tcp_address_to_sockaddr_port_only (const char *bindto, unsigned int port, sockle i6 = GNUNET_malloc (sizeof(struct sockaddr_in6)); i6->sin6_family = AF_INET6; - i6->sin6_port = htons ((uint16_t) port); + i6->sin6_port = htons ((uint16_t) *port); #if HAVE_SOCKADDR_IN_SIN_LEN i6->sin6_len = sizeof(sizeof(struct sockaddr_in6)); #endif @@ -1153,7 +1153,7 @@ static char * extract_ipv6_address (char *cp) { - const char *start; + char *start; start = cp; if (('[' == *cp) && (']' == cp[strlen (cp) - 1])) @@ -1170,10 +1170,11 @@ extract_port(char *colon) { unsigned int port; char dummy[2]; + if (NULL != colon) - { + { /* interpet value after colon as port */ - *colon = '\0'; + //colon = '\0'; colon++; if (1 == sscanf (colon, "%u%1s", &port, dummy)) { @@ -1181,10 +1182,10 @@ extract_port(char *colon) if (port > UINT16_MAX) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Port `%s' invalid: value too large for port\n", + "Port `%u' invalid: value too large for port\n", port); //GNUNET_free (cp); - return NULL; + return 0; } } else @@ -1193,7 +1194,7 @@ extract_port(char *colon) GNUNET_ERROR_TYPE_ERROR, "BINDTO specification invalid: last ':' not followed by number\n"); //GNUNET_free (cp); - return NULL; + return 0; } } else @@ -1209,10 +1210,10 @@ static struct sockaddr * tcp_address_to_sockaddr_numeric (socklen_t *sock_len, struct sockaddr_in v4, struct sockaddr_in6 v6, char *colon) { - unsigned int port; + unsigned int *port; struct sockaddr *in; - port = extract_port(colon); + *port = extract_port(colon); if (NULL == port) return NULL; @@ -1223,13 +1224,12 @@ tcp_address_to_sockaddr_numeric (socklen_t *sock_len, struct sockaddr_in v4, str if (NULL != &v4.sin_addr) { v4.sin_family = AF_INET; - v4.sin_port = htons ((uint16_t) port); + v4.sin_port = htons ((uint16_t) *port); #if HAVE_SOCKADDR_IN_SIN_LEN v4.sin_len = sizeof(struct sockaddr_in); #endif in = GNUNET_memdup (&v4, sizeof(v4)); *sock_len = sizeof(v4); - //GNUNET_free (cp); return in; } } @@ -1239,17 +1239,15 @@ tcp_address_to_sockaddr_numeric (socklen_t *sock_len, struct sockaddr_in v4, str if (NULL != &v6.sin6_addr) { v6.sin6_family = AF_INET6; - v6.sin6_port = htons ((uint16_t) port); + v6.sin6_port = htons ((uint16_t) *port); #if HAVE_SOCKADDR_IN_SIN_LEN v6.sin6_len = sizeof(sizeof(struct sockaddr_in6)); #endif in = GNUNET_memdup (&v6, sizeof(v6)); *sock_len = sizeof(v6); - //GNUNET_free (cp); return in; } } - //GNUNET_free (cp); return NULL; } @@ -1264,7 +1262,7 @@ static struct sockaddr * tcp_address_to_sockaddr (const char *bindto, socklen_t *sock_len) { struct sockaddr *in; - unsigned int port; + unsigned int *port; char dummy[2]; char *colon; char *cp; @@ -1276,7 +1274,7 @@ tcp_address_to_sockaddr (const char *bindto, socklen_t *sock_len) cp = GNUNET_strdup (bindto); start = extract_ipv6_address (cp); - if (1 == sscanf (bindto, "%u%1s", &port, dummy)) + if (1 == sscanf (bindto, "%u%1s", port, dummy)) { in = tcp_address_to_sockaddr_port_only (bindto, port, sock_len); } @@ -1285,6 +1283,7 @@ tcp_address_to_sockaddr (const char *bindto, socklen_t *sock_len) colon = strrchr (cp, ':'); in = tcp_address_to_sockaddr_numeric (&in_len, v4, v6, colon); } + return in; } @@ -1956,29 +1955,34 @@ queue_read_kx (void *cls) * invalid */ static int -mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, - struct GNUNET_TRANSPORT_CommunicatorHandle *ch, - const struct GNUNET_TRANSPORT_CreateQueue *cq) +mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address) { struct Queue *queue; const char *path; struct sockaddr *in; socklen_t in_len; struct GNUNET_NETWORK_Handle *sock; - const char *addr = (const char *) &cq[1]; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Connecting to %s\n", addr); - if (0 != strncmp (addr, + "Connecting to %s\n", address); + if (0 != strncmp (address, COMMUNICATOR_ADDRESS_PREFIX "-", strlen (COMMUNICATOR_ADDRESS_PREFIX "-"))) { GNUNET_break_op (0); return GNUNET_SYSERR; } - path = &addr[strlen (COMMUNICATOR_ADDRESS_PREFIX "-")]; + path = &address[strlen (COMMUNICATOR_ADDRESS_PREFIX "-")]; in = tcp_address_to_sockaddr (path, &in_len); + if (NULL == in) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to setup TCP socket address\n"); + return GNUNET_SYSERR; + } + + sock = GNUNET_NETWORK_socket_create (in->sa_family, SOCK_STREAM, IPPROTO_TCP); if (NULL == sock) { @@ -1994,7 +1998,7 @@ mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "connect to `%s' failed: %s", - addr, + address, strerror (errno)); GNUNET_NETWORK_socket_close (sock); GNUNET_free (in); @@ -2167,7 +2171,9 @@ nat_address_cb (void *cls, } static void -init_own_socket (void *cls, struct sockaddr *resolved_in, socklen_t in_len) +init_own_socket (void *cls, + const struct sockaddr *addr, + socklen_t in_len) { struct sockaddr *in; @@ -2175,65 +2181,73 @@ init_own_socket (void *cls, struct sockaddr *resolved_in, socklen_t in_len) socklen_t sto_len; struct sockaddr_in *v4; struct sockaddr_in6 *v6; - char ipstr[INET6_ADDRSTRLEN]; - unsigned int port = cls; - if (NULL == resolved_in) + unsigned int *port = cls; + + char out_string [128]; + snprintf(out_string, 128, "%u", *port); + + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Setup TCP socket on port %s\n", + out_string); + + if (NULL == addr) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to setup TCP socket address\n"); - //TODO Where do we cancel the request - //GNUNET_RESOLVER_request_cancel (resolve_request_handle); - //TODO check where to free after moving code around - //GNUNET_free (bindto); + "Failed to setup TCP socket address %s on port %s\n", + GNUNET_a2s (addr, in_len), + out_string); return; } - inet_ntop(resolved_in->sa_family, resolved_in, ipstr, sizeof(ipstr)); - + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "address %s\n", + GNUNET_a2s (addr, in_len)); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "resolved address %s\n", - ipstr); + "address %s\n", + GNUNET_a2s (addr, in_len)); listen_sock = - GNUNET_NETWORK_socket_create (resolved_in->sa_family, SOCK_STREAM, IPPROTO_TCP); + GNUNET_NETWORK_socket_create (addr->sa_family, SOCK_STREAM, IPPROTO_TCP); if (NULL == listen_sock) { GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket"); - //GNUNET_RESOLVER_request_cancel (resolve_request_handle); - GNUNET_free (in); - //GNUNET_free (bindto); + GNUNET_free ((struct sockaddr *) addr); return; } - if (AF_INET == resolved_in->sa_family) + if (AF_INET == addr->sa_family) { - v4 = GNUNET_new (struct sockaddr_in); + v4 = (struct sockaddr_in *)addr; v4->sin_family = AF_INET; - v4->sin_port = htons ((uint16_t) port); + v4->sin_port = htons ((uint16_t) *port); #if HAVE_SOCKADDR_IN_SIN_LEN v4->sin_len = sizeof(struct sockaddr_in); #endif in = GNUNET_memdup (v4, sizeof(v4)); - }else if (AF_INET6 == in->sa_family) + GNUNET_free (v4); + }else if (AF_INET6 == addr->sa_family) { - v6 = GNUNET_new (struct sockaddr_in6); + v6 = (struct sockaddr_in6 *)addr; v6->sin6_family = AF_INET6; - v6->sin6_port = htons ((uint16_t) port); + v6->sin6_port = htons ((uint16_t) *port); #if HAVE_SOCKADDR_IN_SIN_LEN v6->sin6_len = sizeof(sizeof(struct sockaddr_in6)); #endif in = GNUNET_memdup (v6, sizeof(v6)); + GNUNET_free (v6); } + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "address %s\n", + GNUNET_a2s (in, in_len)); + if (GNUNET_OK != GNUNET_NETWORK_socket_bind (listen_sock, in, in_len)) { - //GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "bind", bindto); - //GNUNET_RESOLVER_request_cancel (resolve_request_handle); + GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind"); GNUNET_NETWORK_socket_close (listen_sock); listen_sock = NULL; GNUNET_free (in); - //GNUNET_free (bindto); return; } if (GNUNET_OK != @@ -2245,7 +2259,6 @@ init_own_socket (void *cls, struct sockaddr *resolved_in, socklen_t in_len) GNUNET_NETWORK_socket_close (listen_sock); listen_sock = NULL; GNUNET_free (in); - //GNUNET_free (bindto); } /* We might have bound to port 0, allowing the OS to figure it out; thus, get the real IN-address from the socket */ @@ -2300,6 +2313,8 @@ init_own_socket (void *cls, struct sockaddr *resolved_in, socklen_t in_len) GNUNET_SCHEDULER_shutdown (); return; } + //TODO Shall we register all addresses the resolver sends us. Them we have + //to call GNUNET_NAT_register, when the resolver signals resolving ended. nat = GNUNET_NAT_register (cfg, COMMUNICATOR_CONFIG_SECTION, IPPROTO_TCP, @@ -2309,7 +2324,9 @@ init_own_socket (void *cls, struct sockaddr *resolved_in, socklen_t in_len) &nat_address_cb, NULL /* FIXME: support reversal: #5529 */, NULL /* closure */); - + //TODO Remove this, if we like to handle more then one address. + if (NULL != resolve_request_handle) + GNUNET_RESOLVER_request_cancel (resolve_request_handle); } /** @@ -2373,30 +2390,29 @@ run (void *cls, if (1 == sscanf (bindto, "%u%1s", &port, dummy)) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "We think it is port only\n"); - in = tcp_address_to_sockaddr_port_only (bindto, port, &in_len); - init_own_socket (bindto, &in, &in_len); + in = tcp_address_to_sockaddr_port_only (bindto, &port, &in_len); + init_own_socket (&port, in, in_len); } else if (1 == inet_pton (AF_INET, cp, &v4.sin_addr) || 1 == inet_pton (AF_INET6, start, &v6.sin6_addr)) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "We think it is address and port\n"); colon = strrchr (cp, ':'); - in = tcp_address_to_sockaddr_numeric (&in_len, v4, v6, &colon); - init_own_socket (bindto, &in, &in_len); + port = extract_port(colon); + in = tcp_address_to_sockaddr_numeric (&in_len, v4, v6, colon); + init_own_socket (&port, in, in_len); }else { - colon = strrchr (cp, ':'); + + colon = strrchr (cp, ':');; port = extract_port(colon); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "We try to resolve\n"); + printf("%u\n", port); resolve_request_handle = GNUNET_RESOLVER_ip_get (cp, AF_UNSPEC, GNUNET_TIME_UNIT_MINUTES, &init_own_socket, - port); + &port); } + GNUNET_free (bindto); + GNUNET_free (cp); } diff --git a/src/transport/test_communicator_tcp_basic_peer1.conf b/src/transport/test_communicator_tcp_basic_peer1.conf index fc08af1ee..6bd9fbd57 100644 --- a/src/transport/test_communicator_tcp_basic_peer1.conf +++ b/src/transport/test_communicator_tcp_basic_peer1.conf @@ -24,7 +24,7 @@ ENABLE_IPSCAN = YES UNIXPATH = $GNUNET_RUNTIME_DIR/test_gnunet-communicator-unix_1.sock [communicator-tcp] -BINDTO = 60002 +BINDTO = www.google.com:60002 DISABLE_V6 = YES [communicator-udp]