summaryrefslogtreecommitdiffstats
path: root/branches/1.0/tinyNET/src/stun/tnet_stun.h
blob: 05933cae4a5c81118e1cc6dfb5bf19fae85c68a2 (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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
* Copyright (C) 2009-2010 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 General Public License for more details.
*	
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
*/

/**@file tnet_stun.h
 * @brief Session Traversal Utilities for NAT (STUN) implementation as per RFC 5389 and RFC 3489(Obsolete).
 *
 * @author Mamadou Diop <diopmamadou(at)doubango.org>
 *
 * @date Created: Sat Nov 8 16:54:58 2009 mdiop
 */
#ifndef TNET_STUN_H
#define TNET_STUN_H

#include "tinynet_config.h"
#include "stun/tnet_stun_message.h"
#include "tnet_types.h"
#include "tnet_socket.h"

#include "tsk_object.h"

TNET_BEGIN_DECLS

/**@ingroup tnet_stun_group
*/
typedef uint64_t tnet_stun_binding_id_t;
/**@ingroup tnet_stun_group
 * @def	TNET_STUN_INVALID_BINDING_ID
 * STUN2 invalid binding id.
**/
/**@ingroup tnet_stun_group
 * @def	TNET_STUN_IS_VALID_BINDING_ID
 * Checks the validity of the STUN @a id.
**/
#define TNET_STUN_INVALID_BINDING_ID				0
#define TNET_STUN_IS_VALID_BINDING_ID(id)			(id != TNET_STUN_INVALID_BINDING_ID)

/**@ingroup tnet_stun_group
 * Default port for both TCP and UDP protos as per RFC 5389 subclause 9.
**/
#define TNET_STUN_TCP_UDP_DEFAULT_PORT 3478

/**@ingroup tnet_stun_group
 * Default port for TLS protocol as per RFC 5389 subclause 9.
**/
#define TNET_STUN_TLS_DEFAULT_PORT 5349


/**@ingroup tnet_stun_group
 * STUN2 magic cookie value in network byte order as per RFC 5389 subclause 6.
**/
#define TNET_STUN_MAGIC_COOKIE		0x2112A442

/**@ingroup tnet_stun_group
 * STUN2 header size as per RFC 5389 subclause 6.
**/
#define TNET_STUN_HEADER_SIZE		20

/**@ingroup tnet_stun_group
 * STUN2 binding context.
**/
typedef struct tnet_stun_binding_s
{
	TSK_DECLARE_OBJECT;

	//! A unique id to identify this binding. 
	tnet_stun_binding_id_t id;

	//! The username to authenticate to the STUN server. 
	char* username;
	//! The password to authenticate to the STUN server. 
	char* password;
	//! The realm.
	char* realm;
	//! The nonce.
	char* nonce;
	//! The client name.
	char* software;
	//! Local file descriptor for which to get server reflexive address.
	tnet_fd_t localFD;
	//! The type of the bound socket.
	tnet_socket_type_t socket_type;
	//! The address of the STUN server.
	struct sockaddr_storage server;
	//! Server reflexive address of the local socket(STUN1 as per RFC 3489).
	tnet_stun_attribute_mapped_addr_t *maddr;
	//! XORed server reflexive address (STUN2 as per RFC 5389).
	tnet_stun_attribute_xmapped_addr_t *xmaddr;
}tnet_stun_binding_t;

TINYNET_GEXTERN const tsk_object_def_t *tnet_stun_binding_def_t;
/**@ingroup tnet_stun_group
 * List of @ref tnet_stun_binding_t elements.
**/
typedef tsk_list_t tnet_stun_bindings_L_t;

//#if defined(__SYMBIAN32__) || ANDROID /* Forward declaration */
struct tnet_nat_context_s;
//#endif

int tnet_stun_send_reliably(const tnet_stun_message_t* message);
tnet_stun_response_t* tnet_stun_send_unreliably(tnet_fd_t localFD, uint16_t RTO, uint16_t Rc, const tnet_stun_message_t* message, struct sockaddr* server);
TINYNET_API tnet_stun_binding_id_t tnet_stun_bind(const struct tnet_nat_context_s* nat_context, tnet_fd_t localFD);
int tnet_stun_transacid_cmp(const tnet_stun_transacid_t id1, const tnet_stun_transacid_t id2);

TNET_END_DECLS


#endif /* TNET_STUN_H */

OpenPOWER on IntegriCloud