c - UDP recvfrom call returns wrong port number. Why? -
I am playing with calls using 'recvfrom' and 'sendto' UDP;
The problem is that the sin_port member of struct sockaddr is always wrong due to recvfrom?
I'll post some source code but someone has already posted that question (with no replies) and I'm using almost the same code as it does besides, you can post this post. You can get more information about this problem in reading.
Thanks in advance
EDIT: I really think that number 2 can be the answer to 'number' trouble. How can I see it?
Here are two possible reasons:
-
You sin_port It is not changing the order before hosting / displaying the order of the Sin_port Network Endian comes in. It is that you can show the big endian to the port on the little Andian machine.
-
Your customer uses a random source port. Therefore when your destination port is 6000, the customer's source port is chosen randomly. Recvfrom does not give you source IP address and source port number. No destination port
If none of these are available, please provide some relevant test code, and the actual value you are looking for. It is possible that you are going to overflow some buffer overflow, or something else going wrong.
Edit, by looking at the code in your link, you encrypt the buffer size (udpPkg.udpRecvBuf) as 1024. Is buffer really less than 1024 big? If not, then you are probably overflowing with udpPkg.udpRecvBuf
.
Comments
Post a Comment