title: How to simply send UDP data in C?
body: <p>I am struggling with UDP sockets. I would like to benchmark the time to exchange some type of data between two machines. </p>
  
  <p>I quickly wrote this project <a href="https://github.com/nowox/udp-test" rel="nofollow noreferrer">https://github.com/nowox/udp-test</a> in C where I have a simple client:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;stdint.h&gt;
  #include &lt;string.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;sys/socket.h&gt;
  #include &lt;netinet/in.h&gt;
  #include &lt;fcntl.h&gt;
  #include &lt;netdb.h&gt;
  #include &lt;sys/time.h&gt;
  #include &lt;arpa/inet.h&gt;
  #include &lt;time.h&gt;
  #include &lt;errno.h&gt;
  
  #define PORT (3000)
  
  #define SUBIMAGES (1000)
  #define FRAMES_PER_SUBIMAGES (23)
  #define UDP_FRAME (1442)
  
  #define SERVERADDRESS "127.0.0.1" // 138.131.156.36"
  
  #define BUFFER_SIZE (SUBIMAGES * FRAMES_PER_SUBIMAGES * UDP_FRAME)
  
  
  char buffer[BUFFER_SIZE];
  
  /**
   * Populate the buffer with random data.
   */
  void build(uint8_t* buffer, size_t length)
  {
      for (size_t i = 0; i &lt; length; i++)
      {
          buffer[i] = (rand() % 255) + 1;
      }
  }
  
  int main(int argc, char **argv)
  {
      struct timespec start, end;
      int sockfd;
      struct sockaddr_in server;
  
      printf("Build Data...\n");
      build(buffer, sizeof(buffer));
  
      printf("Configure socket...\n");
      sockfd = socket(AF_INET, SOCK_DGRAM, 0);
      if (sockfd &lt; 0)
      {
          fprintf(stderr, "Error opening socket");
          return EXIT_FAILURE;
      }
  
      bzero((char*)&amp;server, sizeof(server));
      server.sin_family = AF_INET;
      server.sin_addr.s_addr = inet_addr(SERVERADDRESS);
      server.sin_port = htons(PORT);
  
      printf("Send UDP data...\n");
      clock_gettime(CLOCK_MONOTONIC_RAW, &amp;start);
      for (size_t i = 0; i &lt; BUFFER_SIZE; i += UDP_FRAME)
      {
          if (sendto(sockfd, &amp;buffer[i], UDP_FRAME, 0,
                     (const struct sockaddr*)&amp;server, sizeof(server)) &lt; 0)
          {
              fprintf(stderr, "Error in sendto()\n");
              return EXIT_FAILURE;
          }
      }
      clock_gettime(CLOCK_MONOTONIC_RAW, &amp;end);
      uint64_t delta_us = (end.tv_sec - start.tv_sec) * 1000000 +
                          (end.tv_nsec - start.tv_nsec) / 1000;
  
      printf("Time to send %d subimages: %f[s]\n", SUBIMAGES, delta_us / 1e6f);
      printf("Finished...\n");
  
      return EXIT_SUCCESS;
  }
  </code></pre>
  
  <p>I am expecting to see the UDP dataframe into Wireshark, but it seems I see nothing. </p>
  
  <p>Initial question: Why is my socket not sending anything? </p>
  
  <p>I figured out it was because of WSL (Windows Subsystem for Linux). So I moved to Ubuntu</p>
  
  <p>Second question: Why is my server not receiving anything?</p>