1
0

Use a random port number for JTAG VPI.

This commit is contained in:
Richard Xia 2016-10-18 14:51:59 -07:00
parent 900a7bbcf1
commit 183ae58704

View File

@ -40,7 +40,8 @@
#include <vpi_user.h> #include <vpi_user.h>
#define RSP_SERVER_PORT 5555 // Calling bind with port 0 will return a socket bound to an unused port.
#define RSP_SERVER_PORT 0
#define XFERT_MAX_SIZE 512 #define XFERT_MAX_SIZE 512
const char * cmd_to_string[] = {"CMD_RESET", const char * cmd_to_string[] = {"CMD_RESET",
@ -63,8 +64,6 @@ int init_jtag_server(int port)
struct sockaddr_in serv_addr; struct sockaddr_in serv_addr;
int flags; int flags;
printf("Listening on port %d\n", port);
listenfd = socket(AF_INET, SOCK_STREAM, 0); listenfd = socket(AF_INET, SOCK_STREAM, 0);
memset(&serv_addr, '0', sizeof(serv_addr)); memset(&serv_addr, '0', sizeof(serv_addr));
@ -76,6 +75,14 @@ int init_jtag_server(int port)
listen(listenfd, 10); listen(listenfd, 10);
socklen_t socklen = sizeof(serv_addr);
if (getsockname(listenfd, (struct sockaddr *)&serv_addr, &socklen) == -1) {
perror("init_jtag_server");
exit(1);
} else {
printf("Listening on port %d\n", ntohs(serv_addr.sin_port));
}
printf("Waiting for client connection..."); printf("Waiting for client connection...");
connfd = accept(listenfd, (struct sockaddr*)NULL, NULL); connfd = accept(listenfd, (struct sockaddr*)NULL, NULL);
printf("ok\n"); printf("ok\n");