This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: patch: when gdbserver port is 0, print port assigned by OS
- From: Daniel Jacobowitz <drow at false dot org>
- To: Mat Hostetter <mat at lcs dot mit dot edu>
- Cc: gdb-patches at sourceware dot org
- Date: Tue, 27 Feb 2007 12:22:19 -0500
- Subject: Re: patch: when gdbserver port is 0, print port assigned by OS
- References: <7uabz6jlvp.fsf@ld-1.internal.tilera.com>
On Thu, Feb 22, 2007 at 09:40:58AM -0500, Mat Hostetter wrote:
> 2007-02-22 Mat Hostetter <mat@lcs.mit.edu>
>
> * remote-utils.c (remote_open): When the user specifies a port
> number of 0, print out the actual port assigned by the OS rather
> than 0. This allows gdbserver to pick its own port number.
I didn't even realize that worked here... nice. I cleaned up
formatting and committed it. Thank you for the patch.
--
Daniel Jacobowitz
CodeSourcery
Index: ChangeLog
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/ChangeLog,v
retrieving revision 1.107
diff -u -p -r1.107 ChangeLog
--- ChangeLog 26 Feb 2007 20:10:18 -0000 1.107
+++ ChangeLog 27 Feb 2007 17:21:06 -0000
@@ -1,3 +1,7 @@
+2007-02-26 Mat Hostetter <mat@lcs.mit.edu>
+
+ * remote-utils.c (remote_open): Print out the assigned port number.
+
2007-02-26 Daniel Jacobowitz <dan@codesourcery.com>
* remote-utils.c (monitor_output): New function.
Index: remote-utils.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/remote-utils.c,v
retrieving revision 1.40
diff -u -p -r1.40 remote-utils.c
--- remote-utils.c 26 Feb 2007 20:10:18 -0000 1.40
+++ remote-utils.c 27 Feb 2007 17:21:06 -0000
@@ -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);