summaryrefslogtreecommitdiffstats
path: root/tinyNET/test/test_stun.h
blob: 4209f0349e34e8e48fdf6c4423f1aa67b8b68d6f (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
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
* Copyright (C) 2009 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
*	
* 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_STUN_H
#define TNET_TEST_STUN_H

//#define STUN_SERVER_IP			"numb.viagenie.ca"
//#define STUN_SERVER_PORT		TNET_STUN_TCP_UDP_DEFAULT_PORT
//#define STUN_SERVER_PROTO		tnet_socket_type_udp_ipv4

// http://tools.ietf.org/html/draft-ietf-behave-stun-test-vectors-04

void test_stun_dump_transacid(tnet_stun_transacid_t transcid)
{
	char transac_idstriing[TNET_STUN_TRANSACID_SIZE*2+1];
	tsk_str_from_hex(transcid, TNET_STUN_TRANSACID_SIZE, transac_idstriing);

	transac_idstriing[sizeof(transac_idstriing)-1] = '\0'; 

	TSK_DEBUG_INFO("STUN transac id:%s", transac_idstriing);
}

void test_sun_sendMessage()
{
	/*tnet_stun_message_handle_t *message = 0;
	tsk_buffer_t *buffer = 0;
	tnet_socket_t *socket = 0;
	struct sockaddr_storage to;


	message = TNET_STUN_MESSAGE_CREATE();
	tnet_stun_message_set_type(message, tsm_binding_request);
	tnet_stun_message_set_random_transacid(message);

	if(!(buffer = tnet_stun_message_serialize(message)))
	{
		goto bail;
	}

	// Create blocking socket and bind it 
	socket = tnet_socket_create_EX(TNET_SOCKET_HOST_ANY, TNET_SOCKET_PORT_ANY, STUN_SERVER_PROTO, 0);
	if(!TNET_SOCKET_IS_VALID(socket))
	{
		goto bail;
	}

	// Create stun server's sockaddr structure 
	if(tnet_sockaddr_init(STUN_SERVER_IP, STUN_SERVER_PORT, STUN_SERVER_PROTO, &to))
	{
		goto bail;
	}

	tnet_socket_sendto(socket, (struct sockaddr*)&to, buffer->data, buffer->size);

bail:
	TSK_OBJECT_SAFE_FREE(message);
	TSK_OBJECT_SAFE_FREE(socket);
	TSK_OBJECT_SAFE_FREE(buffer);*/
}

void test_stun_context()
{
//	tnet_socket_t *localSocket = 0;
//	tnet_stun_context_t *context = 0;
//
//	/* Somewhere in Your application ==> Create and bind your local socket
//	*/
//	if(!(localSocket = tnet_socket_create_EX(TNET_SOCKET_HOST_ANY, TNET_SOCKET_PORT_ANY, STUN_SERVER_PROTO, 0)))
//	{
//		goto bail;
//	}
//	
//	/*	Create your STUN2 context
//	*/
//	if(!(context = TNET_STUN_CONTEXT_CREATE("myusername", "mypassword", localSocket->fd)))
//	{
//		goto bail;
//	}
//	
//	tnet_stun_resolve(context, STUN_SERVER_IP, STUN_SERVER_PORT, STUN_SERVER_PROTO);
//
//bail:
//	TNET_OBJECT_SAFE_FREE(localSocket);
//	TNET_OBJECT_SAFE_FREE(context);
}

void test_stun()
{
	//test_stun_transacid();
	//test_sun_sendMessage();
	test_stun_context();
}

#endif /* TNET_TEST_STUN_H */
OpenPOWER on IntegriCloud