Commit 2a4660c1 authored by Pekka Pessi's avatar Pekka Pessi
Browse files

Fixed stun miniserver (and stun stub in tport).

darcs-hash:20060404175757-88462-2df2a1ed28c4d021c7339606108ce9494b7cb8ed.gz
parent 957f0037
...@@ -653,9 +653,8 @@ int stun_encode_message(stun_msg_t *msg, stun_buffer_t *pwd) { ...@@ -653,9 +653,8 @@ int stun_encode_message(stun_msg_t *msg, stun_buffer_t *pwd) {
if (msg->enc_buf.data == NULL) { if (msg->enc_buf.data == NULL) {
/* convert msg to binary format */ /* convert msg to binary format */
/* convert attributes to binary format for transmission */ /* convert attributes to binary format for transmission */
attr = msg->stun_attr;
len = 0; len = 0;
while(attr) { for (attr = msg->stun_attr; attr ; attr = attr->next) {
switch(attr->attr_type) { switch(attr->attr_type) {
case RESPONSE_ADDRESS: case RESPONSE_ADDRESS:
case MAPPED_ADDRESS: case MAPPED_ADDRESS:
...@@ -668,8 +667,6 @@ int stun_encode_message(stun_msg_t *msg, stun_buffer_t *pwd) { ...@@ -668,8 +667,6 @@ int stun_encode_message(stun_msg_t *msg, stun_buffer_t *pwd) {
case TURN_SOURCE_ADDRESS: case TURN_SOURCE_ADDRESS:
#endif #endif
z = stun_encode_address(attr); z = stun_encode_address(attr);
if(z < 0) return z;
len += z;
break; break;
case CHANGE_REQUEST: case CHANGE_REQUEST:
#ifdef USE_TURN #ifdef USE_TURN
...@@ -678,8 +675,6 @@ int stun_encode_message(stun_msg_t *msg, stun_buffer_t *pwd) { ...@@ -678,8 +675,6 @@ int stun_encode_message(stun_msg_t *msg, stun_buffer_t *pwd) {
case TURN_BANDWIDTH: case TURN_BANDWIDTH:
#endif #endif
z = stun_encode_uint32(attr); z = stun_encode_uint32(attr);
if (z < 0) return z;
len += z;
break; break;
case USERNAME: case USERNAME:
...@@ -690,21 +685,21 @@ int stun_encode_message(stun_msg_t *msg, stun_buffer_t *pwd) { ...@@ -690,21 +685,21 @@ int stun_encode_message(stun_msg_t *msg, stun_buffer_t *pwd) {
case TURN_DATA: case TURN_DATA:
#endif #endif
z = stun_encode_buffer(attr); z = stun_encode_buffer(attr);
if(z < 0) return z;
len += z;
break; break;
case MESSAGE_INTEGRITY: case MESSAGE_INTEGRITY:
msg_int = attr; msg_int = attr;
len += 24; /* postpone encoding to 2nd round */ z = 24;
break; break;
case ERROR_CODE: case ERROR_CODE:
z = stun_encode_error_code(attr); z = stun_encode_error_code(attr);
if(z < 0) return z;
len += z;
default: default:
break; break;
z = 0;
} }
attr = attr->next;
if(z < 0) return z;
len += z;
} }
msg->stun_hdr.msg_len = len; msg->stun_hdr.msg_len = len;
......
...@@ -326,11 +326,11 @@ int process_3489_request(stun_mini_t *mini, ...@@ -326,11 +326,11 @@ int process_3489_request(stun_mini_t *mini,
a->attr_type = CHANGED_ADDRESS; a->attr_type = CHANGED_ADDRESS;
addr = malloc(sizeof *addr); if (!addr) return STUN_500_SERVER_ERROR; addr = malloc(sizeof *addr); if (!addr) return STUN_500_SERVER_ERROR;
memcpy(addr, changed->ss_addr.array, sizeof *addr); memcpy(addr, changed->ss_addr.array, sizeof *addr);
}
a->pattr = addr; a->pattr = addr;
a->next = NULL; a->next = NULL;
*next = a; next = &(a->next); *next = a; next = &(a->next);
}
stun_send_message(socket, (void *)from, response, NULL); stun_send_message(socket, (void *)from, response, NULL);
......
...@@ -150,7 +150,7 @@ int tport_recv_stun_dgram(tport_t const *self, int N) ...@@ -150,7 +150,7 @@ int tport_recv_stun_dgram(tport_t const *self, int N)
status = 500, error = "Server Error"; status = 500, error = "Server Error";
} }
if (dgram[1] == 1) { if (dgram[0] == 1) {
/* This is a response. */ /* This is a response. */
if (self->tp_pri->pri_vtable->vtp_stun_response) { if (self->tp_pri->pri_vtable->vtp_stun_response) {
if (self->tp_pri->pri_vtable->vtp_stun_response(self, dgram, n, if (self->tp_pri->pri_vtable->vtp_stun_response(self, dgram, n,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment