title: How to check if UDP packet received in C Linux
body: <p>"recvfrom()" in below sample code waits until UDP packet is received.  </p>
  
  <p>But I need to check whether UDP packet is available or not.
  If packet is not received, then continue other tasks.
  If packet is received, then receive packet and parsing.
  How can I do this in Linux c program?  Please help!</p>
  
  <pre><code>for (;;) 
  {
      printf("waiting on port %d\n", SERVICE_PORT);
      recvlen = recvfrom(fd, buf, BUFSIZE, 0, (struct sockaddr *)&amp;remaddr, &amp;addrlen);
      printf("received %d bytes\n", recvlen);
      if (recvlen &gt; 0) {
          buf[recvlen] = 0;
          printf("received message: \"%s\"\n", buf);
      }
  }
  </code></pre>