#include "platform.h"
#include "gnunet_tun_lib.h"
+static int ret;
+
static void
-test_udp (size_t pll)
+test_udp (size_t pll,
+ int pl_fill,
+ uint16_t crc)
{
struct GNUNET_TUN_IPv4Header ip;
struct GNUNET_TUN_UdpHeader udp;
struct in_addr src;
struct in_addr dst;
- inet_pton (AF_INET, "1.2.3.4", &src);
- inet_pton (AF_INET, "122.2.3.5", &dst);
- memset (payload, 42, sizeof (payload));
+ GNUNET_assert (1 == inet_pton (AF_INET, "1.2.3.4", &src));
+ GNUNET_assert (1 == inet_pton (AF_INET, "122.2.3.5", &dst));
+ memset (payload, pl_fill, sizeof (payload));
GNUNET_TUN_initialize_ipv4_header (&ip,
IPPROTO_UDP,
pll + sizeof (udp),
&src,
&dst);
+ udp.source_port = htons (4242);
+ udp.destination_port = htons (4242);
+ udp.len = htons (pll);
GNUNET_TUN_calculate_udp4_checksum (&ip,
&udp,
payload,
pll);
- fprintf (stderr, "CRC: %u\n",
- ntohs (udp.crc));
+ if (crc != ntohs (udp.crc))
+ {
+ fprintf (stderr, "Got CRC: %u, wanted: %u\n",
+ ntohs (udp.crc),
+ crc);
+ ret = 1;
+ }
}
int main (int argc,
char **argv)
{
- test_udp (4);
- return 0;
+ test_udp (4, 3, 22439);
+ test_udp (4, 1, 23467);
+ test_udp (7, 17, 6516);
+ test_udp (12451, 251, 42771);
+ return ret;
}