summaryrefslogtreecommitdiffstats
path: root/tinyNET/test/test_ifaces.h
blob: 2fd4e438f410abdd61aa767a46591dd06df35d9b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/* Copyright (C) 2014 Mamadou DIOP.
*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
*/
#ifndef TNET_TEST_IFACES_H
#define TNET_TEST_IFACES_H

void test_faces_bestsource()
{
	tnet_ip_t source;

    // IPv6
	if(!tnet_getbestsource("fe80::fe4c:3ea1", 5060, tnet_socket_type_udp_ipv6, &source)){
		TSK_DEBUG_INFO("Best IPv6 source is [%s]", source);
	}
	else{
		TSK_DEBUG_ERROR("Failed to get best IPv6 source.");
	}
    // IPv6
	if(!tnet_getbestsource("2a01:e35:8b32:7050:212:f0ff:fe4c:3ea1", 5060, tnet_socket_type_udp_ipv6, &source)){
		TSK_DEBUG_INFO("Best IPv6 source is [%s]", source);
	}
	else{
		TSK_DEBUG_ERROR("Failed to get best IPv6 source.");
	}
	// IPv4
	if(!tnet_getbestsource("192.168.0.11", 5060, tnet_socket_type_udp_ipv4, &source)){
		TSK_DEBUG_INFO("Best IPv4 source is [%s]", source);
	}
	else{
		TSK_DEBUG_ERROR("Failed to get best IPv4 source.");
	}
}

void test_ifaces_dump_ifaces()
{
	tnet_interfaces_L_t* ifaces = tnet_get_interfaces();
	tsk_list_item_t *item;

	tsk_list_foreach(item, ifaces)
	{
		const tnet_interface_t *iface = item->data;
		TSK_DEBUG_INFO("Interface: %s", iface->description);
	}

	TSK_OBJECT_SAFE_FREE(ifaces);
}

void test_ifaces_dump_addresses()
{
	tnet_addresses_L_t* addresses = tnet_get_addresses_all();
	tsk_list_item_t *item;

	tsk_list_foreach(item, addresses)
	{
		const tnet_address_t *address = item->data;
		if(address->anycast)
		{
			TSK_DEBUG_INFO("ANYCAST address: %s", address->ip);
		}
		else if(address->unicast)
		{
			TSK_DEBUG_INFO("UNICAST address: %s", address->ip);
		}
		else if(address->multicast)
		{
			TSK_DEBUG_INFO("MULTICAST address: %s", address->ip);
		}
		else if(address->dnsserver)
		{
			TSK_DEBUG_INFO("DNSSERVER address: %s", address->ip);
		}
	}

	TSK_OBJECT_SAFE_FREE(addresses);
}

void test_ifaces()
{
	test_faces_bestsource();
	test_ifaces_dump_ifaces();
	test_ifaces_dump_addresses();
}

#endif /* TNET_TEST_IFACES_H */
OpenPOWER on IntegriCloud