Skip to content

Commit

Permalink
gdb-server: Bind to 127.0.0.1
Browse files Browse the repository at this point in the history
Binding to both 127.0.0.1 and ::1 using IPV6_ONLY does not work.
IPV6_ONLY does only work with in6addr_any. Some Linux distros (looking
at you Ubuntu) only define localhost as an alias for 127.0.0.1 (not for
::1) in /etc/hosts thereby causing gdb connection attempts to fail. By
binding only to 127.0.0.1 this problem is solved. Besides, IPv6 does not
work in docker (see #5).
  • Loading branch information
nmeum committed Feb 23, 2021
1 parent 149bc0d commit 071c1ea
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions vp/src/core/common/gdb-mc/gdb_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,25 +63,21 @@ void GDBServer::set_run_event(debug_target_if *hart, sc_core::sc_event *event) {
}

void GDBServer::create_sock(uint16_t port) {
struct sockaddr_in6 addr;
int reuse, ip6only;
struct sockaddr_in addr;
int reuse;

sockfd = socket(AF_INET6, SOCK_STREAM, 0);
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd == -1)
throw std::system_error(errno, std::generic_category());

ip6only = 0;
if (setsockopt(sockfd, IPPROTO_IPV6, IPV6_V6ONLY, &ip6only, sizeof(ip6only)) == -1)
goto err;

reuse = 1;
if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEPORT, &reuse, sizeof(reuse)) == -1)
goto err;

memset(&addr, 0, sizeof(addr));
addr.sin6_family = AF_INET6;
addr.sin6_addr = in6addr_loopback;
addr.sin6_port = htons(port);
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
addr.sin_port = htons(port);

if (bind(sockfd, (struct sockaddr *)&addr, sizeof(addr)) == -1)
goto err;
Expand Down

0 comments on commit 071c1ea

Please sign in to comment.