From 6cf39df87b6904b9aa35678fc00cf48d18a5c5af Mon Sep 17 00:00:00 2001 From: "Anselm R. Garbe" Date: Sat, 21 Jan 2006 19:37:01 +0200 Subject: [PATCH] now we use the P9-alike address syntax, ie 'unix!/tmp/bar' for a unix socket file --- libixp2/socket.c | 44 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/libixp2/socket.c b/libixp2/socket.c index a0e1611f..0a54ded9 100644 --- a/libixp2/socket.c +++ b/libixp2/socket.c @@ -16,8 +16,8 @@ #include "cext.h" #include "ixp.h" -int -ixp_connect_sock(char *sockfile) +static int +connect_unix_sock(char *sockfile) { int fd = 0; struct sockaddr_un addr = { 0 }; @@ -37,6 +37,23 @@ ixp_connect_sock(char *sockfile) return fd; } +int +ixp_connect_sock(char *sockfile) +{ + char *p = strchr(sockfile, '!'); + char *file, *type; + + if(!p) + return -1; + *p = 0; + file = &p[1]; + type = sockfile; /* unix, tcp */ + + if(strncmp(type, "unix", 5)) + return connect_unix_sock(file); + return -1; +} + int ixp_accept_sock(int fd) { @@ -47,8 +64,8 @@ ixp_accept_sock(int fd) return accept(fd, (struct sockaddr *) &addr, &su_len); } -int -ixp_create_sock(char *sockfile, char **errstr) +static int +create_unix_sock(char *sockfile, char **errstr) { int fd; int yes = 1; @@ -84,3 +101,22 @@ ixp_create_sock(char *sockfile, char **errstr) } return fd; } + +int +ixp_create_sock(char *sockfile, char **errstr) +{ + char *p = strchr(sockfile, '!'); + char *file, *type; + + if(!p) { + *errstr = "no socket type defined"; + return -1; + } + *p = 0; + file = &p[1]; + type = sockfile; /* unix, tcp */ + + if(!strncmp(type, "unix", 5)) + return create_unix_sock(file, errstr); + return -1; +}