|
From: openocd-gerrit <ope...@us...> - 2026-05-30 18:16:44
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Main OpenOCD repository".
The branch, master has been updated
via 9013ad2e5ebbb2e64f3af1c75cc33164f93c4a08 (commit)
from 5bc49ef84c4beb0e83989a7ced551987b743c2b5 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 9013ad2e5ebbb2e64f3af1c75cc33164f93c4a08
Author: Marc Schink <de...@za...>
Date: Wed May 13 02:29:16 2026 +0200
adapter/jtag-dpi: Use getaddrinfo() to support hostnames and IPv6
Connection establishment currently supports only IPv4 addresses via
inet_addr(). Replace inet_addr() with getaddrinfo() to allow using
hostnames and to add IPv6 support.
Change-Id: Iafcb9e7f120e2c002989ec8587a8cee5c410fed4
Signed-off-by: Marc Schink <de...@za...>
Reviewed-on: https://review.openocd.org/c/openocd/+/9656
Tested-by: jenkins
Reviewed-by: Antonio Borneo <bor...@gm...>
diff --git a/doc/openocd.texi b/doc/openocd.texi
index fbe8cc282..fc6fad101 100644
--- a/doc/openocd.texi
+++ b/doc/openocd.texi
@@ -3695,7 +3695,7 @@ Specifies the TCP/IP port number of the SystemVerilog DPI server interface.
@end deffn
@deffn {Config Command} {jtag_dpi set_address} address
-Specifies the TCP/IP address of the SystemVerilog DPI server interface.
+Specifies the hostname or IP address of the SystemVerilog DPI server interface.
@end deffn
@end deffn
diff --git a/src/jtag/drivers/jtag_dpi.c b/src/jtag/drivers/jtag_dpi.c
index 35dd24507..d5a42b1fb 100644
--- a/src/jtag/drivers/jtag_dpi.c
+++ b/src/jtag/drivers/jtag_dpi.c
@@ -16,6 +16,9 @@
#endif
#include <jtag/interface.h>
+#ifdef HAVE_NETDB_H
+#include <netdb.h>
+#endif
#ifdef HAVE_ARPA_INET_H
#include <arpa/inet.h>
#endif
@@ -31,7 +34,6 @@ static uint16_t server_port = SERVER_PORT;
static char *server_address;
static int sockfd;
-static struct sockaddr_in serv_addr;
static uint8_t *last_ir_buf;
static int last_ir_num_bits;
@@ -264,18 +266,6 @@ static int jtag_dpi_execute_queue(struct jtag_command *cmd_queue)
static int jtag_dpi_init(void)
{
- sockfd = socket(AF_INET, SOCK_STREAM, 0);
- if (sockfd < 0) {
- LOG_ERROR("socket: %s, function %s, file %s, line %d",
- strerror(errno), __func__, __FILE__, __LINE__);
- return ERROR_FAIL;
- }
-
- memset(&serv_addr, 0, sizeof(serv_addr));
-
- serv_addr.sin_family = AF_INET;
- serv_addr.sin_port = htons(server_port);
-
if (!server_address) {
server_address = strdup(SERVER_ADDRESS);
if (!server_address) {
@@ -285,26 +275,65 @@ static int jtag_dpi_init(void)
}
}
- serv_addr.sin_addr.s_addr = inet_addr(server_address);
+ const struct addrinfo hints = {
+ .ai_family = AF_UNSPEC,
+ .ai_socktype = SOCK_STREAM
+ };
+
+ char port_str[5 + 1];
+ snprintf(port_str, sizeof(port_str), "%" PRIu16, server_port);
- if (serv_addr.sin_addr.s_addr == INADDR_NONE) {
- LOG_ERROR("inet_addr error occurred");
+ struct addrinfo *result;
+ int ret = getaddrinfo(server_address, port_str, &hints, &result);
+
+ if (ret != 0) {
+ LOG_ERROR("getaddrinfo: %s", gai_strerror(ret));
return ERROR_FAIL;
}
- if (connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) {
+ struct addrinfo *rp;
+ for (rp = result; rp ; rp = rp->ai_next) {
+ sockfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
+ if (sockfd == -1)
+ continue;
+
+ if (connect(sockfd, rp->ai_addr, rp->ai_addrlen) != -1)
+ break;
+
close(sockfd);
- LOG_ERROR("Can't connect to %s : %" PRIu16, server_address, server_port);
+ }
+
+ if (!rp) {
+ LOG_ERROR("Can't connect to %s : %" PRIu16, server_address,
+ server_port);
+ freeaddrinfo(result);
return ERROR_FAIL;
}
- if (serv_addr.sin_addr.s_addr == htonl(INADDR_LOOPBACK)) {
+
+ bool is_loopback = false;
+ if (rp->ai_family == AF_INET) {
+ struct sockaddr_in sa;
+ memcpy(&sa, rp->ai_addr, sizeof(sa));
+ is_loopback = (sa.sin_addr.s_addr == htonl(INADDR_LOOPBACK));
+ } else if (rp->ai_family == AF_INET6) {
+ struct sockaddr_in6 sa;
+ memcpy(&sa, rp->ai_addr, sizeof(sa));
+ is_loopback = IN6_IS_ADDR_LOOPBACK(&sa.sin6_addr);
+ }
+
+ if (is_loopback) {
+ LOG_DEBUG("Enabling TCP_NODELAY to enhance the speed of local connections");
+
/* This increases performance dramatically for local
* connections, which is the most likely arrangement
* for a DPI connection. */
int flag = 1;
- setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(int));
+ setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag,
+ sizeof(int));
}
+ freeaddrinfo(result);
+
LOG_INFO("Connection to %s : %" PRIu16 " succeed", server_address, server_port);
return ERROR_OK;
@@ -372,7 +401,7 @@ static const struct command_registration jtag_dpi_subcommand_handlers[] = {
.name = "set_address",
.handler = &jtag_dpi_set_address,
.mode = COMMAND_CONFIG,
- .help = "set the address of the DPI server",
+ .help = "set the hostname or IP address of the DPI server",
.usage = "[address]",
},
COMMAND_REGISTRATION_DONE
-----------------------------------------------------------------------
Summary of changes:
doc/openocd.texi | 2 +-
src/jtag/drivers/jtag_dpi.c | 71 +++++++++++++++++++++++++++++++--------------
2 files changed, 51 insertions(+), 22 deletions(-)
hooks/post-receive
--
Main OpenOCD repository
|