diff --git a/client/src/uart/uart.h b/client/src/uart/uart.h index 954fa6685..cb67d7482 100644 --- a/client/src/uart/uart.h +++ b/client/src/uart/uart.h @@ -84,6 +84,11 @@ uint32_t uart_get_timeouts(void); /* Specify the outbound address and port for TCP/UDP connections */ -bool uart_bind(void *socket, char *bindAddrStr, char *bindPortStr, bool isBindingIPv6); +bool uart_bind(void *socket, const char *bindAddrStr, const char *bindPortStr, bool isBindingIPv6); + +/* Parse address and port from string. + This could change the addrPortStr + */ +int uart_parse_address_port(char *addrPortStr, const char **addrStr, const char **portStr, bool *isIPv6); #endif // _UART_H_ diff --git a/client/src/uart/uart_common.c b/client/src/uart/uart_common.c index af439699a..3e7fc5fb5 100644 --- a/client/src/uart/uart_common.c +++ b/client/src/uart/uart_common.c @@ -38,7 +38,7 @@ #include #endif -bool uart_bind(void *socket, char *bindAddrStr, char *bindPortStr, bool isBindingIPv6) { +bool uart_bind(void *socket, const char *bindAddrStr, const char *bindPortStr, bool isBindingIPv6) { if (bindAddrStr == NULL && bindPortStr == NULL) return true; // no need to bind @@ -71,4 +71,64 @@ bool uart_bind(void *socket, char *bindAddrStr, char *bindPortStr, bool isBindin int res = bind(*(int *)socket, (struct sockaddr *)&bindSockaddr, sizeof(bindSockaddr)); #endif return (res >= 0); +} + +int uart_parse_address_port(char *addrPortStr, const char **addrStr, const char **portStr, bool *isIPv6) { + + if (addrPortStr == NULL || addrStr == NULL || portStr == NULL) { + return PM3_EINVARG; + } + + *addrStr = addrPortStr; + *portStr = NULL; + + // find the start of the address + char *endBracket = strrchr(addrPortStr, ']'); + if (addrPortStr[0] == '[') { + *addrStr += 1; + if (endBracket == NULL) { + // [] unmatched + return PM3_ESOFT; + } + } + + if (isIPv6 != NULL) { + // Assume v4 + *isIPv6 = false; + } + + // find the port + char *lColon = strchr(addrPortStr, ':'); + char *rColon = strrchr(addrPortStr, ':'); + if (rColon == NULL) { + // no colon + // "", "[]" + *portStr = NULL; + } else if (lColon == rColon) { + // only one colon + // ":", "[]:" + *portStr = rColon + 1; + } else { + // two or more colon, IPv6 address + // "[]:" + // "", "[]" + if (endBracket != NULL && rColon == endBracket + 1) { + *portStr = rColon + 1; + } else { + *portStr = NULL; + } + + if (isIPv6 != NULL) { + *isIPv6 = true; + } + } + + // handle the end of the address + if (endBracket != NULL) { + *endBracket = '\0'; + } else if (rColon != NULL && lColon == rColon) { + *rColon = '\0'; + } + + return PM3_SUCCESS; } \ No newline at end of file diff --git a/client/src/uart/uart_posix.c b/client/src/uart/uart_posix.c index 267e0fe43..ee94fc31f 100644 --- a/client/src/uart/uart_posix.c +++ b/client/src/uart/uart_posix.c @@ -114,8 +114,6 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) { struct addrinfo *addr = NULL, *rp; char *addrPortStr = str_dup(pcPortName + 4); - char *addrstr = addrPortStr; - const char *portstr; if (addrPortStr == NULL) { PrintAndLogEx(ERR, "error: string duplication"); free(sp); @@ -126,54 +124,24 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) { // find the "bind" option char *bindAddrPortStr = strstr(addrPortStr, ",bind="); - char *bindAddrStr = NULL; - char *bindPortStr = NULL; - bool isBindingIPv6 = false; // Assume v4 + const char *bindAddrStr = NULL; + const char *bindPortStr = NULL; + bool isBindingIPv6 = false; + if (bindAddrPortStr != NULL) { *bindAddrPortStr = '\0'; // as the end of target address (and port) - bindAddrPortStr += 6; - bindAddrStr = bindAddrPortStr; + bindAddrPortStr += 6; // strlen(",bind=") - // find the start of the bind address - char *endBracket = strrchr(bindAddrPortStr, ']'); - if (bindAddrPortStr[0] == '[') { - bindAddrStr += 1; - if (endBracket == NULL) { + int result = uart_parse_address_port(bindAddrPortStr, &bindAddrStr, &bindPortStr, &isBindingIPv6); + if (result != PM3_SUCCESS) { + if (result == PM3_ESOFT) { PrintAndLogEx(ERR, "error: wrong address: [] unmatched in bind option"); - free(addrPortStr); - free(sp); - return INVALID_SERIAL_PORT; - } - } - - // find the bind port - char *lColon = strchr(bindAddrPortStr, ':'); - char *rColon = strrchr(bindAddrPortStr, ':'); - if (rColon == NULL) { - // no colon - // ",bind=", ",bind=[]" - bindPortStr = NULL; - } else if (lColon == rColon) { - // only one colon - // ",bind=:", ",bind=[]:" - bindPortStr = rColon + 1; - } else { - // two or more colon, IPv6 address - // ",bind=[]:" - // ",bind=", ",bind=[]" - if (endBracket != NULL && rColon == endBracket + 1) { - bindPortStr = rColon + 1; } else { - bindPortStr = NULL; + PrintAndLogEx(ERR, "error: failed to parse address and port in bind option"); } - isBindingIPv6 = true; - } - - // handle the end of the bind address - if (endBracket != NULL) { - *endBracket = '\0'; - } else if (rColon != NULL && lColon == rColon) { - *rColon = '\0'; + free(addrPortStr); + free(sp); + return INVALID_SERIAL_PORT; } // for bind option, it's possible to only specify address or port @@ -183,51 +151,24 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) { bindPortStr = NULL; } - // find the start of the address - char *endBracket = strrchr(addrPortStr, ']'); - if (addrPortStr[0] == '[') { - addrstr += 1; - if (endBracket == NULL) { + const char *addrStr = NULL; + const char *portStr = NULL; + bool isIPv6 = false; + + int result = uart_parse_address_port(addrPortStr, &addrStr, &portStr, &isIPv6); + if (result != PM3_SUCCESS) { + if (result == PM3_ESOFT) { PrintAndLogEx(ERR, "error: wrong address: [] unmatched"); - free(addrPortStr); - free(sp); - return INVALID_SERIAL_PORT; - } - } - - - // assume v4 - g_conn.send_via_ip = PM3_TCPv4; - - // find the port - char *lColon = strchr(addrPortStr, ':'); - char *rColon = strrchr(addrPortStr, ':'); - if (rColon == NULL) { - // no colon - // "tcp:", "tcp:[]" - portstr = "18888"; - } else if (lColon == rColon) { - // only one colon - // "tcp::", "tcp:[]:" - portstr = rColon + 1; - } else { - // two or more colon, IPv6 address - // "tcp:[]:" - // "tcp:", "tcp:[]" - if (endBracket != NULL && rColon == endBracket + 1) { - portstr = rColon + 1; } else { - portstr = "18888"; + PrintAndLogEx(ERR, "error: failed to parse address and port"); } - g_conn.send_via_ip = PM3_TCPv6; + free(addrPortStr); + free(sp); + return INVALID_SERIAL_PORT; } - // handle the end of the address - if (endBracket != NULL) { - *endBracket = '\0'; - } else if (rColon != NULL && lColon == rColon) { - *rColon = '\0'; - } + g_conn.send_via_ip = isIPv6 ? PM3_TCPv6 : PM3_TCPv4; + portStr = (portStr == NULL) ? "18888" : portStr; struct addrinfo info; @@ -236,13 +177,13 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) { info.ai_family = PF_UNSPEC; info.ai_socktype = SOCK_STREAM; - if ((strstr(addrstr, "localhost") != NULL) || - (strstr(addrstr, "127.0.0.1") != NULL) || - (strstr(addrstr, "::1") != NULL)) { + if ((strstr(addrStr, "localhost") != NULL) || + (strstr(addrStr, "127.0.0.1") != NULL) || + (strstr(addrStr, "::1") != NULL)) { g_conn.send_via_local_ip = true; } - int s = getaddrinfo(addrstr, portstr, &info, &addr); + int s = getaddrinfo(addrStr, portStr, &info, &addr); if (s != 0) { PrintAndLogEx(ERR, "error: getaddrinfo: %s", gai_strerror(s)); freeaddrinfo(addr); @@ -306,8 +247,6 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) { struct addrinfo *addr = NULL, *rp; char *addrPortStr = str_dup(pcPortName + 4); - char *addrstr = addrPortStr; - const char *portstr; if (addrPortStr == NULL) { PrintAndLogEx(ERR, "error: string duplication"); free(sp); @@ -318,54 +257,24 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) { // find the "bind" option char *bindAddrPortStr = strstr(addrPortStr, ",bind="); - char *bindAddrStr = NULL; - char *bindPortStr = NULL; - bool isBindingIPv6 = false; // Assume v4 + const char *bindAddrStr = NULL; + const char *bindPortStr = NULL; + bool isBindingIPv6 = false; + if (bindAddrPortStr != NULL) { *bindAddrPortStr = '\0'; // as the end of target address (and port) - bindAddrPortStr += 6; - bindAddrStr = bindAddrPortStr; + bindAddrPortStr += 6; // strlen(",bind=") - // find the start of the bind address - char *endBracket = strrchr(bindAddrPortStr, ']'); - if (bindAddrPortStr[0] == '[') { - bindAddrStr += 1; - if (endBracket == NULL) { + int result = uart_parse_address_port(bindAddrPortStr, &bindAddrStr, &bindPortStr, &isBindingIPv6); + if (result != PM3_SUCCESS) { + if (result == PM3_ESOFT) { PrintAndLogEx(ERR, "error: wrong address: [] unmatched in bind option"); - free(addrPortStr); - free(sp); - return INVALID_SERIAL_PORT; - } - } - - // find the bind port - char *lColon = strchr(bindAddrPortStr, ':'); - char *rColon = strrchr(bindAddrPortStr, ':'); - if (rColon == NULL) { - // no colon - // ",bind=", ",bind=[]" - bindPortStr = NULL; - } else if (lColon == rColon) { - // only one colon - // ",bind=:", ",bind=[]:" - bindPortStr = rColon + 1; - } else { - // two or more colon, IPv6 address - // ",bind=[]:" - // ",bind=", ",bind=[]" - if (endBracket != NULL && rColon == endBracket + 1) { - bindPortStr = rColon + 1; } else { - bindPortStr = NULL; + PrintAndLogEx(ERR, "error: failed to parse address and port in bind option"); } - isBindingIPv6 = true; - } - - // handle the end of the bind address - if (endBracket != NULL) { - *endBracket = '\0'; - } else if (rColon != NULL && lColon == rColon) { - *rColon = '\0'; + free(addrPortStr); + free(sp); + return INVALID_SERIAL_PORT; } // for bind option, it's possible to only specify address or port @@ -375,50 +284,24 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) { bindPortStr = NULL; } - // find the start of the address - char *endBracket = strrchr(addrPortStr, ']'); - if (addrPortStr[0] == '[') { - addrstr += 1; - if (endBracket == NULL) { + const char *addrStr = NULL; + const char *portStr = NULL; + bool isIPv6 = false; + + int result = uart_parse_address_port(addrPortStr, &addrStr, &portStr, &isIPv6); + if (result != PM3_SUCCESS) { + if (result == PM3_ESOFT) { PrintAndLogEx(ERR, "error: wrong address: [] unmatched"); - free(addrPortStr); - free(sp); - return INVALID_SERIAL_PORT; - } - } - - // Assume v4 - g_conn.send_via_ip = PM3_UDPv4; - - // find the port - char *lColon = strchr(addrPortStr, ':'); - char *rColon = strrchr(addrPortStr, ':'); - if (rColon == NULL) { - // no colon - // "udp:", "udp:[]" - portstr = "18888"; - } else if (lColon == rColon) { - // only one colon - // "udp::", "udp:[]:" - portstr = rColon + 1; - } else { - // two or more colon, IPv6 address - // "udp:[]:" - // "udp:", "udp:[]" - if (endBracket != NULL && rColon == endBracket + 1) { - portstr = rColon + 1; } else { - portstr = "18888"; + PrintAndLogEx(ERR, "error: failed to parse address and port"); } - g_conn.send_via_ip = PM3_UDPv6; + free(addrPortStr); + free(sp); + return INVALID_SERIAL_PORT; } - // handle the end of the address - if (endBracket != NULL) { - *endBracket = '\0'; - } else if (rColon != NULL && lColon == rColon) { - *rColon = '\0'; - } + g_conn.send_via_ip = isIPv6 ? PM3_UDPv6 : PM3_UDPv4; + portStr = (portStr == NULL) ? "18888" : portStr; struct addrinfo info; @@ -427,13 +310,13 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) { info.ai_family = PF_UNSPEC; info.ai_socktype = SOCK_DGRAM; - if ((strstr(addrstr, "localhost") != NULL) || - (strstr(addrstr, "127.0.0.1") != NULL) || - (strstr(addrstr, "::1") != NULL)) { + if ((strstr(addrStr, "localhost") != NULL) || + (strstr(addrStr, "127.0.0.1") != NULL) || + (strstr(addrStr, "::1") != NULL)) { g_conn.send_via_local_ip = true; } - int s = getaddrinfo(addrstr, portstr, &info, &addr); + int s = getaddrinfo(addrStr, portStr, &info, &addr); if (s != 0) { PrintAndLogEx(ERR, "error: getaddrinfo: %s", gai_strerror(s)); freeaddrinfo(addr); diff --git a/client/src/uart/uart_win32.c b/client/src/uart/uart_win32.c index f91a69290..df6b51f9d 100644 --- a/client/src/uart/uart_win32.c +++ b/client/src/uart/uart_win32.c @@ -115,8 +115,6 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) { struct addrinfo *addr = NULL, *rp; char *addrPortStr = str_dup(pcPortName + 4); - char *addrstr = addrPortStr; - const char *portstr; if (addrPortStr == NULL) { PrintAndLogEx(ERR, "error: string duplication"); free(sp); @@ -127,54 +125,24 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) { // find the "bind" option char *bindAddrPortStr = strstr(addrPortStr, ",bind="); - char *bindAddrStr = NULL; - char *bindPortStr = NULL; - bool isBindingIPv6 = false; // Assume v4 + const char *bindAddrStr = NULL; + const char *bindPortStr = NULL; + bool isBindingIPv6 = false; + if (bindAddrPortStr != NULL) { *bindAddrPortStr = '\0'; // as the end of target address (and port) - bindAddrPortStr += 6; - bindAddrStr = bindAddrPortStr; + bindAddrPortStr += 6; // strlen(",bind=") - // find the start of the bind address - char *endBracket = strrchr(bindAddrPortStr, ']'); - if (bindAddrPortStr[0] == '[') { - bindAddrStr += 1; - if (endBracket == NULL) { + int result = uart_parse_address_port(bindAddrPortStr, &bindAddrStr, &bindPortStr, &isBindingIPv6); + if (result != PM3_SUCCESS) { + if (result == PM3_ESOFT) { PrintAndLogEx(ERR, "error: wrong address: [] unmatched in bind option"); - free(addrPortStr); - free(sp); - return INVALID_SERIAL_PORT; - } - } - - // find the bind port - char *lColon = strchr(bindAddrPortStr, ':'); - char *rColon = strrchr(bindAddrPortStr, ':'); - if (rColon == NULL) { - // no colon - // ",bind=", ",bind=[]" - bindPortStr = NULL; - } else if (lColon == rColon) { - // only one colon - // ",bind=:", ",bind=[]:" - bindPortStr = rColon + 1; - } else { - // two or more colon, IPv6 address - // ",bind=[]:" - // ",bind=", ",bind=[]" - if (endBracket != NULL && rColon == endBracket + 1) { - bindPortStr = rColon + 1; } else { - bindPortStr = NULL; + PrintAndLogEx(ERR, "error: failed to parse address and port in bind option"); } - isBindingIPv6 = true; - } - - // handle the end of the bind address - if (endBracket != NULL) { - *endBracket = '\0'; - } else if (rColon != NULL && lColon == rColon) { - *rColon = '\0'; + free(addrPortStr); + free(sp); + return INVALID_SERIAL_PORT; } // for bind option, it's possible to only specify address or port @@ -184,50 +152,24 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) { bindPortStr = NULL; } - // find the start of the address - char *endBracket = strrchr(addrPortStr, ']'); - if (addrPortStr[0] == '[') { - addrstr += 1; - if (endBracket == NULL) { + const char *addrStr = NULL; + const char *portStr = NULL; + bool isIPv6 = false; + + int result = uart_parse_address_port(addrPortStr, &addrStr, &portStr, &isIPv6); + if (result != PM3_SUCCESS) { + if (result == PM3_ESOFT) { PrintAndLogEx(ERR, "error: wrong address: [] unmatched"); - free(addrPortStr); - free(sp); - return INVALID_SERIAL_PORT; - } - } - - // Assume v4 - g_conn.send_via_ip = PM3_TCPv4; - - // find the port - char *lColon = strchr(addrPortStr, ':'); - char *rColon = strrchr(addrPortStr, ':'); - if (rColon == NULL) { - // no colon - // "tcp:", "tcp:[]" - portstr = "18888"; - } else if (lColon == rColon) { - // only one colon - // "tcp::", "tcp:[]:" - portstr = rColon + 1; - } else { - // two or more colon, IPv6 address - // "tcp:[]:" - // "tcp:", "tcp:[]" - if (endBracket != NULL && rColon == endBracket + 1) { - portstr = rColon + 1; } else { - portstr = "18888"; + PrintAndLogEx(ERR, "error: failed to parse address and port"); } - g_conn.send_via_ip = PM3_TCPv6; + free(addrPortStr); + free(sp); + return INVALID_SERIAL_PORT; } - // handle the end of the address - if (endBracket != NULL) { - *endBracket = '\0'; - } else if (rColon != NULL && lColon == rColon) { - *rColon = '\0'; - } + g_conn.send_via_ip = isIPv6 ? PM3_TCPv6 : PM3_TCPv4; + portStr = (portStr == NULL) ? "18888" : portStr; WSADATA wsaData; struct addrinfo info; @@ -246,13 +188,13 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) { info.ai_socktype = SOCK_STREAM; info.ai_protocol = IPPROTO_TCP; - if ((strstr(addrstr, "localhost") != NULL) || - (strstr(addrstr, "127.0.0.1") != NULL) || - (strstr(addrstr, "::1") != NULL)) { + if ((strstr(addrStr, "localhost") != NULL) || + (strstr(addrStr, "127.0.0.1") != NULL) || + (strstr(addrStr, "::1") != NULL)) { g_conn.send_via_local_ip = true; } - int s = getaddrinfo(addrstr, portstr, &info, &addr); + int s = getaddrinfo(addrStr, portStr, &info, &addr); if (s != 0) { PrintAndLogEx(ERR, "error: getaddrinfo: %d: %s", s, gai_strerror(s)); freeaddrinfo(addr); @@ -322,8 +264,6 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) { struct addrinfo *addr = NULL, *rp; char *addrPortStr = str_dup(pcPortName + 4); - char *addrstr = addrPortStr; - const char *portstr; if (addrPortStr == NULL) { PrintAndLogEx(ERR, "error: string duplication"); free(sp); @@ -334,54 +274,24 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) { // find the "bind" option char *bindAddrPortStr = strstr(addrPortStr, ",bind="); - char *bindAddrStr = NULL; - char *bindPortStr = NULL; - bool isBindingIPv6 = false; // Assume v4 + const char *bindAddrStr = NULL; + const char *bindPortStr = NULL; + bool isBindingIPv6 = false; + if (bindAddrPortStr != NULL) { *bindAddrPortStr = '\0'; // as the end of target address (and port) - bindAddrPortStr += 6; - bindAddrStr = bindAddrPortStr; + bindAddrPortStr += 6; // strlen(",bind=") - // find the start of the bind address - char *endBracket = strrchr(bindAddrPortStr, ']'); - if (bindAddrPortStr[0] == '[') { - bindAddrStr += 1; - if (endBracket == NULL) { + int result = uart_parse_address_port(bindAddrPortStr, &bindAddrStr, &bindPortStr, &isBindingIPv6); + if (result != PM3_SUCCESS) { + if (result == PM3_ESOFT) { PrintAndLogEx(ERR, "error: wrong address: [] unmatched in bind option"); - free(addrPortStr); - free(sp); - return INVALID_SERIAL_PORT; - } - } - - // find the bind port - char *lColon = strchr(bindAddrPortStr, ':'); - char *rColon = strrchr(bindAddrPortStr, ':'); - if (rColon == NULL) { - // no colon - // ",bind=", ",bind=[]" - bindPortStr = NULL; - } else if (lColon == rColon) { - // only one colon - // ",bind=:", ",bind=[]:" - bindPortStr = rColon + 1; - } else { - // two or more colon, IPv6 address - // ",bind=[]:" - // ",bind=", ",bind=[]" - if (endBracket != NULL && rColon == endBracket + 1) { - bindPortStr = rColon + 1; } else { - bindPortStr = NULL; + PrintAndLogEx(ERR, "error: failed to parse address and port in bind option"); } - isBindingIPv6 = true; - } - - // handle the end of the bind address - if (endBracket != NULL) { - *endBracket = '\0'; - } else if (rColon != NULL && lColon == rColon) { - *rColon = '\0'; + free(addrPortStr); + free(sp); + return INVALID_SERIAL_PORT; } // for bind option, it's possible to only specify address or port @@ -391,50 +301,24 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) { bindPortStr = NULL; } - // find the start of the address - char *endBracket = strrchr(addrPortStr, ']'); - if (addrPortStr[0] == '[') { - addrstr += 1; - if (endBracket == NULL) { + const char *addrStr = NULL; + const char *portStr = NULL; + bool isIPv6 = false; + + int result = uart_parse_address_port(addrPortStr, &addrStr, &portStr, &isIPv6); + if (result != PM3_SUCCESS) { + if (result == PM3_ESOFT) { PrintAndLogEx(ERR, "error: wrong address: [] unmatched"); - free(addrPortStr); - free(sp); - return INVALID_SERIAL_PORT; - } - } - - // Assume v4 - g_conn.send_via_ip = PM3_UDPv4; - - // find the port - char *lColon = strchr(addrPortStr, ':'); - char *rColon = strrchr(addrPortStr, ':'); - if (rColon == NULL) { - // no colon - // "udp:", "udp:[]" - portstr = "18888"; - } else if (lColon == rColon) { - // only one colon - // "udp::", "udp:[]:" - portstr = rColon + 1; - } else { - // two or more colon, IPv6 address - // "udp:[]:" - // "udp:", "udp:[]" - if (endBracket != NULL && rColon == endBracket + 1) { - portstr = rColon + 1; } else { - portstr = "18888"; + PrintAndLogEx(ERR, "error: failed to parse address and port"); } - g_conn.send_via_ip = PM3_UDPv6; + free(addrPortStr); + free(sp); + return INVALID_SERIAL_PORT; } - // handle the end of the address - if (endBracket != NULL) { - *endBracket = '\0'; - } else if (rColon != NULL && lColon == rColon) { - *rColon = '\0'; - } + g_conn.send_via_ip = isIPv6 ? PM3_UDPv6 : PM3_UDPv4; + portStr = (portStr == NULL) ? "18888" : portStr; WSADATA wsaData; struct addrinfo info; @@ -453,13 +337,13 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) { info.ai_socktype = SOCK_DGRAM; info.ai_protocol = IPPROTO_UDP; - if ((strstr(addrstr, "localhost") != NULL) || - (strstr(addrstr, "127.0.0.1") != NULL) || - (strstr(addrstr, "::1") != NULL)) { + if ((strstr(addrStr, "localhost") != NULL) || + (strstr(addrStr, "127.0.0.1") != NULL) || + (strstr(addrStr, "::1") != NULL)) { g_conn.send_via_local_ip = true; } - int s = getaddrinfo(addrstr, portstr, &info, &addr); + int s = getaddrinfo(addrStr, portStr, &info, &addr); if (s != 0) { PrintAndLogEx(ERR, "error: getaddrinfo: %d: %s", s, gai_strerror(s)); freeaddrinfo(addr);