71Ensure (pcap, routethrough_dst_is_localhost)
74 g_socket_use_real =
false;
75 gchar *
interface = NULL;
76 gchar *ipv4_str =
"127.0.0.1";
77 gvm_host_t *gvm_host = NULL;
79 struct in6_addr *dst6_p = &dst6;
81 struct in_addr *dst4_p = &dst4;
82 assert_that ((gvm_host = gvm_host_from_str (ipv4_str)), is_not_null);
83 assert_that (gvm_host_get_addr6 ((gvm_host_t *) gvm_host, dst6_p),
85 assert_that (dst6_p, is_not_null);
86 dst4.s_addr = dst6_p->s6_addr32[3];
94 g_socket_use_real =
true;
96 gvm_host_free (gvm_host);
101Ensure (pcap, routethrough_dst_is_not_localhost)
103 g_socket_use_real =
false;
105 gchar *
interface = NULL;
106 gchar *ipv4_str =
"93.184.216.34";
107 gvm_host_t *gvm_host = NULL;
108 struct in6_addr dst6;
109 struct in6_addr *dst6_p = &dst6;
111 struct in_addr *dst4_p = &dst4;
112 assert_that ((gvm_host = gvm_host_from_str (ipv4_str)), is_not_null);
113 assert_that (gvm_host_get_addr6 ((gvm_host_t *) gvm_host, dst6_p),
115 assert_that (dst6_p, is_not_null);
116 dst4.s_addr = dst6_p->s6_addr32[3];
119 assert_that (interface, is_not_equal_to_string (
"lo"));
120 g_socket_use_real =
true;
122 gvm_host_free (gvm_host);
133Ensure (pcap, routethrough_src_globalsource_set)
136 g_socket_use_real =
false;
137 cgreen_mocks_are (learning_mocks);
139 struct in_addr src = {.s_addr = 0};
140 gchar *
interface = NULL;
142 inet_pton (AF_INET,
"93.184.216.34", &(dst.s_addr));
145 gvm_source_iface_init (
"lo");
147 assert_that ((interface =
routethrough (NULL, &src)), is_null);
148 assert_that ((src.s_addr == INADDR_ANY));
155 assert_that (interface, is_not_equal_to_string (
"lo"));
156 assert_that ((src.s_addr != INADDR_ANY));
157 g_socket_use_real =
true;
161Ensure (pcap, routethrough_src_globalsource_not_set)
163 g_socket_use_real =
false;
165 struct in_addr src = {.s_addr = 0};
166 gchar *
interface = NULL;
168 inet_pton (AF_INET,
"127.0.0.1", &(dst.s_addr));
171 gvm_source_iface_init (NULL);
173 assert_that ((interface =
routethrough (NULL, &src)), is_null);
174 assert_that ((src.s_addr == INADDR_ANY));
182 assert_that ((src.s_addr != INADDR_ANY));
183 g_socket_use_real =
true;
257 struct in6_addr dest;
258 struct in6_addr result;
259 struct in6_addr mask;
260 struct in6_addr network;
261 const uint8_t byte_options[9] = {0xFF, 0x00, 0x80, 0xC0, 0xE0,
262 0xF0, 0xF8, 0xFC, 0xFE};
265 const uint8_t addr_in[16] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
266 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
267 memcpy (dest.s6_addr, addr_in,
sizeof addr_in);
269 const uint8_t result_in[16] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
270 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
271 0xFF, 0xFF, 0xFF, 0xFF};
272 memcpy (result.s6_addr, result_in,
sizeof result_in);
275 for (
int i = 128; i > 0; i--)
279 int byte_to_modify = i / 8;
280 if (byte_to_modify != 16)
281 result.s6_addr[byte_to_modify] = byte_options[(i % 8) + 1];
283 assert_that (IN6_ARE_ADDR_EQUAL (&network, &result));
290 TestSuite *suite = create_test_suite ();
291 add_test_with_context (suite, pcap, routethrough_dst_is_localhost);
292 add_test_with_context (suite, pcap, routethrough_dst_is_not_localhost);
293 add_test_with_context (suite, pcap, routethrough_no_src_dst_given);
294 add_test_with_context (suite, pcap, routethrough_src_globalsource_set);
295 add_test_with_context (suite, pcap, routethrough_src_globalsource_not_set);
309 suite = create_test_suite ();
313 ret = run_single_test (suite, argv[1], create_text_reporter ());
315 ret = run_test_suite (suite, create_text_reporter ());
317 destroy_test_suite (suite);
char * routethrough(struct in_addr *dest, struct in_addr *source)
An awesome function to determine what interface a packet to a given destination should be routed thro...
int __wrap_setsockopt(__attribute__((unused)) int sockfd, __attribute__((unused)) int level, __attribute__((unused)) int optname, __attribute__((unused)) const void *optval, __attribute__((unused)) socklen_t optlen)