ipc_local.c (593B)
1 /* ISC license. */ 2 3 #include <skalibs/nonposix.h> 4 #include <sys/socket.h> 5 #include <sys/un.h> 6 #include <string.h> 7 8 #include <skalibs/bytestr.h> 9 #include <skalibs/socket.h> 10 11 int ipc_local (int s, char *p, size_t l, int *trunc) 12 { 13 struct sockaddr_un sa ; 14 socklen_t dummy = sizeof sa ; 15 memset(&sa, 0, sizeof sa) ; 16 if (getsockname(s, (struct sockaddr *)&sa, &dummy) == -1) return -1 ; 17 dummy = byte_chr(sa.sun_path, dummy, 0) ; 18 *trunc = 1 ; 19 if (!l) return 0 ; 20 if (l < (dummy + 1)) dummy = l - 1 ; 21 else *trunc = 0 ; 22 memcpy(p, sa.sun_path, dummy) ; 23 p[dummy] = 0 ; 24 return 0 ; 25 }