48#include "gnunet_private_config.h"
53#include <sys/socket.h>
55#include <sys/select.h>
65#include <netinet/ip.h>
66#include <netinet/ip_icmp.h>
67#include <netinet/in.h>
70#ifndef ICMP_TIME_EXCEEDED
71#define ICMP_TIME_EXCEEDED 11
83#define GNUNET_memcpy(dst, src, n) do { if (0 != n) { (void) memcpy (dst, src, \
100#define DUMMY_IP "192.0.2.86"
105#define NAT_TRAV_PORT 22225
110#define ICMP_SEND_FREQUENCY_MS 500
245 for (i = 0; i < bytes / 2; i++)
248 sum = htons (0xffff -
sum);
264 struct sockaddr_in dst;
271 ip_pkt.
pkt_len = htons (
sizeof(packet));
274 ip_pkt.
ttl = IPDEFTTL;
275 ip_pkt.
proto = IPPROTO_ICMP;
277 ip_pkt.
src_ip = my_ip->s_addr;
287 icmp_echo.
type = ICMP_ECHO;
293 ((uint16_t *) &icmp_echo,
300 memset (&dst, 0,
sizeof(dst));
301 dst.sin_family = AF_INET;
302#if HAVE_SOCKADDR_IN_SIN_LEN
303 dst.sin_len =
sizeof(
struct sockaddr_in);
305 dst.sin_addr =
dummy;
310 (
struct sockaddr *) &dst,
316 "sendto failed: %s\n",
320 else if (
sizeof(packet) != err)
323 "Error: partial send of ICMP message\n");
334 struct sockaddr_in dst;
337 memset (&dst, 0,
sizeof(dst));
338 dst.sin_family = AF_INET;
339#if HAVE_SOCKADDR_IN_SIN_LEN
340 dst.sin_len =
sizeof(
struct sockaddr_in);
342 dst.sin_addr =
dummy;
348 (
struct sockaddr *) &dst,
354 "sendto failed: %s\n",
361 "Error: partial send of ICMP message\n");
374 struct in_addr source_ip;
382 have = read (
icmpsock, buf,
sizeof(buf));
386 "Error reading raw socket: %s\n",
392 "Received message of %u bytes\n",
393 (
unsigned int) have);
418 source_ip.s_addr = ip_pkt.
src_ip;
426 switch (ip_pkt.
proto)
465 fprintf (stdout,
"%s\n",
466 inet_ntop (AF_INET, &source_ip, buf,
sizeof(buf)));
468 fprintf (stdout,
"%s:%u\n",
469 inet_ntop (AF_INET, &source_ip, buf,
sizeof(buf)),
470 (
unsigned int)
port);
493 "setsockopt failed: %s\n",
505 "setsockopt failed: %s\n",
523 struct sockaddr_in addr;
525 ret = socket (AF_INET, SOCK_DGRAM, 0);
529 "Error opening UDP socket: %s\n",
533 memset (&addr, 0,
sizeof(addr));
534 addr.sin_family = AF_INET;
535#if HAVE_SOCKADDR_IN_SIN_LEN
536 addr.sin_len =
sizeof(
struct sockaddr_in);
538 addr.sin_addr = *my_ip;
542 (
struct sockaddr *) &addr,
546 "Error binding UDP socket to port %u: %s\n",
560 struct in_addr external;
585 if (0 != setresuid (uid, uid, uid))
588 "Failed to setresuid: %s\n",
594 if (0 != (setuid (uid) | seteuid (uid)))
597 "Failed to setuid: %s\n",
608 "This program must be started with our (internal NAT) IP as the only argument.\n");
612 if (1 != inet_pton (AF_INET, argv[1], &external))
615 "Error parsing IPv4 address: %s\n",
623 "Internal error converting dummy IP to binary.\n");
632 "Error opening RAW socket: %s\n",
633 strerror (icmp_eno));
642 "Socket number too large (%d > %u)\n",
644 (
unsigned int) FD_SETSIZE);
653 "Error opening RAW socket: %s\n",
680 if (-1 == select (
icmpsock + 1, &rs, NULL, NULL, &tv))
685 "select failed: %s\n",
696 if (0 == (++alt % 2))
static int ret
Final status code.
static uint16_t port
Port number.
static int global_ret
Global status value.
static char * data
The data to insert into the dht.
static void process_icmp_response()
We've received an ICMP response.
#define ICMP_TIME_EXCEEDED
static uint16_t calc_checksum(const uint16_t *data, unsigned int bytes)
CRC-16 for IP/ICMP headers.
static void send_udp()
Send a UDP message to the dummy IP.
#define NAT_TRAV_PORT
Port for UDP.
#define DUMMY_IP
Must match IP given in the client.
static int rawsock
Socket we use to send our ICMP requests.
static int setup_raw_socket()
Fully initialize the raw socket.
static int icmpsock
Socket we use to receive "fake" ICMP replies.
#define ICMP_SEND_FREQUENCY_MS
How often do we send our ICMP messages to receive replies?
static struct in_addr dummy
Target "dummy" address.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
static int make_udp_socket(const struct in_addr *my_ip)
Create a UDP socket for writing.
int main(int argc, char *const *argv)
static void send_icmp_echo(const struct in_addr *my_ip)
Send an ICMP message to the dummy IP.
static int udpsock
Socket we use to send our UDP requests.
#define PACKET_ID
Must match packet ID used by gnunet-helper-nat-client.c.