Commit 09c1e857 authored by Martti Mela's avatar Martti Mela

stun works with nua_cli

darcs-hash:20060114155429-1b897-f3082016b825b35da22f59de7b1cfcdd99f9d1f7.gz
parent b57b4816
......@@ -655,7 +655,7 @@ static int get_localinfo(su_localinfo_t *clientinfo)
int i, error, found = 0;
char ipaddr[SU_ADDRSIZE + 2] = { 0 };
/* hints->li_family = AF_INET; */
hints->li_family = AF_INET;
if ((error = su_getlocalinfo(hints, &res)) == 0) {
/* try to bind to the first available address */
......@@ -667,7 +667,7 @@ static int get_localinfo(su_localinfo_t *clientinfo)
clientinfo->li_addrlen = li->li_addrlen;
sa = clientinfo->li_addr;
memcpy(sa, li->li_addr, sizeof(su_addrinfo_t));
memcpy(sa, li->li_addr, sizeof(su_sockaddr_t));
SU_DEBUG_3(("%s: local address found to be %s.\n",
__func__,
inet_ntop(clientinfo->li_family, SU_ADDR(sa),
......@@ -732,8 +732,8 @@ int stun_handle_bind(stun_handle_t *sh,
stun_discovery_t *sd = NULL;
ta_list ta;
stun_action_t action = stun_action_binding_request;
struct sockaddr *sa;
int err;
su_sockaddr_t *sa;
int err, index;
SU_DEBUG_7(("%s: entering.\n", __func__));
......@@ -753,7 +753,7 @@ int stun_handle_bind(stun_handle_t *sh,
return errno = EINVAL, -1;
}
if (assign_socket(sh, s) < 0)
if ((index = assign_socket(sh, s)) < 0)
return -1;
bind_len = sizeof bind_addr;
......@@ -762,7 +762,7 @@ int stun_handle_bind(stun_handle_t *sh,
bind_len = sizeof bind_addr;
memset(sa, 0, sizeof(bind_addr));
/* if bound check the error */
err = getsockname(s, sa, &bind_len);
err = getsockname(s, (struct sockaddr *) sa, &bind_len);
if (err < 0 && errno == SOCKET_ERROR) {
STUN_ERROR(errno, getsockname);
return -1;
......@@ -779,9 +779,10 @@ int stun_handle_bind(stun_handle_t *sh,
}
else {
/* Not bound - bind it */
get_localinfo(clientinfo);
//get_localinfo(clientinfo);
if (err = bind(s, (struct sockaddr *) &clientinfo->li_addr, bind_len) < 0) {
clientinfo->li_family = AF_INET6;
if ((err = bind(s, (struct sockaddr *) sa, bind_len)) < 0) {
STUN_ERROR(errno, bind);
SU_DEBUG_3(("%s: Error binding to %s:%u\n", __func__,
inet_ntop(clientinfo->li_family, SU_ADDR(clientinfo->li_addr),
......@@ -805,6 +806,7 @@ int stun_handle_bind(stun_handle_t *sh,
sd = stun_discovery_create(sh, action);
sd->sd_socket = s;
sd->sd_index = index;
req = stun_request_create(sd);
......@@ -939,6 +941,7 @@ int stun_handle_get_nattype(stun_handle_t *sh,
sd = stun_discovery_create(sh, stun_action_get_nattype);
sd->sd_socket = s;
sd->sd_index = index;
/* If no server given, use default address from stun_handle_create() */
if (!server) {
......@@ -2243,6 +2246,7 @@ int stun_handle_get_lifetime(stun_handle_t *sh,
sd = stun_discovery_create(sh, stun_action_get_lifetime);
sd->sd_socket = s;
sd->sd_index = index;
/* If no server given, use default address from stun_handle_create() */
if (!server) {
......@@ -2404,7 +2408,9 @@ int stun_handle_release(stun_handle_t *sh, su_socket_t s)
continue;
/* Index has same value as sockfd, right? */
su_root_deregister(sh->sh_root, sd->sd_socket);
su_root_deregister(sh->sh_root, sd->sd_index);
SU_DEBUG_3(("%s: socket deregistered from STUN \n", __func__));
return 0;
}
......
......@@ -163,7 +163,7 @@ int main(int argc, char *argv[])
return -1;
}
s = su_socket(AF_INET, SOCK_DGRAM, 0);
s = su_socket(AF_INET6, SOCK_DGRAM, 0);
if (s == -1) {
SU_DEBUG_0(("%s: %s failed: %s\n", __func__, "stun_socket_create()", su_gli_strerror(errno)));
return -1;
......
......@@ -6870,7 +6870,7 @@ void tport_stun_cb(tport_master_t *mr, stun_handle_t *sh,
break;
case stun_action_binding_request:
if (event != stun_bind_done || event != stun_bind_timeout)
if (event != stun_bind_done && event != stun_bind_timeout)
break;
sa = stun_discovery_get_address(sd);
......@@ -7006,6 +7006,7 @@ int tport_nat_stun_bind(struct tport_nat_s *nat,
su_root_step(mr->mr_root, 1000);
}
stun_handle_release(nat->stun, s);
SU_DEBUG_9(("%s: stun_bind() ok\n", __func__));
memcpy(su, &nat->sockaddr, sizeof(su));
......
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