即使我知道数据出现在以太网端口,我也无法接收任何数据。套接字创建和绑定是成功的。但它只是永远存在于recvfrom()
中。在我的智慧结束,所以我求求你的帮助!这是我的套接字相关代码(重新输入,而不是复制/粘贴可能的错别字):
#define MTU 1500
struct sockaddr_in LocalEndPoint;
struct sockaddr_in RemoteEndPoint;
int socketHandle = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if(socketHandle == -1)
printf("Error 1");
else
printf("Socket created");
memset((char*)&LocalEndPoint, 0, sizeof(LocalEndPoint));
LocalEndPoint.sin_family = AF_INET;
LocalEndPoint.sin_port = htons(51610);
LocalEndPoint.sin_addr.s_addr = htonl(INADDR_ANY);
int bind_ret_val = bind(socketHandle, (sockaddr*)&LocalEndPoint, sizeof(LocalEndPoint)) < 0;
if(bind_ret_val < 0)
printf("Error 2");
else
printf("Bound");
char* buffer = new char[MTU];
unsigned int msg_length;
socklen_t addressSize0 = sizeof(RemoteEndPoint);
printf("Waiting for packet");
msg_length = recvfrom(socketHandle, buffer, MTU, 0, (struct sockaddr*)&RemoteEndPoint, &addressSize0);
printf("Packet received");
我连接的相机是流式传输UDP数据包。我通过在线以太网嗅探器确认相机正在发送包含以下信息的数据包,这似乎与我的以太网适配器和插槽配置完美匹配。
source MAC = 70:B3:D5:EA:E3:11
destination MAC = 00:1F:7B:B4:1F:11
source IP = 192.168.40.61
destination IP = 192.168.40.11
source port = 51610
destination port = 51610
我还在ifconfig命令中确认我的接收[Linux]机器中的eth0
适配器,适配器正在看到数据包,因为ifconfig
给出了“RX数据包”的数据包计数随着溪流逐渐增加。