Skip to content

Commit 99de656

Browse files
authored
Skip hostname parsing for stun servers (#2125)
* Skip hostname parsing for stun servers * Clang-format * Fix unit test
1 parent 15d19f0 commit 99de656

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/include/com/amazonaws/kinesis/video/webrtcclient/Include.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -722,10 +722,12 @@ extern "C" {
722722
/**
723723
* Parameterized string for KVS STUN Server
724724
*/
725-
#define KINESIS_VIDEO_STUN_URL_POSTFIX "amazonaws.com"
726-
#define KINESIS_VIDEO_STUN_URL_POSTFIX_CN "amazonaws.com.cn"
727-
#define KINESIS_VIDEO_STUN_URL "stun:stun.kinesisvideo.%s.%s:443"
728-
#define KINESIS_VIDEO_STUN_URL_WITHOUT_PORT "stun.kinesisvideo.%s.%s"
725+
#define KINESIS_VIDEO_STUN_URL_POSTFIX "amazonaws.com"
726+
#define KINESIS_VIDEO_STUN_URL_POSTFIX_CN "amazonaws.com.cn"
727+
#define KINESIS_VIDEO_STUN_URL_PREFIX "stun."
728+
#define KINESIS_VIDEO_STUN_URL_PREFIX_LENGTH 5
729+
#define KINESIS_VIDEO_STUN_URL "stun:stun.kinesisvideo.%s.%s:443"
730+
#define KINESIS_VIDEO_STUN_URL_WITHOUT_PORT "stun.kinesisvideo.%s.%s"
729731

730732
/**
731733
* Default signaling SSL port

src/source/Ice/Network.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,25 +406,31 @@ STATUS getIpWithHostName(PCHAR hostname, PKvsIpAddress destIp)
406406
struct in_addr inaddr;
407407

408408
CHAR addr[KVS_IP_ADDRESS_STRING_BUFFER_LEN + 1] = {'\0'};
409+
BOOL isStunServer;
409410

410411
CHK(hostname != NULL, STATUS_NULL_ARG);
411412
DLOGI("ICE SERVER Hostname received: %s", hostname);
412413

413414
hostnameLen = STRLEN(hostname);
414415
addrLen = SIZEOF(addr);
416+
isStunServer = STRNCMP(hostname, KINESIS_VIDEO_STUN_URL_PREFIX, KINESIS_VIDEO_STUN_URL_PREFIX_LENGTH) == 0;
415417

416418
// Adding this check in case we directly get an IP address. With the current usage pattern,
417419
// there is no way this function would receive an address directly, but having this check
418420
// in place anyways
419421
if (isIpAddr(hostname, hostnameLen)) {
420422
MEMCPY(addr, hostname, hostnameLen);
421-
} else {
423+
} else if (!isStunServer) {
422424
retStatus = getIpAddrFromDnsHostname(hostname, addr, hostnameLen, addrLen);
423425
}
424426

425427
// Verify the generated address has the format x.x.x.x
426428
if (!isIpAddr(addr, hostnameLen) || retStatus != STATUS_SUCCESS) {
427-
DLOGW("Parsing for address failed for %s, fallback to getaddrinfo", hostname);
429+
// Only print the message for TURN servers since STUN addresses don't have the IP in the URL
430+
if (!isStunServer) {
431+
DLOGW("Parsing for address failed for %s, fallback to getaddrinfo", hostname);
432+
}
433+
428434
errCode = getaddrinfo(hostname, NULL, NULL, &res);
429435
if (errCode != 0) {
430436
errStr = errCode == EAI_SYSTEM ? (strerror(errno)) : ((PCHAR) gai_strerror(errCode));

0 commit comments

Comments
 (0)