Skip to content

Commit

Permalink
stun: fix logging received port
Browse files Browse the repository at this point in the history
  • Loading branch information
yosoyubik committed Dec 1, 2023
1 parent 6f8e718 commit 9578d35
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions pkg/vere/io/ames.c
Original file line number Diff line number Diff line change
Expand Up @@ -1361,7 +1361,7 @@ static void _stun_on_request(u3_ames *sam_u, c3_y* buf_r,
adr_u, _stun_send_response_cb
);

if ( sas_i != 0) {
if ( sas_i != 0 ) {
u3l_log("stun: send response fail_sync: %s", uv_strerror(sas_i));
c3_free(buf_y);
c3_free(snd_u);
Expand All @@ -1378,7 +1378,7 @@ _stun_on_response(u3_ames* sam_u, c3_y* buf_y, c3_w buf_len)
c3_w xor_index = _stun_find_xor_mapped_address(buf_y, buf_len);

// Ignore STUN responses that dont' have the XOR-MAPPED-ADDRESS attribute
if (xor_index != 0) {
if ( xor_index != 0 ) {
c3_w ip_addr_xor = _ames_sift_word(buf_y + xor_index + 2);
c3_s port_xor = _ames_sift_short(buf_y + xor_index);

Expand Down Expand Up @@ -1658,26 +1658,25 @@ _stun_find_xor_mapped_address(c3_y* buf_y, c3_w buf_len)
if ( fin_y != 0 ) {
c3_w cur = (c3_w)(fin_y - buf_y) + 6;

c3_s port = ntohs(htons(_ames_sift_short(buf_y + cur)) ^ cookie >> 16); // XX wrong
c3_s port = htons(_ames_sift_short(buf_y + cur)) ^ cookie >> 16;
c3_w ip = ntohl(htonl(_ames_sift_word(buf_y + cur + 2)) ^ cookie);

char ip_str[INET_ADDRSTRLEN];

if ( (inet_ntop(AF_INET, &ip, ip_str, INET_ADDRSTRLEN) == NULL) ||
port > 65535 ) {
if (inet_ntop(AF_INET, &ip, ip_str, INET_ADDRSTRLEN) == NULL) {
fin_y = 0;
i = buf_len;
} else {
if ( u3o_verbose && 1) {
u3l_log("ip:port %s:%u", ip_str, port);
if ( u3o_verbose ) {
u3l_log("stun: hear ip:port %s:%u", ip_str, port);
}
}
}
i += 1;
}

// If non-zero, skip attribute type, length, reserved byte and IP family
return (fin_y) ? 0 : (c3_w)(fin_y - buf_y) + 6;
return ( !fin_y ) ? 0 : (c3_w)(fin_y - buf_y) + 6;
}
}

Expand Down

0 comments on commit 9578d35

Please sign in to comment.