From: Christian Grothoff Date: Thu, 4 Feb 2010 09:44:21 +0000 (+0000) Subject: fixes X-Git-Tag: initial-import-from-subversion-38251~22802 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=e53e1c7834c4df3fd43971e9eb2113ce73fd9a52;p=oweals%2Fgnunet.git fixes --- diff --git a/src/transport/gnunet-nat-server.c b/src/transport/gnunet-nat-server.c index 88674fd2c..11e4e905a 100644 --- a/src/transport/gnunet-nat-server.c +++ b/src/transport/gnunet-nat-server.c @@ -118,6 +118,8 @@ static uint16_t udpports[NUM_UDP_PORTS]; static int icmpsock; +static int rawsock; + static struct in_addr dummy; @@ -284,7 +286,7 @@ send_icmp (const struct in_addr *my_ip, memset (&dst, 0, sizeof (dst)); dst.sin_family = AF_INET; dst.sin_addr = *other; - err = sendto(icmpsock, + err = sendto(rawsock, packet, off, 0, (struct sockaddr*)&dst, @@ -354,12 +356,22 @@ process_icmp_response (const struct in_addr *my_ip, off += sizeof (struct udp_packet); /* If not ICMP and not TTL exceeded */ + if ( (ip_pkt.proto == IPPROTO_ICMP) && + (icmp_pkt.type == ICMP_DEST_UNREACH) && + (icmp_pkt.code == ICMP_HOST_UNREACH) ) + { + /* this is what is normal due to our UDP traffic */ + return; + } if ( (ip_pkt.proto != IPPROTO_ICMP) || (icmp_pkt.type != ICMP_TIME_EXCEEDED) || (icmp_pkt.code != ICMP_NET_UNREACH) ) { fprintf (stderr, - "Received unexpected ICMP message contents, ignoring\n"); + "Received unexpected ICMP message contents (%u, %u, %u), ignoring\n", + ip_pkt.proto, + icmp_pkt.type, + icmp_pkt.code); return; } memcpy(&sip, &ip_pkt.src_ip, sizeof (sip)); @@ -391,11 +403,37 @@ process_icmp_response (const struct in_addr *my_ip, static int make_icmp_socket () +{ + int ret; + + ret = socket (AF_INET, SOCK_RAW, IPPROTO_ICMP); + if (-1 == ret) + { + fprintf (stderr, + "Error opening RAW socket: %s\n", + strerror (errno)); + return -1; + } + if (ret >= FD_SETSIZE) + { + fprintf (stderr, + "Socket number too large (%d > %u)\n", + ret, + (unsigned int) FD_SETSIZE); + close (ret); + return -1; + } + return ret; +} + + +static int +make_raw_socket () { const int one = 1; int ret; - ret = socket (AF_INET, SOCK_RAW, 0); + ret = socket (AF_INET, SOCK_RAW, IPPROTO_RAW); if (-1 == ret) { fprintf (stderr, @@ -454,8 +492,14 @@ main (int argc, char *const *argv) dst.sin_family = AF_INET; dst.sin_port = htons (NAT_TRAV_PORT); dst.sin_addr = dummy; + if (-1 == (icmpsock = make_icmp_socket())) return 1; + if (-1 == (rawsock = make_raw_socket())) + { + close (icmpsock); + return 1; + } for (i=0;i