diff --git a/juice/include/juice/juice.h b/juice/include/juice/juice.h index 819da402a..675d2d5bd 100644 --- a/juice/include/juice/juice.h +++ b/juice/include/juice/juice.h @@ -63,7 +63,17 @@ typedef void (*juice_cb_candidate_t)(juice_agent_t *agent, const char *sdp, void typedef void (*juice_cb_gathering_done_t)(juice_agent_t *agent, void *user_ptr); typedef void (*juice_cb_recv_t)(juice_agent_t *agent, const char *data, size_t size, void *user_ptr); -typedef void (*juice_cb_stun_binding_t)(const char *ufrag, const char *pwd, const char *bind_address); + +typedef struct juice_stun_binding { + const char *ufrag; + const char *pwd; + + uint8_t family; + const char *address; + uint16_t port; +} juice_stun_binding_t; + +typedef void (*juice_cb_stun_binding_t)(const juice_stun_binding_t *info); typedef struct juice_turn_server { const char *host; diff --git a/juice/src/conn_mux.c b/juice/src/conn_mux.c index 4d05de120..ed11e4673 100644 --- a/juice/src/conn_mux.c +++ b/juice/src/conn_mux.c @@ -299,9 +299,29 @@ static juice_agent_t *lookup_agent(conn_registry_t *registry, char *buf, size_t if (registry->cb_stun_binding) { JLOG_DEBUG("Found STUN agent for unknown ICE ufrag"); - char src_str[ADDR_MAX_STRING_LEN]; - addr_record_to_string(src, src_str, ADDR_MAX_STRING_LEN); - registry->cb_stun_binding(username, separator + 1, src_str); + + const struct sockaddr *sa = (const struct sockaddr *)&src->addr; + + socklen_t salen = addr_get_len(sa); + if (salen == 0) + return NULL; + + char host[ADDR_MAX_NUMERICHOST_LEN]; + if (getnameinfo(sa, salen, host, ADDR_MAX_NUMERICHOST_LEN, NULL, 0, NI_NUMERICHOST)) { + JLOG_ERROR("getnameinfo failed, errno=%d", sockerrno); + return NULL; + } + + juice_stun_binding_t binding_info; + + binding_info.ufrag = username; + binding_info.pwd = separator + 1; + binding_info.family = sa->sa_family; + binding_info.address = host; + binding_info.port = addr_get_port(src); + + registry->cb_stun_binding(&binding_info); + return NULL; } } else {