Clean up the code for timeout
Rename UART_TCP_CLIENT_RX_TIMEOUT_MS to UART_NET_CLIENT_RX_TIMEOUT_MS Add UART_UDP_LOCAL_CLIENT_RX_TIMEOUT_MS for shorter timeout Check if the target address is local in uart_open()
This commit is contained in:
5 files changed
+47
-20
No files matched your search
@@ -91,6 +91,8 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
|
||||
sp->udpBuffer = NULL;
|
||||
// init timeouts
|
||||
timeout.tv_usec = UART_FPC_CLIENT_RX_TIMEOUT_MS * 1000;
|
||||
g_conn.send_via_local_ip = false;
|
||||
g_conn.send_via_ip = PM3_NONE;
|
||||
|
||||
char *prefix = strdup(pcPortName);
|
||||
if (prefix == NULL) {
|
||||
@@ -119,7 +121,7 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
|
||||
return INVALID_SERIAL_PORT;
|
||||
}
|
||||
|
||||
timeout.tv_usec = UART_TCP_CLIENT_RX_TIMEOUT_MS * 1000;
|
||||
timeout.tv_usec = UART_NET_CLIENT_RX_TIMEOUT_MS * 1000;
|
||||
|
||||
// find the "bind" option
|
||||
char *bindAddrPortStr = strstr(addrPortStr, ",bind=");
|
||||
@@ -233,6 +235,12 @@ 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)) {
|
||||
g_conn.send_via_local_ip = true;
|
||||
}
|
||||
|
||||
int s = getaddrinfo(addrstr, portstr, &info, &addr);
|
||||
if (s != 0) {
|
||||
PrintAndLogEx(ERR, "error: getaddrinfo: %s", gai_strerror(s));
|
||||
@@ -304,7 +312,7 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
|
||||
return INVALID_SERIAL_PORT;
|
||||
}
|
||||
|
||||
timeout.tv_usec = UART_TCP_CLIENT_RX_TIMEOUT_MS * 1000;
|
||||
timeout.tv_usec = UART_NET_CLIENT_RX_TIMEOUT_MS * 1000;
|
||||
|
||||
// find the "bind" option
|
||||
char *bindAddrPortStr = strstr(addrPortStr, ",bind=");
|
||||
@@ -417,6 +425,12 @@ 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)) {
|
||||
g_conn.send_via_local_ip = true;
|
||||
}
|
||||
|
||||
int s = getaddrinfo(addrstr, portstr, &info, &addr);
|
||||
if (s != 0) {
|
||||
PrintAndLogEx(ERR, "error: getaddrinfo: %s", gai_strerror(s));
|
||||
@@ -528,7 +542,7 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
|
||||
}
|
||||
|
||||
// we must use max timeout!
|
||||
timeout.tv_usec = UART_TCP_CLIENT_RX_TIMEOUT_MS * 1000;
|
||||
timeout.tv_usec = UART_NET_CLIENT_RX_TIMEOUT_MS * 1000;
|
||||
|
||||
size_t servernameLen = (strlen(pcPortName) - 7) + 1;
|
||||
char serverNameBuf[servernameLen];
|
||||
|
||||
@@ -44,7 +44,7 @@ typedef struct {
|
||||
// this is for TCP connection
|
||||
struct timeval timeout = {
|
||||
.tv_sec = 0, // 0 second
|
||||
.tv_usec = UART_TCP_CLIENT_RX_TIMEOUT_MS * 1000
|
||||
.tv_usec = UART_NET_CLIENT_RX_TIMEOUT_MS * 1000
|
||||
};
|
||||
|
||||
uint32_t newtimeout_value = 0;
|
||||
@@ -92,6 +92,8 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
|
||||
}
|
||||
|
||||
sp->udpBuffer = NULL;
|
||||
g_conn.send_via_local_ip = false;
|
||||
g_conn.send_via_ip = PM3_NONE;
|
||||
|
||||
char *prefix = strdup(pcPortName);
|
||||
if (prefix == NULL) {
|
||||
@@ -121,7 +123,7 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
|
||||
return INVALID_SERIAL_PORT;
|
||||
}
|
||||
|
||||
timeout.tv_usec = UART_TCP_CLIENT_RX_TIMEOUT_MS * 1000;
|
||||
timeout.tv_usec = UART_NET_CLIENT_RX_TIMEOUT_MS * 1000;
|
||||
|
||||
// find the "bind" option
|
||||
char *bindAddrPortStr = strstr(addrPortStr, ",bind=");
|
||||
@@ -244,6 +246,12 @@ 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)) {
|
||||
g_conn.send_via_local_ip = true;
|
||||
}
|
||||
|
||||
int s = getaddrinfo(addrstr, portstr, &info, &addr);
|
||||
if (s != 0) {
|
||||
PrintAndLogEx(ERR, "error: getaddrinfo: %d: %s", s, gai_strerror(s));
|
||||
@@ -322,7 +330,7 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
|
||||
return INVALID_SERIAL_PORT;
|
||||
}
|
||||
|
||||
timeout.tv_usec = UART_TCP_CLIENT_RX_TIMEOUT_MS * 1000;
|
||||
timeout.tv_usec = UART_NET_CLIENT_RX_TIMEOUT_MS * 1000;
|
||||
|
||||
// find the "bind" option
|
||||
char *bindAddrPortStr = strstr(addrPortStr, ",bind=");
|
||||
@@ -445,6 +453,12 @@ 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)) {
|
||||
g_conn.send_via_local_ip = true;
|
||||
}
|
||||
|
||||
int s = getaddrinfo(addrstr, portstr, &info, &addr);
|
||||
if (s != 0) {
|
||||
PrintAndLogEx(ERR, "error: getaddrinfo: %d: %s", s, gai_strerror(s));
|
||||
|
||||
Reference in new issue
Block a user