How to determine the local port?

Discussion in 'C Programming' started by anketm@gmail.com, May 23, 2005.

  1. Guest

    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
     
    , May 23, 2005
    #1
    1. Advertising

  2. writes:
    > I am writing a simple client using UDP sockets.


    Standard C doesn't support UDP sockets, or any kind of networking.

    Try a newsgroup specific your system, (possibly comp.unix.programmer).

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
     
    Keith Thompson, May 23, 2005
    #2
    1. Advertising

  3. CBFalconer Guest

    wrote:
    >
    > 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?


    This is all off topic here. See the references in my sig below,
    especially the first two.

    --
    Some useful references about C:
    <http://www.ungerhu.com/jxh/clc.welcome.txt>
    <http://benpfaff.org/writings/clc/off-topic.html>
    <http://www.eskimo.com/~scs/C-faq/top.html>
    <http://anubis.dkuug.dk/jtc1/sc22/wg14/www/docs/n869/> (C99)
    <http://www.dinkumware.com/refxc.html> (C-library}
    <http://gcc.gnu.org/onlinedocs/> (GNU docs)
     
    CBFalconer, May 24, 2005
    #3
  4. Eric Sosman Guest

    wrote:

    > 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.


    The local Port is Taylor's Ten-Year-Old Tawny. The
    well-known Ports include Graham's 1977 and Taylor's 1983.
    The reserved Port is the Fonseca 1963, the limited (alas!)
    supply of Taylor 1948 having been exhausted.

    --
    Eric Sosman
    lid
     
    Eric Sosman, May 24, 2005
    #4
  5. CBFalconer Guest

    Eric Sosman wrote:
    >
    > wrote:
    >
    > > 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.

    >
    > The local Port is Taylor's Ten-Year-Old Tawny. The
    > well-known Ports include Graham's 1977 and Taylor's 1983.
    > The reserved Port is the Fonseca 1963, the limited (alas!)
    > supply of Taylor 1948 having been exhausted.


    So have some Madiera, m'dear :)

    --
    Some useful references about C:
    <http://www.ungerhu.com/jxh/clc.welcome.txt>
    <http://www.eskimo.com/~scs/C-faq/top.html>
    <http://benpfaff.org/writings/clc/off-topic.html>
    <http://anubis.dkuug.dk/jtc1/sc22/wg14/www/docs/n869/> (C99)
    <http://www.dinkumware.com/refxc.html> (C-library}
    <http://gcc.gnu.org/onlinedocs/> (GNU docs)
     
    CBFalconer, May 24, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sven Heithecker
    Replies:
    2
    Views:
    646
    Ralf Hildebrandt
    Aug 2, 2004
  2. =?Utf-8?B?WVNVVA==?=

    Access local port or Running local exe file

    =?Utf-8?B?WVNVVA==?=, Jan 14, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    519
    =?Utf-8?B?WVNVVA==?=
    Jan 14, 2006
  3. Replies:
    1
    Views:
    575
    Roedy Green
    Oct 19, 2005
  4. Peña, Botp
    Replies:
    1
    Views:
    242
    Robert Klemme
    Jan 24, 2004
  5. Replies:
    1
    Views:
    579
    Toni Erdmann
    Mar 2, 2005
Loading...

Share This Page