skalibs

Mirror/fork of https://skarnet.org/software/skalibs/
git clone https://ccx.te2000.cz/git/skalibs
Log | Files | Refs | README | LICENSE

socket_connected.c (389B)


      1 /* ISC license. */
      2 
      3 #include <skalibs/nonposix.h>
      4 
      5 #include <sys/socket.h>
      6 #include <netinet/in.h>
      7 
      8 #include <skalibs/allreadwrite.h>
      9 #include <skalibs/socket.h>
     10 
     11 int socket_connected (int s)
     12 {
     13   struct sockaddr_in sa ;
     14   socklen_t dummy = sizeof sa ;
     15   if (getpeername(s, (struct sockaddr *)&sa, &dummy) == -1)
     16   {
     17     char ch ;
     18     fd_read(s, &ch, 1) ;
     19     return 0 ;
     20   }
     21   return 1 ;
     22 }