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