Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef STUN_COMMON_H
00026
00027 #define STUN_COMMON_H
00028
00039 #include <sofia-sip/su_localinfo.h>
00040
00041 SOFIA_BEGIN_DECLS
00042
00043
00044 #define BINDING_REQUEST 0x0001
00045 #define BINDING_RESPONSE 0x0101
00046 #define BINDING_ERROR_RESPONSE 0x0111
00047 #define SHARED_SECRET_REQUEST 0x0002
00048 #define SHARED_SECRET_RESPONSE 0x0102
00049 #define SHARED_SECRET_ERROR_RESPONSE 0x0112
00050
00051
00052 #define MAPPED_ADDRESS 0x0001
00053 #define RESPONSE_ADDRESS 0x0002
00054 #define CHANGE_REQUEST 0x0003
00055 #define SOURCE_ADDRESS 0x0004
00056 #define CHANGED_ADDRESS 0x0005
00057 #define USERNAME 0x0006
00058 #define PASSWORD 0x0007
00059 #define MESSAGE_INTEGRITY 0x0008
00060 #define ERROR_CODE 0x0009
00061 #define UNKNOWN_ATTRIBUTES 0x000a
00062 #define REFLECTED_FROM 0x000b
00063 #define STUN_A_REALM 0x0014
00064 #define STUN_A_NONCE 0x0015
00065 #define STUN_A_XOR_MAPPED_ADDRESS 0x0020
00066 #define STUN_A_FINGERPRINT 0x0023
00067 #define STUN_A_SERVER 0x8022
00068 #define STUN_A_ALTERNATE_SERVER 0x8023
00069 #define STUN_A_REFRESH_INTERVAL 0x8024
00070
00071
00072 #define STUN_A_LAST_MANDATORY 0x0023
00075 #define STUN_A_OPTIONAL 0x7fff
00076
00077
00078 #define STUN_A_ALTERNATE_SERVER_DEP 0x000e
00079 #define STUN_A_BUGGYSERVER_XORONLY 0x0021
00080 #define STUN_A_BUGGYSERVER_SERVER 0x0022
00081 #define LARGEST_ATTRIBUTE STUN_A_LAST_MANDATORY
00082 #define OPTIONAL_ATTRIBUTE STUN_A_OPTIONAL
00084
00085 #define STUN_400_BAD_REQUEST 400
00086 #define STUN_401_UNAUTHORIZED 401
00087 #define STUN_420_UNKNOWN_ATTRIBUTE 420
00088 #define STUN_430_STALE_CREDENTIALS 430
00089 #define STUN_431_INTEGRITY_CHECK_FAILURE 431
00090 #define STUN_432_MISSING_USERNAME 432
00091 #define STUN_433_USE_TLS 433
00092 #define STUN_500_SERVER_ERROR 500
00093 #define STUN_600_GLOBAL_FAILURE 600
00094
00095
00096 #define STUN_CR_CHANGE_IP 0x0004
00097 #define STUN_CR_CHANGE_PORT 0x0002
00098
00099
00100 #define STUN_EC_CLASS 0x0070
00101 #define STUN_EC_NUM 0x000F
00102
00103 #define RAND_MAX_16 65535
00104
00105 #define STUN_TID_BYTES 16
00106
00107
00108 #define STUN_MAX_RETRX 5
00109 #define STUN_MAX_RETRX_INT 1600
00111 #define STUN_DEFAULT_PORT 3478
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128 struct stun_buffer_s {
00129 unsigned char *data;
00130 unsigned size;
00131 };
00132
00133 typedef struct stun_buffer_s stun_buffer_t;
00134
00135 typedef struct {
00136 uint16_t msg_type;
00137 uint16_t msg_len;
00138 uint8_t tran_id[16];
00139 } stun_hdr_t;
00140
00141 typedef struct stun_attr_s {
00142 uint16_t attr_type;
00143 void *pattr;
00144 stun_buffer_t enc_buf;
00145 struct stun_attr_s *next;
00146 } stun_attr_t;
00147
00148 typedef struct {
00149 stun_hdr_t stun_hdr;
00150 stun_attr_t *stun_attr;
00151 stun_buffer_t enc_buf;
00152 } stun_msg_t;
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162 typedef struct sockaddr_in stun_attr_sockaddr_t;
00163
00164
00165 typedef struct stun_attr_uint32_s {
00166 uint32_t value;
00167 } stun_attr_uint32_t;
00168
00169 typedef stun_attr_uint32_t stun_attr_changerequest_t;
00170
00171
00172 typedef struct {
00173 int code;
00174 char *phrase;
00175 } stun_attr_errorcode_t;
00176
00177
00178
00179
00180
00181
00182 typedef stun_buffer_t stun_attr_username_t;
00183
00184
00185 typedef stun_buffer_t stun_attr_password_t;
00186
00187
00188 typedef struct stun_attr_unknownattributes_s{
00189 uint16_t attr_type[2];
00190 struct stun_attr_unknownattributes_s *next;
00191 } stun_attr_unknownattributes_t;
00192
00193
00194 int stun_parse_message(stun_msg_t *msg);
00195 int stun_parse_attribute(stun_msg_t *msg, unsigned char *p);
00196 int stun_parse_attr_address(stun_attr_t *attr, const unsigned char *p, unsigned len);
00197 int stun_parse_attr_error_code(stun_attr_t *attr, const unsigned char *p, unsigned len);
00198 int stun_parse_attr_unknown_attributes(stun_attr_t *attr, const unsigned char *p, unsigned len);
00199 int stun_parse_attr_uint32(stun_attr_t *attr, const unsigned char *p, unsigned len);
00200 int stun_parse_attr_buffer(stun_attr_t *attr, const unsigned char *p, unsigned len);
00201
00202 stun_attr_t *stun_get_attr(stun_attr_t *attr, uint16_t attr_type);
00203
00204 int stun_encode_address(stun_attr_t *attr);
00205 int stun_encode_uint32(stun_attr_t *attr);
00206 int stun_encode_buffer(stun_attr_t *attr);
00207 int stun_encode_error_code(stun_attr_t *attr);
00208 int stun_encode_message_integrity(stun_attr_t *attr, unsigned char *buf, int len, stun_buffer_t *pwd);
00209 int stun_encode_type_len(stun_attr_t *attr, uint16_t len);
00210 int stun_encode_response_address(stun_attr_t *attr);
00211
00212 int stun_validate_message_integrity(stun_msg_t *msg, stun_buffer_t *pwd);
00213
00214 int stun_copy_buffer(stun_buffer_t *p, stun_buffer_t *p2);
00215 void stun_init_buffer(stun_buffer_t *p);
00216 int stun_free_buffer(stun_buffer_t *p);
00217 int stun_free_message(stun_msg_t *msg);
00218
00219 int stun_init_message(stun_msg_t *msg);
00220
00221 int stun_encode_message(stun_msg_t *msg, stun_buffer_t *pwd);
00222
00223 char const *stun_response_phrase(int status);
00224 void debug_print(stun_buffer_t *buf);
00225 char const *stun_attr_phrase(uint16_t type);
00226
00234 char *stun_determine_ip_address(int family);
00235
00236 SOFIA_END_DECLS
00237
00238 #endif