diff options
author | Mikael Magnusson <mikma@users.sourceforge.net> | 2019-03-27 23:18:25 +0100 |
---|---|---|
committer | Mikael Magnusson <mikma@users.sourceforge.net> | 2021-01-12 23:34:17 +0100 |
commit | 42c826b49b3e879810b38669805e14f76c281685 (patch) | |
tree | 13b9f09ace2d68288053f919b7af0928052beae1 /sysdep/unix/io.c | |
parent | a40ddf5c616465a93287e4ac41a98d04b4fb2b37 (diff) |
Unix: Implement sk_connect_unix
Diffstat (limited to 'sysdep/unix/io.c')
-rw-r--r-- | sysdep/unix/io.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/sysdep/unix/io.c b/sysdep/unix/io.c index 9d54a2c3..3aba48d2 100644 --- a/sysdep/unix/io.c +++ b/sysdep/unix/io.c @@ -1512,6 +1512,34 @@ sk_open_unix(sock *s, char *name) return 0; } +int +sk_connect_unix(sock *s, char *name) +{ + struct sockaddr_un sa; + int fd; + + /* We are sloppy during error (leak fd and not set s->err), but we die anyway */ + + fd = socket(AF_UNIX, SOCK_STREAM, 0); + if (fd < 0) + return -1; + + if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) + return -1; + + /* Path length checked in test_old_bird() */ + sa.sun_family = AF_UNIX; + strcpy(sa.sun_path, name); + + if (connect(fd, (struct sockaddr *) &sa, SUN_LEN(&sa)) < 0) + return -1; + + s->fd = fd; + s->type = SK_UNIX; + sk_insert(s); + return 0; +} + #define CMSG_RX_SPACE MAX(CMSG4_SPACE_PKTINFO+CMSG4_SPACE_TTL, \ CMSG6_SPACE_PKTINFO+CMSG6_SPACE_TTL) |