ReactOS 0.4.16-dev-125-g798ea90
UNew.c
Go to the documentation of this file.
1#include "syshdrs.h"
2
3#if !defined(NO_UNIX_DOMAIN_SOCKETS)
4
5int
6MakeSockAddrUn(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
26int
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
41int
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
56int
57UNewStreamServer(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
86int
87UNewDatagramServer(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
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char * strncpy(char *DstString, const char *SrcString, ACPI_SIZE Count)
Definition: utclib.c:427
#define close
Definition: acwin.h:98
#define SOCK_STREAM
Definition: tcpip.h:118
#define errno
Definition: errno.h:18
#define memset(x, y, z)
Definition: compat.h:39
SOCKET WSAAPI socket(IN INT af, IN INT type, IN INT protocol)
Definition: socklife.c:143
int sun_family
Definition: wintirpc.h:89
char sun_path[MAX_PATH]
Definition: wintirpc.h:90
int UNewDatagramServer(const char *const, const int, const int)
#define kUBindFailed
Definition: usio.h:4
int MakeSockAddrUn(struct sockaddr_un *, const char *const)
int UNewStreamClient(void)
int UNewStreamServer(const char *const, const int, const int, int)
int UNewDatagramClient(void)
#define kUListenFailed
Definition: usio.h:5
int UBind(int, const char *const, const int, const int)
int UListen(int, int)
#define kUNewFailed
Definition: usio.h:3
#define AF_UNIX
Definition: winsock.h:345
#define SOCK_DGRAM
Definition: winsock.h:336