In my application, there're two physical computers, both in Windows environment. Computer 2 (with IP "192.168.2.2") has a VMware Linux virtual machine (with IP "192.168.80.129") installed on it. What I want to do is to send UDP socket from the virtual machine to computer 1 (with IP "192.168.2.1").
As required by my application, when the udp sent through virtual machine to computer 2, the ports should be specified.
Now my situation is that, when I create and configure udp sockets in Linux, I specify two ports LOCAL_PORT(9000) and REMOTE_PORT(9001).
When I open WireShark to monitor, in the Linux VM, the source port is LOCAL_PORT(9001), however, the destination port is "iua(9900)". Source IP is "192.168.80.129" and destination IP is "192.168.2.1", which is correct.
When I open Wireshark in Windows on either computer 1 or computer 2, Source IP shown is "192.168.2.2", while destination IP is "192.168.2.1". This seems understandable, because the sender is a virtual machine, thus Udp is actually sent by the host computer(computer 2). The destination port is correct as 9001, however, the source port seems to be arbitrary.
Does anyone know what I can do in the VM so that the source port can be the number (9900) as assigned instead of an arbitrary number? Thanks!
int sock1;
struct sockaddr_in slAddr, myAddr;
memset(&slAddr, 0, sizeof(slAddr));
memset(&myAddr, 0, sizeof(myAddr));
slAddr.sin_family = AF_INET;
slAddr.sin_port = htons(RM_PORT);//RM_PORT=9900
slAddr.sin_addr.s_addr = inet_addr(SL_IP);//SL_IP="192.168.2.1"
myAddr.sin_family = AF_INET;
myAddr.sin_port = htons(LC_PORT);//LC_PORT=9901
myAddr.sin_addr.s_addr = inet_addr(MY_IP);//MY_IP="192.168.80.129"
sock1 = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
bind(sock1, (struct sockaddr *)&myAddr, sizeof(myAddr));
sendto(sock1, packeddata, 8, 0, (struct sockaddr*)&slAddr, sizeof(slAddr));