Windows changes UDP destination port specified in send_to call??!! - TCP-IP

This is a discussion on Windows changes UDP destination port specified in send_to call??!! - TCP-IP ; I have an interesting bug i'm trying to understand. I am writing a simple "UDP Socket" class that wraps the Winsock APIs. I have found that when i specify a UDP server port on Windows (say 666) the port mysteriously ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: Windows changes UDP destination port specified in send_to call??!!

  1. Windows changes UDP destination port specified in send_to call??!!

    I have an interesting bug i'm trying to understand. I am writing a simple
    "UDP Socket" class that wraps the Winsock APIs. I have found that when i
    specify a UDP server port on Windows (say 666) the port mysteriously gets
    changed to another port (in this case 39426).

    To clarify:

    1) The UDP client sends a datagram from Windows box 1 to port 666 on Windows
    box 2.
    2) MS Network Monitor shows that the UDP client app is ACTUALLY using
    destination port 39426 (the 666 has changed to 39426).
    3) The UDP Server socket is undeed receiving datagrams from port 39426 since
    the application receives the message.

    I'm assuming that Windows for some reason changes the port behind my back!

    Questions:
    a) How is the client notified of the port change on the server side?
    b) Why does Windows behave this way?

    This behavior is a big problem for me since i need to communicate between
    the Windows platform and an embedded platform using UDP datagrams. As it is
    now, the embedded RTOS (Nucleus) is using the destination port used in the
    Send_To call which results in the datagram being addressed to port 666
    (which my PC-side UDP server doesn't receive on due to the port being
    swapped behind my back).

    Thanks,
    /John.




  2. Re: Windows changes UDP destination port specified in send_to call??!!

    On Sep 8, 2:43 am, "John Gulbrandsen" wrote:
    > 1) The UDP client sends a datagram from Windows box 1 to port 666 on Windows
    > box 2.
    > 2) MS Network Monitor shows that the UDP client app is ACTUALLY using
    > destination port 39426 (the 666 has changed to 39426).
    > 3) The UDP Server socket is undeed receiving datagrams from port 39426 since
    > the application receives the message.


    It sounds like you forgot to include a "htons" call when setting the
    port number. Windows is running on a little-endian machine while the
    network is using big-endian.

    666 = 0x029A
    39426 = 0x9A02


  3. Re: Windows changes UDP destination port specified in send_to call??!!

    Ahh Bob, you're right! After including the htons call the software works as
    intended...

    Thanks a million.
    /John.

    wrote in message
    news:1189235663.819391.253370@19g2000hsx.googlegro ups.com...
    > On Sep 8, 2:43 am, "John Gulbrandsen" wrote:
    >> 1) The UDP client sends a datagram from Windows box 1 to port 666 on
    >> Windows
    >> box 2.
    >> 2) MS Network Monitor shows that the UDP client app is ACTUALLY using
    >> destination port 39426 (the 666 has changed to 39426).
    >> 3) The UDP Server socket is undeed receiving datagrams from port 39426
    >> since
    >> the application receives the message.

    >
    > It sounds like you forgot to include a "htons" call when setting the
    > port number. Windows is running on a little-endian machine while the
    > network is using big-endian.
    >
    > 666 = 0x029A
    > 39426 = 0x9A02
    >




+ Reply to Thread