Mombu the Microsoft Forum

Go Back   Mombu the Microsoft Forum > Microsoft > Windows changes UDP destination port specified in send_to call??!!
User Name
Password
REGISTER NOW! Mark Forums Read




Reply
1 30th June 17:08
john gulbrandsen
External User
 
Posts: 1
Default 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.
  Reply With Quote


 


2 30th June 17:08
External User
 
Posts: 1
Default Windows changes UDP destination port specified in send_to call??!!



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 With Quote
3 30th June 17:08
john gulbrandsen
External User
 
Posts: 1
Default 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.
  Reply With Quote
Reply


Thread Tools
Display Modes




666