Networking Forums

Networking Forums > Computer Networking > Linux Networking > How to determine the local port?

Reply
Thread Tools Display Modes

How to determine the local port?

 
 
anketm@gmail.com
Guest
Posts: n/a

 
      05-23-2005, 10:42 PM
I am writing a simple client using UDP sockets.
I am wondering if there is any way to determine what local port a
socket was bound to when bind() is not explicitly called.

This is what my program looks like:

sock = socket(PF_INET, SOCK_DGRAM, 0);
sendto(sock, message, strlen(message) + 1, 0, (struct sockaddr *)
&server, sizeof(server));

Note that bind() was not called, and the socket was arbitrarily(?)
bound to a local port by the kernel. How do I determine what port it
was bound to?

Thanks.
Anket Mathur

 
Reply With Quote
 
 
 
 
=?iso-8859-1?q?M=E5ns_Rullg=E5rd?=
Guest
Posts: n/a

 
      05-23-2005, 11:39 PM
(E-Mail Removed) writes:

> I am writing a simple client using UDP sockets.
> I am wondering if there is any way to determine what local port a
> socket was bound to when bind() is not explicitly called.
>
> This is what my program looks like:
>
> sock = socket(PF_INET, SOCK_DGRAM, 0);
> sendto(sock, message, strlen(message) + 1, 0, (struct sockaddr *)
> &server, sizeof(server));
>
> Note that bind() was not called, and the socket was arbitrarily(?)
> bound to a local port by the kernel. How do I determine what port it
> was bound to?


getsockname

--
Måns Rullgård
(E-Mail Removed)
 
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Utility to Map Remote Port to Local Port Will Windows Networking 0 12-14-2006 06:41 AM
iptables forward to local different port Ross Linux Networking 13 06-17-2006 12:32 PM
local port tunneling? hellrazor Windows Networking 2 07-15-2005 05:22 PM
How to determine which port modem is on? etc Alex Bell Linux Networking 7 06-03-2005 02:53 PM
Printing on Custom Local Port =?Utf-8?B?Q2hyaXMgTC4gV2hpdGU=?= Windows Networking 0 01-06-2004 06:21 PM



1 2 3 4 5 6 7 8 9 10 11