0
udp 요청을 stun.l.google.com:19305
에게 보내지 만 Google 기절 서버에서 응답을받지 못했습니다. 이 코드 조각에서 오류 검사를 모두 생략했습니다. 내 프로그램이 recvfrom
에 있습니다.STUN 바인딩 요청이 잘못되었습니다.
int stun_socket = socket(AF_INET, SOCK_DGRAM, 0);
struct sockaddr_in stun_client;
memset(&stun_client, 0, sizeof(stun_client));
stun_client.sin_family = AF_INET;
stun_client.sin_port = htons(local_port);
int rc = bind(stun_socket, (struct sockaddr *)&stun_client, sizeof(stun_client));
struct sockaddr_in stun_server;
memset(&stun_server, 0, sizeof(stun_server));
stun_server.sin_family = AF_INET;
stun_server.sin_port = htons(remote_port);
inet_pton(AF_INET, server, &stun_server.sin_addr);
typedef struct stun_header_tag {
uint16_t message_type;
uint16_t message_length;
unsigned char transaction_id[16];
} stun_header_t;
stun_header_t header;
header.message_type = htons(0x0001); /* Binding Request */
header.message_length = htons(0);
*(int *)(&header.transaction_id[8]) = 0xFFEEFFEE; /* transaction id in the response should keep consistent with this one */
rc = sendto(stun_socket, (void *)&header, sizeof(header), 0, (struct sockaddr *)&stun_server, sizeof(stun_server));
char response[64];
rc = recvfrom(stun_socket, response, 64, 0, NULL, 0);
답장을 보내 주셔서 감사합니다.하지만 원격 서버에서 응답이 없습니다. 코드 조각을 붙여 넣으십시오. – CharlesLiuChina
서버에 대해 실행중인 코드의 tcpdump 또는 wireshark 추적을 가져 와서 링크를 보내주십시오. – selbie
위의 링크에서 코드를 컴파일하십시오. 'stunclient stun.l.google.com 19305'를 실행하여 생성 된 트레이스와 트레이스를 비교할 수 있습니다. – selbie