Home --> Documentations --> PJLIB-UTIL Reference

stun_simple.h
1 /* $Id: stun_simple.h 4224 2012-08-09 05:21:25Z nanang $ */
2 /*
3  * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4  * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */
20 #ifndef __PJSTUN_H__
21 #define __PJSTUN_H__
22 
28 #include <pjlib-util/types.h>
29 #include <pj/sock.h>
30 
31 
33 
34 /*
35  * This enumeration describes STUN message types.
36  */
37 typedef enum pjstun_msg_type
38 {
39  PJSTUN_BINDING_REQUEST = 0x0001,
40  PJSTUN_BINDING_RESPONSE = 0x0101,
41  PJSTUN_BINDING_ERROR_RESPONSE = 0x0111,
42  PJSTUN_SHARED_SECRET_REQUEST = 0x0002,
43  PJSTUN_SHARED_SECRET_RESPONSE = 0x0102,
44  PJSTUN_SHARED_SECRET_ERROR_RESPONSE = 0x0112
45 } pjstun_msg_type;
46 
47 
48 /*
49  * This enumeration describes STUN attribute types.
50  */
51 typedef enum pjstun_attr_type
52 {
53  PJSTUN_ATTR_MAPPED_ADDR = 1,
54  PJSTUN_ATTR_RESPONSE_ADDR,
55  PJSTUN_ATTR_CHANGE_REQUEST,
56  PJSTUN_ATTR_SOURCE_ADDR,
57  PJSTUN_ATTR_CHANGED_ADDR,
58  PJSTUN_ATTR_USERNAME,
59  PJSTUN_ATTR_PASSWORD,
60  PJSTUN_ATTR_MESSAGE_INTEGRITY,
61  PJSTUN_ATTR_ERROR_CODE,
62  PJSTUN_ATTR_UNKNOWN_ATTRIBUTES,
63  PJSTUN_ATTR_REFLECTED_FROM,
64  PJSTUN_ATTR_XOR_MAPPED_ADDR = 0x0020
65 } pjstun_attr_type;
66 
67 
68 /*
69  * This structre describes STUN message header.
70  */
71 typedef struct pjstun_msg_hdr
72 {
73  pj_uint16_t type;
74  pj_uint16_t length;
75  pj_uint32_t tsx[4];
77 
78 
79 /*
80  * This structre describes STUN attribute header.
81  */
82 typedef struct pjstun_attr_hdr
83 {
84  pj_uint16_t type;
85  pj_uint16_t length;
87 
88 
89 /*
90  * This structre describes STUN MAPPED-ADDR attribute.
91  */
93 {
94  pjstun_attr_hdr hdr;
95  pj_uint8_t ignored;
96  pj_uint8_t family;
97  pj_uint16_t port;
98  pj_uint32_t addr;
100 
105 
107 {
108  pjstun_attr_hdr hdr;
109  pj_uint32_t value;
111 
112 typedef struct pjstun_username_attr
113 {
114  pjstun_attr_hdr hdr;
115  pj_uint32_t value[1];
117 
119 
121 {
122  pjstun_attr_hdr hdr;
123  pj_uint16_t ignored;
124  pj_uint8_t err_class;
125  pj_uint8_t number;
126  char reason[4];
128 
129 typedef struct pjstun_msg
130 {
131  pjstun_msg_hdr *hdr;
132  int attr_count;
134 } pjstun_msg;
135 
136 /* STUN message API (stun.c). */
137 
138 PJ_DECL(pj_status_t) pjstun_create_bind_req( pj_pool_t *pool,
139  void **msg, pj_size_t *len,
140  pj_uint32_t id_hi,
141  pj_uint32_t id_lo);
142 PJ_DECL(pj_status_t) pjstun_parse_msg( void *buf, pj_size_t len,
143  pjstun_msg *msg);
144 PJ_DECL(void*) pjstun_msg_find_attr( pjstun_msg *msg, pjstun_attr_type t);
145 
146 
197  int sock_cnt, pj_sock_t sock[],
198  const pj_str_t *srv1, int port1,
199  const pj_str_t *srv2, int port2,
200  pj_sockaddr_in mapped_addr[]);
201 
202 
203 /*
204  * This structre describes configurable setting for requesting mapped address.
205  */
206 typedef struct pjstun_setting
207 {
213 
218 
222  int port1;
223 
228 
232  int port2;
233 
235 
236 
271  const pjstun_setting *opt,
272  int sock_cnt,
273  pj_sock_t sock[],
274  pj_sockaddr_in mapped_addr[]);
275 
276 
277 PJ_END_DECL
278 
283 #endif /* __PJSTUN_H__ */
284 
pj_bool_t use_stun2
Definition: stun_simple.h:212
Definition: stun_simple.h:71
pj_status_t pjstun_get_mapped_addr2(pj_pool_factory *pf, const pjstun_setting *opt, int sock_cnt, pj_sock_t sock[], pj_sockaddr_in mapped_addr[])
int pj_bool_t
Definition: stun_simple.h:120
int port2
Definition: stun_simple.h:232
int port1
Definition: stun_simple.h:222
pj_str_t srv2
Definition: stun_simple.h:227
#define PJSTUN_MAX_ATTR
Definition: config.h:226
Definition: stun_simple.h:206
Definition: stun_simple.h:112
int pj_status_t
pj_status_t pjstun_get_mapped_addr(pj_pool_factory *pf, int sock_cnt, pj_sock_t sock[], const pj_str_t *srv1, int port1, const pj_str_t *srv2, int port2, pj_sockaddr_in mapped_addr[])
Definition: stun_simple.h:92
unsigned int pj_uint32_t
Definition: stun_simple.h:106
#define PJ_BEGIN_DECL
long pj_sock_t
unsigned char pj_uint8_t
Definition: stun_simple.h:129
Definition: stun_simple.h:82
unsigned short pj_uint16_t
pj_str_t srv1
Definition: stun_simple.h:217
size_t pj_size_t

 


PJLIB-UTIL Open Source, small footprint, and portable asynchronous/caching DNS resolver, text scanner, STUN client, and XML library
Copyright (C) 2006-2009 Teluu Inc.