UDP source port

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • slaskbrev1@gmail.com

    UDP source port

    Hi.
    Im sending data over a SOCK_DGRAM socket, is it possible to define
    what source port my program will use?
    I guess one alternative is to craft the UDP header by myself, what
    type of socket would I use then? Do I have to craft the IP header
    aswell and use SOCK_RAW?

    Thanks
  • Antoninus Twink

    #2
    Re: UDP source port

    On 17 Apr 2008 at 9:34, slaskbrev1@gmai l.com wrote:
    Im sending data over a SOCK_DGRAM socket, is it possible to define
    what source port my program will use?
    Yes - just set the sin_port field of the struct sockaddr *address
    argument you give to bind(). (The default value of 0 for sin_port just
    means "pick any available port".)

    Comment

    • slaskbrev1@gmail.com

      #3
      Re: UDP source port

      On 17 Apr, 12:43, Antoninus Twink <nos...@nospam. invalidwrote:
      On 17 Apr 2008 at 9:34, slaskbr...@gmai l.com wrote:
      >
      Im sending data over a SOCK_DGRAM socket, is it possible to define
      what source port my program will use?
      >
      Yes - just set the sin_port field of the struct sockaddr *address
      argument you give to bind(). (The default value of 0 for sin_port just
      means "pick any available port".)
      Thanks. It bothers me I didnt figure that out myself. :)

      Comment

      • Keith Thompson

        #4
        Re: UDP source port

        slaskbrev1@gmai l.com writes:
        Im sending data over a SOCK_DGRAM socket, is it possible to define
        what source port my program will use?
        I guess one alternative is to craft the UDP header by myself, what
        type of socket would I use then? Do I have to craft the IP header
        aswell and use SOCK_RAW?
        Please ask in a newsgroup that discusses your operating system,
        perhaps comp.unix.progr ammer or one of the Windows groups.

        --
        Keith Thompson (The_Other_Keit h) <kst-u@mib.org>
        Nokia
        "We must do something. This is something. Therefore, we must do this."
        -- Antony Jay and Jonathan Lynn, "Yes Minister"

        Comment

        • ionic

          #5
          Re: UDP source port

          Call bind() right after socket(), specify your local port and NIC
          adapter in sockaddr_in.


          Comment

          Working...