diff options
author | Martin Willi <martin@revosec.ch> | 2014-06-04 16:26:58 +0200 |
---|---|---|
committer | Martin Willi <martin@revosec.ch> | 2014-06-04 16:26:58 +0200 |
commit | 8c55f8ef42816a695895990cf89697a30c235355 (patch) | |
tree | c4aa8a3f0f08166b37369bb93132d0ece470af42 /src/libstrongswan/networking/streams/stream_unix.c | |
parent | b4c51061c3c649e948324d1f3ad37ef6e48f8b96 (diff) | |
parent | d930d184177ef352c4b5def4e5848463819435ec (diff) | |
download | strongswan-8c55f8ef42816a695895990cf89697a30c235355.tar.bz2 strongswan-8c55f8ef42816a695895990cf89697a30c235355.tar.xz |
Merge branch 'win'
Ports the strongSwan core libraries and some plugins to the Windows platform
using a MinGW based toolchain. Beside generic platform abstraction and
the windows.[ch] compatibility layer, this merge introduces a Windows native
threading backend and a charon-svc Windows IKE service.
Travis adds a MinGW cross-compile build to Windows, and further enables -Werror
to let builds fail for all compiler warnings with gcc and Clang.
Diffstat (limited to 'src/libstrongswan/networking/streams/stream_unix.c')
-rw-r--r-- | src/libstrongswan/networking/streams/stream_unix.c | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/src/libstrongswan/networking/streams/stream_unix.c b/src/libstrongswan/networking/streams/stream_unix.c new file mode 100644 index 000000000..13e56bc78 --- /dev/null +++ b/src/libstrongswan/networking/streams/stream_unix.c @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2013 Martin Willi + * Copyright (C) 2013 revosec AG + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +#include <library.h> +#include <errno.h> +#include <unistd.h> +#include <limits.h> + +#include "stream_unix.h" + +/** + * See header + */ +int stream_parse_uri_unix(char *uri, struct sockaddr_un *addr) +{ + if (!strpfx(uri, "unix://")) + { + return -1; + } + uri += strlen("unix://"); + + memset(addr, 0, sizeof(*addr)); + addr->sun_family = AF_UNIX; + strncpy(addr->sun_path, uri, sizeof(addr->sun_path)); + addr->sun_path[sizeof(addr->sun_path)-1] = '\0'; + + return offsetof(struct sockaddr_un, sun_path) + strlen(addr->sun_path); +} + +/** + * See header + */ +stream_t *stream_create_unix(char *uri) +{ + struct sockaddr_un addr; + int len, fd; + + len = stream_parse_uri_unix(uri, &addr); + if (len == -1) + { + DBG1(DBG_NET, "invalid stream URI: '%s'", uri); + return NULL; + } + fd = socket(AF_UNIX, SOCK_STREAM, 0); + if (fd < 0) + { + DBG1(DBG_NET, "opening socket '%s' failed: %s", uri, strerror(errno)); + return NULL; + } + if (connect(fd, (struct sockaddr*)&addr, len) < 0) + { + DBG1(DBG_NET, "connecting to '%s' failed: %s", uri, strerror(errno)); + close(fd); + return NULL; + } + return stream_create_from_fd(fd); +} |