summaryrefslogtreecommitdiff
path: root/source4/lib/socket
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2005-05-01 18:49:43 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:16:25 -0500
commitb2584a403c6382ef478755979d955043fc9569a1 (patch)
tree5ef82f852c106c27c122f1c3beca2f2c73b09374 /source4/lib/socket
parent7282ddda0a38139fa457e6451f100f6d1792d927 (diff)
downloadsamba-b2584a403c6382ef478755979d955043fc9569a1.tar.gz
samba-b2584a403c6382ef478755979d955043fc9569a1.tar.bz2
samba-b2584a403c6382ef478755979d955043fc9569a1.zip
r6562: added support for datagram unix domain sockets in the socket library
(This used to be commit 23b2046dcb5c4593cba6964f400a2e5246fb35f7)
Diffstat (limited to 'source4/lib/socket')
-rw-r--r--source4/lib/socket/socket.c3
-rw-r--r--source4/lib/socket/socket_unix.c32
2 files changed, 26 insertions, 9 deletions
diff --git a/source4/lib/socket/socket.c b/source4/lib/socket/socket.c
index ddc2097f42..86e2f05962 100644
--- a/source4/lib/socket/socket.c
+++ b/source4/lib/socket/socket.c
@@ -159,7 +159,8 @@ NTSTATUS socket_recv(struct socket_context *sock, void *buf,
size_t wantlen, size_t *nread, uint32_t flags)
{
if (sock->state != SOCKET_STATE_CLIENT_CONNECTED &&
- sock->state != SOCKET_STATE_SERVER_CONNECTED) {
+ sock->state != SOCKET_STATE_SERVER_CONNECTED &&
+ sock->type != SOCKET_TYPE_DGRAM) {
return NT_STATUS_INVALID_PARAMETER;
}
diff --git a/source4/lib/socket/socket_unix.c b/source4/lib/socket/socket_unix.c
index 614229aaac..3f265f7214 100644
--- a/source4/lib/socket/socket_unix.c
+++ b/source4/lib/socket/socket_unix.c
@@ -38,9 +38,22 @@ static NTSTATUS unixdom_error(int ernum)
static NTSTATUS unixdom_init(struct socket_context *sock)
{
- sock->fd = socket(PF_UNIX, SOCK_STREAM, 0);
+ int type;
+
+ switch (sock->type) {
+ case SOCKET_TYPE_STREAM:
+ type = SOCK_STREAM;
+ break;
+ case SOCKET_TYPE_DGRAM:
+ type = SOCK_DGRAM;
+ break;
+ default:
+ return NT_STATUS_INVALID_PARAMETER;
+ }
+
+ sock->fd = socket(PF_UNIX, type, 0);
if (sock->fd == -1) {
- return NT_STATUS_INSUFFICIENT_RESOURCES;
+ return map_nt_error_from_unix(errno);
}
sock->private_data = NULL;
@@ -126,9 +139,11 @@ static NTSTATUS unixdom_listen(struct socket_context *sock,
return unixdom_error(errno);
}
- ret = listen(sock->fd, queue_size);
- if (ret == -1) {
- return unixdom_error(errno);
+ if (sock->type == SOCKET_TYPE_STREAM) {
+ ret = listen(sock->fd, queue_size);
+ if (ret == -1) {
+ return unixdom_error(errno);
+ }
}
if (!(flags & SOCKET_FLAG_BLOCK)) {
@@ -151,6 +166,10 @@ static NTSTATUS unixdom_accept(struct socket_context *sock,
socklen_t cli_addr_len = sizeof(cli_addr);
int new_fd;
+ if (sock->type != SOCKET_TYPE_STREAM) {
+ return NT_STATUS_INVALID_PARAMETER;
+ }
+
new_fd = accept(sock->fd, (struct sockaddr *)&cli_addr, &cli_addr_len);
if (new_fd == -1) {
return unixdom_error(errno);
@@ -290,8 +309,5 @@ static const struct socket_ops unixdom_ops = {
const struct socket_ops *socket_unixdom_ops(enum socket_type type)
{
- if (type != SOCKET_TYPE_STREAM) {
- return NULL;
- }
return &unixdom_ops;
}