From 6f8486daac90adbf742dde9b81775651b5b6e624 Mon Sep 17 00:00:00 2001 From: Daniel Jacobowitz Date: Tue, 27 Feb 2007 17:21:35 +0000 Subject: [PATCH] from Mat Hostetter * remote-utils.c (remote_open): Print out the assigned port number. --- gdb/gdbserver/ChangeLog | 4 ++++ gdb/gdbserver/remote-utils.c | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog index b2dd45c12aa..19003715e25 100644 --- a/gdb/gdbserver/ChangeLog +++ b/gdb/gdbserver/ChangeLog @@ -1,3 +1,7 @@ +2007-02-26 Mat Hostetter + + * remote-utils.c (remote_open): Print out the assigned port number. + 2007-02-26 Daniel Jacobowitz * remote-utils.c (monitor_output): New function. diff --git a/gdb/gdbserver/remote-utils.c b/gdb/gdbserver/remote-utils.c index 6a9a176c07e..b9a0733067b 100644 --- a/gdb/gdbserver/remote-utils.c +++ b/gdb/gdbserver/remote-utils.c @@ -209,6 +209,17 @@ remote_open (char *name) || listen (tmp_desc, 1)) perror_with_name ("Can't bind address"); + /* If port is zero, a random port will be selected, and the + fprintf below needs to know what port was selected. */ + if (port == 0) + { + socklen_t len = sizeof (sockaddr); + if (getsockname (tmp_desc, (struct sockaddr *) &sockaddr, &len) < 0 + || len < sizeof (sockaddr)) + perror_with_name ("Can't determine port"); + port = ntohs (sockaddr.sin_port); + } + fprintf (stderr, "Listening on port %d\n", port); fflush (stderr); -- 2.30.2