1 #include "syshdrs.h"
2
3 #if !defined(NO_UNIX_DOMAIN_SOCKETS)
4
5 int
MakeSockAddrUn(struct sockaddr_un * uaddr,const char * const sockfile)6 MakeSockAddrUn(struct sockaddr_un *uaddr, const char *const sockfile)
7 {
8 int ualen;
9
10 memset(uaddr, 0, sizeof(struct sockaddr_un));
11 uaddr->sun_family = AF_UNIX;
12 strncpy(uaddr->sun_path, sockfile, sizeof(uaddr->sun_path) - 1);
13 #ifdef HAVE_SOCKADDR_UN_SUN_LEN
14 /* 4.3bsd-reno */
15 ualen = sizeof(uaddr->sun_len) + sizeof(uaddr->sun_family) + strlen(uaddr->sun_path) + 1;
16 uaddr->sun_len = ualen;
17 #else
18 ualen = sizeof(uaddr->sun_family) + strlen(uaddr->sun_path) + 1;
19 #endif
20 return (ualen);
21 } /* MakeSockAddrUn */
22
23
24
25
26 int
UNewStreamClient(void)27 UNewStreamClient(void)
28 {
29 int sfd;
30
31 sfd = socket(AF_UNIX, SOCK_STREAM, 0);
32 if (sfd < 0)
33 return kUNewFailed;
34
35 return (sfd);
36 } /* UNewStreamClient */
37
38
39
40
41 int
UNewDatagramClient(void)42 UNewDatagramClient(void)
43 {
44 int sfd;
45
46 sfd = socket(AF_UNIX, SOCK_DGRAM, 0);
47 if (sfd < 0)
48 return kUNewFailed;
49
50 return (sfd);
51 } /* UNewDatagramClient */
52
53
54
55
56 int
UNewStreamServer(const char * const astr,const int nTries,const int reuseFlag,int listenQueueSize)57 UNewStreamServer(const char *const astr, const int nTries, const int reuseFlag, int listenQueueSize)
58 {
59 int oerrno;
60 int sfd;
61
62 sfd = socket(AF_UNIX, SOCK_STREAM, 0);
63 if (sfd < 0)
64 return kUNewFailed;
65
66 if (UBind(sfd, astr, nTries, reuseFlag) < 0) {
67 oerrno = errno;
68 (void) close(sfd);
69 errno = oerrno;
70 return kUBindFailed;
71 }
72
73 if (UListen(sfd, listenQueueSize) < 0) {
74 oerrno = errno;
75 (void) close(sfd);
76 errno = oerrno;
77 return kUListenFailed;
78 }
79
80 return (sfd);
81 } /* UNewStreamServer */
82
83
84
85
86 int
UNewDatagramServer(const char * const astr,const int nTries,const int reuseFlag)87 UNewDatagramServer(const char *const astr, const int nTries, const int reuseFlag)
88 {
89 int oerrno;
90 int sfd;
91
92 sfd = socket(AF_UNIX, SOCK_DGRAM, 0);
93 if (sfd < 0)
94 return kUNewFailed;
95
96 if (UBind(sfd, astr, nTries, reuseFlag) < 0) {
97 oerrno = errno;
98 (void) close(sfd);
99 errno = oerrno;
100 return kUBindFailed;
101 }
102
103 return (sfd);
104 } /* UNewDatagramServer */
105
106 #endif
107