summaryrefslogtreecommitdiff
path: root/pjlib/include/pj/stun.h
diff options
context:
space:
mode:
Diffstat (limited to 'pjlib/include/pj/stun.h')
-rw-r--r--pjlib/include/pj/stun.h123
1 files changed, 123 insertions, 0 deletions
diff --git a/pjlib/include/pj/stun.h b/pjlib/include/pj/stun.h
new file mode 100644
index 00000000..999dda42
--- /dev/null
+++ b/pjlib/include/pj/stun.h
@@ -0,0 +1,123 @@
+#ifndef __PJ_STUN_H__
+#define __PJ_STUN_H__
+
+#include <pj/types.h>
+#include <pj/sock.h>
+
+PJ_BEGIN_DECL
+
+#define PJ_STUN_MAX_ATTR 16
+
+typedef enum pj_stun_msg_type
+{
+ PJ_STUN_BINDING_REQUEST = 0x0001,
+ PJ_STUN_BINDING_RESPONSE = 0x0101,
+ PJ_STUN_BINDING_ERROR_RESPONSE = 0x0111,
+ PJ_STUN_SHARED_SECRET_REQUEST = 0x0002,
+ PJ_STUN_SHARED_SECRET_RESPONSE = 0x0102,
+ PJ_STUN_SHARED_SECRET_ERROR_RESPONSE = 0x0112
+} pj_stun_msg_type;
+
+typedef enum pj_stun_attr_type
+{
+ PJ_STUN_ATTR_MAPPED_ADDR = 1,
+ PJ_STUN_ATTR_RESPONSE_ADDR,
+ PJ_STUN_ATTR_CHANGE_REQUEST,
+ PJ_STUN_ATTR_SOURCE_ADDR,
+ PJ_STUN_ATTR_CHANGED_ADDR,
+ PJ_STUN_ATTR_USERNAME,
+ PJ_STUN_ATTR_PASSWORD,
+ PJ_STUN_ATTR_MESSAGE_INTEGRITY,
+ PJ_STUN_ATTR_ERROR_CODE,
+ PJ_STUN_ATTR_UNKNOWN_ATTRIBUTES,
+ PJ_STUN_ATTR_REFLECTED_FORM
+} pj_stun_attr_type;
+
+typedef struct pj_stun_msg_hdr
+{
+ pj_uint16_t type;
+ pj_uint16_t length;
+ pj_uint32_t tsx[4];
+} pj_stun_msg_hdr;
+
+typedef struct pj_stun_attr_hdr
+{
+ pj_uint16_t type;
+ pj_uint16_t length;
+} pj_stun_attr_hdr;
+
+typedef struct pj_stun_mapped_addr_attr
+{
+ pj_stun_attr_hdr hdr;
+ pj_uint8_t ignored;
+ pj_uint8_t family;
+ pj_uint16_t port;
+ pj_uint32_t addr;
+} pj_stun_mapped_addr_attr;
+
+typedef pj_stun_mapped_addr_attr pj_stun_response_addr_attr;
+typedef pj_stun_mapped_addr_attr pj_stun_changed_addr_attr;
+typedef pj_stun_mapped_addr_attr pj_stun_src_addr_attr;
+typedef pj_stun_mapped_addr_attr pj_stun_reflected_form_attr;
+
+typedef struct pj_stun_change_request_attr
+{
+ pj_stun_attr_hdr hdr;
+ pj_uint32_t value;
+} pj_stun_change_request_attr;
+
+typedef struct pj_stun_username_attr
+{
+ pj_stun_attr_hdr hdr;
+ pj_uint32_t value[1];
+} pj_stun_username_attr;
+
+typedef pj_stun_username_attr pj_stun_password_attr;
+
+typedef struct pj_stun_error_code_attr
+{
+ pj_stun_attr_hdr hdr;
+ pj_uint16_t ignored;
+ pj_uint8_t err_class;
+ pj_uint8_t number;
+ char reason[4];
+} pj_stun_error_code_attr;
+
+typedef struct pj_stun_msg
+{
+ pj_stun_msg_hdr *hdr;
+ int attr_count;
+ pj_stun_attr_hdr *attr[PJ_STUN_MAX_ATTR];
+} pj_stun_msg;
+
+/* STUN message API (stun.c). */
+
+PJ_DECL(pj_status_t) pj_stun_create_bind_req( pj_pool_t *pool,
+ void **msg, pj_size_t *len,
+ pj_uint32_t id_hi,
+ pj_uint32_t id_lo);
+PJ_DECL(pj_status_t) pj_stun_parse_msg( void *buf, pj_size_t len,
+ pj_stun_msg *msg);
+PJ_DECL(void*) pj_stun_msg_find_attr( pj_stun_msg *msg, pj_stun_attr_type t);
+
+/* STUN simple client API (stun_client.c) */
+enum pj_stun_err_code {
+ PJ_STUN_ERR_MEMORY = (-2),
+ PJ_STUN_ERR_RESOLVE = (-3),
+ PJ_STUN_ERR_TRANSPORT = (-4),
+ PJ_STUN_ERR_INVALID_MSG = (-5),
+ PJ_STUN_ERR_NO_RESPONSE = (-6),
+ PJ_STUN_ERR_SYMETRIC = (-7),
+};
+
+PJ_DECL(pj_status_t) pj_stun_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[]);
+PJ_DECL(const char*) pj_stun_get_err_msg(pj_status_t status);
+
+PJ_END_DECL
+
+#endif /* __PJ_STUN_H__ */
+