skalibs

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

ipc_bind.c (484B)


      1 /* ISC license. */
      2 
      3 #include <skalibs/nonposix.h>
      4 #include <sys/socket.h>
      5 #include <sys/un.h>
      6 #include <string.h>
      7 #include <errno.h>
      8 
      9 #include <skalibs/socket.h>
     10 #include <skalibs/posixishard.h>
     11 
     12 int ipc_bind (int s, char const *p)
     13 {
     14   struct sockaddr_un sa ;
     15   size_t l = strlen(p) ;
     16   if (l > IPCPATH_MAX) return (errno = EPROTO, -1) ;
     17   memset(&sa, 0, sizeof sa) ;
     18   sa.sun_family = AF_UNIX ;
     19   memcpy(sa.sun_path, p, l+1) ;
     20   return bind(s, (struct sockaddr *)&sa, sizeof sa) ;
     21 }