- char buf[65536];
- ssize_t have;
- struct in_addr source_ip;
- struct ip_header ip_pkt;
- struct icmp_ttl_exceeded_header icmp_ttl;
- struct icmp_echo_header icmp_echo;
- struct udp_header udp_pkt;
- size_t off;
- uint16_t port;
-
- have = read (icmpsock, buf, sizeof (buf));
- if (-1 == have)
- {
- fprintf (stderr,
- "Error reading raw socket: %s\n",
- strerror (errno));
- return;
- }
-#if VERBOSE
- fprintf (stderr,
- "Received message of %u bytes\n",
- (unsigned int) have);
-#endif
- if (have < (ssize_t) (sizeof (struct ip_header) + sizeof (struct icmp_ttl_exceeded_header) + sizeof (struct ip_header)))
- {
- /* malformed */
- return;
- }
- off = 0;
- memcpy (&ip_pkt,
- &buf[off],
- sizeof (struct ip_header));
- off += sizeof (struct ip_header);
- memcpy(&source_ip,
- &ip_pkt.src_ip,
- sizeof (source_ip));
- memcpy (&icmp_ttl,
- &buf[off],
- sizeof (struct icmp_ttl_exceeded_header));
- off += sizeof (struct icmp_ttl_exceeded_header);
- if ( (ICMP_TIME_EXCEEDED != icmp_ttl.type) ||
- (0 != icmp_ttl.code) )
- {
- /* different type than what we want */
- return;
- }
- /* skip 2nd IP header */
- memcpy (&ip_pkt,
- &buf[off],
- sizeof (struct ip_header));
- off += sizeof (struct ip_header);
-
- switch (ip_pkt.proto)
- {
- case IPPROTO_ICMP:
- if (have != (sizeof (struct ip_header) * 2 +
- sizeof (struct icmp_ttl_exceeded_header) +
- sizeof (struct icmp_echo_header)) )
- {
- /* malformed */
- return;
- }
- /* grab ICMP ECHO content */
- memcpy (&icmp_echo,
- &buf[off],
- sizeof (struct icmp_echo_header));
- port = (uint16_t) ntohl (icmp_echo.reserved);
- break;
- case IPPROTO_UDP:
- if (have != (sizeof (struct ip_header) * 2 +
- sizeof (struct icmp_ttl_exceeded_header) +
- sizeof (struct udp_header)) )
- {
- /* malformed */
- return;
- }
- /* grab UDP content */
- memcpy (&udp_pkt,
- &buf[off],
- sizeof (struct udp_header));
- port = ntohs (udp_pkt.length);
- break;
- default:
- /* different type than what we want */
- return;
- }
-
- if (port == 0)
- fprintf (stdout,
- "%s\n",
- inet_ntop (AF_INET,
- &source_ip,
- buf,
- sizeof (buf)));
+ const struct GNUNET_NAT_TestMessage *tm;
+ uint16_t dport;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received test request\n");
+ tm = (const struct GNUNET_NAT_TestMessage *) msg;
+ dport = ntohs (tm->dport);
+ if (0 == dport)
+ try_anat (tm->dst_ipv4,
+ ntohs (tm->data),
+ (int) ntohl (tm->is_tcp));
+ else if (GNUNET_YES == ntohl (tm->is_tcp))
+ try_send_tcp (tm->dst_ipv4,
+ dport,
+ tm->data);