mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-23 06:35:38 -07:00
Add IPv6 support for TCP (Linux)
This commit is contained in:
parent
5266321983
commit
2e0c24c8f2
1 changed files with 45 additions and 10 deletions
|
@ -108,8 +108,10 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
|
||||||
|
|
||||||
struct addrinfo *addr = NULL, *rp;
|
struct addrinfo *addr = NULL, *rp;
|
||||||
|
|
||||||
char *addrstr = strdup(pcPortName + 4);
|
char *addrPortStr = strdup(pcPortName + 4);
|
||||||
if (addrstr == NULL) {
|
char *addrstr = addrPortStr;
|
||||||
|
const char *portstr;
|
||||||
|
if (addrPortStr == NULL) {
|
||||||
PrintAndLogEx(ERR, "error: string duplication");
|
PrintAndLogEx(ERR, "error: string duplication");
|
||||||
free(sp);
|
free(sp);
|
||||||
return INVALID_SERIAL_PORT;
|
return INVALID_SERIAL_PORT;
|
||||||
|
@ -117,26 +119,59 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
|
||||||
|
|
||||||
timeout.tv_usec = UART_TCP_CLIENT_RX_TIMEOUT_MS * 1000;
|
timeout.tv_usec = UART_TCP_CLIENT_RX_TIMEOUT_MS * 1000;
|
||||||
|
|
||||||
char *colon = strrchr(addrstr, ':');
|
// find the start of the address
|
||||||
const char *portstr;
|
char *endBracket = strrchr(addrPortStr, ']');
|
||||||
if (colon) {
|
if (addrPortStr[0] == '[') {
|
||||||
portstr = colon + 1;
|
addrstr += 1;
|
||||||
*colon = '\0';
|
if (endBracket == NULL) {
|
||||||
} else {
|
PrintAndLogEx(ERR, "error: wrong address: [] unmatched");
|
||||||
|
free(addrPortStr);
|
||||||
|
free(sp);
|
||||||
|
return INVALID_SERIAL_PORT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// find the port
|
||||||
|
char *lColon = strchr(addrPortStr, ':');
|
||||||
|
char *rColon = strrchr(addrPortStr, ':');
|
||||||
|
if (rColon == NULL) {
|
||||||
|
// no colon
|
||||||
|
// "tcp:<ipv4 address>", "tcp:[<ipv4 address>]"
|
||||||
portstr = "18888";
|
portstr = "18888";
|
||||||
|
} else if (lColon == rColon) {
|
||||||
|
// only one colon
|
||||||
|
// "tcp:<ipv4 address>:<port>", "tcp:[<ipv4 address>]:<port>"
|
||||||
|
portstr = rColon + 1;
|
||||||
|
} else {
|
||||||
|
// two or more colon, IPv6 address
|
||||||
|
// tcp:[<ipv6 address>]:<port>
|
||||||
|
// "tcp:<ipv6 address>", "tcp:[<ipv6 address>]"
|
||||||
|
if (endBracket != NULL && rColon == endBracket + 1) {
|
||||||
|
portstr = rColon + 1;
|
||||||
|
} else {
|
||||||
|
portstr = "18888";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// handle the end of the address
|
||||||
|
if (endBracket != NULL) {
|
||||||
|
*endBracket = '\0';
|
||||||
|
} else if (rColon != NULL && lColon == rColon) {
|
||||||
|
*rColon = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
struct addrinfo info;
|
struct addrinfo info;
|
||||||
|
|
||||||
memset(&info, 0, sizeof(info));
|
memset(&info, 0, sizeof(info));
|
||||||
|
|
||||||
|
info.ai_family = PF_UNSPEC;
|
||||||
info.ai_socktype = SOCK_STREAM;
|
info.ai_socktype = SOCK_STREAM;
|
||||||
|
|
||||||
int s = getaddrinfo(addrstr, portstr, &info, &addr);
|
int s = getaddrinfo(addrstr, portstr, &info, &addr);
|
||||||
if (s != 0) {
|
if (s != 0) {
|
||||||
PrintAndLogEx(ERR, "error: getaddrinfo: %s", gai_strerror(s));
|
PrintAndLogEx(ERR, "error: getaddrinfo: %s", gai_strerror(s));
|
||||||
freeaddrinfo(addr);
|
freeaddrinfo(addr);
|
||||||
free(addrstr);
|
free(addrPortStr);
|
||||||
free(sp);
|
free(sp);
|
||||||
return INVALID_SERIAL_PORT;
|
return INVALID_SERIAL_PORT;
|
||||||
}
|
}
|
||||||
|
@ -155,7 +190,7 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
|
||||||
}
|
}
|
||||||
|
|
||||||
freeaddrinfo(addr);
|
freeaddrinfo(addr);
|
||||||
free(addrstr);
|
free(addrPortStr);
|
||||||
|
|
||||||
if (rp == NULL) { /* No address succeeded */
|
if (rp == NULL) { /* No address succeeded */
|
||||||
PrintAndLogEx(ERR, "error: Could not connect");
|
PrintAndLogEx(ERR, "error: Could not connect");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue