diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-02-22 10:15:02 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-02-22 10:15:02 +0000 |
commit | 4d13edf008c6d1c325331d4a849c3349ccba6ec0 (patch) | |
tree | a06a658370939ab3144977c384d0e40e74f9784f /src/tun | |
parent | 26e1543206629acaaf9ce135c91915c4e1431b46 (diff) | |
download | gnunet-4d13edf008c6d1c325331d4a849c3349ccba6ec0.tar.gz gnunet-4d13edf008c6d1c325331d4a849c3349ccba6ec0.zip |
-initial testcase
Diffstat (limited to 'src/tun')
-rw-r--r-- | src/tun/Makefile.am | 14 | ||||
-rw-r--r-- | src/tun/test_tun.c | 59 |
2 files changed, 73 insertions, 0 deletions
diff --git a/src/tun/Makefile.am b/src/tun/Makefile.am index bfc1135d8..31de64667 100644 --- a/src/tun/Makefile.am +++ b/src/tun/Makefile.am | |||
@@ -18,3 +18,17 @@ libgnunettun_la_LIBADD = \ | |||
18 | libgnunettun_la_LDFLAGS = \ | 18 | libgnunettun_la_LDFLAGS = \ |
19 | $(GN_LIB_LDFLAGS) | 19 | $(GN_LIB_LDFLAGS) |
20 | 20 | ||
21 | |||
22 | check_PROGRAMS = \ | ||
23 | test_tun | ||
24 | |||
25 | |||
26 | if ENABLE_TEST_RUN | ||
27 | TESTS = $(check_PROGRAMS) | ||
28 | endif | ||
29 | |||
30 | test_tun_SOURCES = \ | ||
31 | test_tun.c | ||
32 | test_tun_LDADD = \ | ||
33 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
34 | $(top_builddir)/src/tun/libgnunettun.la | ||
diff --git a/src/tun/test_tun.c b/src/tun/test_tun.c new file mode 100644 index 000000000..0177ea462 --- /dev/null +++ b/src/tun/test_tun.c | |||
@@ -0,0 +1,59 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2010, 2011, 2012 Christian Grothoff | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file tun/test_tun.c | ||
23 | * @brief test for tun.c | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_tun_lib.h" | ||
28 | |||
29 | static void | ||
30 | test_udp (size_t pll) | ||
31 | { | ||
32 | struct GNUNET_TUN_IPv4Header ip; | ||
33 | struct GNUNET_TUN_UdpHeader udp; | ||
34 | char payload[pll]; | ||
35 | struct in_addr src; | ||
36 | struct in_addr dst; | ||
37 | |||
38 | inet_pton (AF_INET, "1.2.3.4", &src); | ||
39 | inet_pton (AF_INET, "122.2.3.5", &dst); | ||
40 | memset (payload, 42, sizeof (payload)); | ||
41 | GNUNET_TUN_initialize_ipv4_header (&ip, | ||
42 | IPPROTO_UDP, | ||
43 | pll + sizeof (udp), | ||
44 | &src, | ||
45 | &dst); | ||
46 | GNUNET_TUN_calculate_udp4_checksum (&ip, | ||
47 | &udp, | ||
48 | payload, | ||
49 | pll); | ||
50 | fprintf (stderr, "CRC: %u\n", | ||
51 | ntohs (udp.crc)); | ||
52 | } | ||
53 | |||
54 | int main (int argc, | ||
55 | char **argv) | ||
56 | { | ||
57 | test_udp (4); | ||
58 | return 0; | ||
59 | } | ||