How to determine the local port?
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > How to determine the local port?




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    How to determine the local port?  
anketm@gmail.com


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-23-05 10:59 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






[ Post a follow-up to this message ]



    Re: How to determine the local port?  
Måns Rullgård


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-24-05 01:49 AM

anketm@gmail.com 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
mru@inprovide.com





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 06:35 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register