开发者

Why would recvfrom() under report the packet size?

开发者 https://www.devze.com 2023-02-17 05:52 出处:网络
I am working on a Linux server that listens for UDP messages as part of a discovery protocol.My code for listening follows:

I am working on a Linux server that listens for UDP messages as part of a discovery protocol. My code for listening follows:

           rcd = ::select(
              socket_handle + 1,
              &wait_list,
              0,            // no write
              0,            // no error
              &timeout);
           if(rcd > 0)
           {
              if(FD_ISSET(socket_handle,&wait_list))
              {
                 struct sockaddr address;
                 socklen_t address_size = sizeof(address);
                 len = ::recvfrom(
                    socket_handle,
                    rx_buff,
                    max_datagram_size,
                    0,      // no flags
                    &address,
                    &address_size);
                 if(len > 0 && address.sa_family == AF_INET)
                 {
                    struct sockaddr_in *address_in =
                       reinterpret_cast<struct sockaddr_in *>(&address);
                    event_datagram_received::cpost(
                       this,
                       rx_buff,
                       rcd,
                       ntohl(address_in->sin_addr.s_addr),
                       ntohs(address_in->sin_port));
                 }
       开发者_开发知识库       }
           }

In the meantime, I have written a windows client that transmits the UDP messages. I have verified using wireshark that the messages are being transmitted with the right format and length (five bytes). However, when I examine the return value for recvfrom(), this value is always one. The size of my receive buffer (max_datagram_size) is set to 1024. The one byte of the packet that we get appears to have the correct value. My question is: why am I not getting all of the expected bytes?

In case it matters, my Linux server is running under Debian 5 within a VirtualBox virtual machine.


nos answered my question in the first comment. I was using the wrong variable to report the buffer length.

0

精彩评论

暂无评论...
验证码 换一张
取 消