title: Not all udp sent packets on localhost are displayed on wireshark
body: <p>I'm writing a simple udp traffic generator using C++ and PracticalSocket as socket wrapper (<a href="http://cs.ecs.baylor.edu/~donahoo/practical/CSockets/practical/" rel="nofollow noreferrer">http://cs.ecs.baylor.edu/~donahoo/practical/CSockets/practical/</a>) and I'm using Wireshark to check the output.
  The issue is that all packets are sent without errors, but I didn't received all packets on wireshark.
  Example: I sent 10000 packets without errors, but Wireshark displays 9876 packets only.
  This is the SENDER code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "PracticalSocket.h"
  #include &lt;thread&gt;
  using namespace std;
  const int PAYLOAD_SIZE = 1464;
  
  int main(int argc, char *argv[])
  {
      char txBuffer[PAYLOAD_SIZE];
      string destAddress = argv[1];
      unsigned short destPort =  atoi(argv[2]);
      unsigned long numOfPackets =  atoi(argv[3]);
      UDPSocket tx_sock;
      unsigned long int i;
      printf("START\n");
      int ret;
      unsigned long int errors=0;
      for(i=0;i&lt;numOfPackets;i++)
      {
          ret=tx_sock.sendTo(txBuffer, PAYLOAD_SIZE, destAddress, destPort);
          if(ret&lt;=0) {
              errors++;
              printf("ERROR\n");
          }
  
      }
      printf("END - packets(%d) errors(%d)\n",i,errors);
      return i;
  }
  </code></pre>
  
  <p>The input and output in the terminal is:</p>
  
  <p>udpGen 127.0.0.1 1234 10000</p>
  
  <p>START</p>
  
  <p>END - packets(10000) errors(0)</p>
  
  <p>Then I wrote a receiver utility to check if the issue is WS.</p>
  
  <pre><code>#include "PracticalSocket.h"
  
  using namespace std;
  const int BUFFERSIZE = 1500;
  
  int main(int argc, char *argv[])
  {
  
      unsigned short rxLocalPort = atoi(argv[1]);
      unsigned long int maxCounter = atoi(argv[2]);;
      UDPSocket rx_sock(rxLocalPort);
      char echoBuffer[BUFFERSIZE];         // Buffer for echo string
      int recvMsgSize;                  // Size of received message
      string sourceAddress;             // Address of datagram source
      unsigned short sourcePort;        // Port of datagram source
      unsigned long int counter = 0;
      printf("rx from port %d\n",rxLocalPort);
      bool go=true;
      while(go)
      {
          recvMsgSize = rx_sock.recvFrom(echoBuffer, BUFFERSIZE, sourceAddress, sourcePort);
          counter++;
          if(counter&gt;=maxCounter){
              go=false;
          }
      }
      printf("received %d packets\n",counter);
      return 0;
  }
  </code></pre>
  
  <p>From the command line I passed 1234 as destPort and 10000 as numOfPackets.
  The application didn't exit from the while loop and so didn't print nothing. It returns only if I pass a greater value of packets to the sender application (i.e 11000).</p>
  
  <p>Then I tried also to increase the tx and rx buffers on both sides, but with no effects. To do that, I added a member function to the UDPSocket class:</p>
  
  <pre><code>void UDPSocket::setbufferSize(int sndbuf, int rcvbuf) {
      int s = sndbuf;
      int r = rcvbuf;
      setsockopt(sockDesc, SOL_SOCKET, SO_SNDBUF, (raw_type *)&amp;s, sizeof(s));
      setsockopt(sockDesc, SOL_SOCKET, SO_RCVBUF, (raw_type *)&amp;r, sizeof(r));
  }
  </code></pre>