diff options
author | Mikael Magnusson <mikma@users.sourceforge.net> | 2019-03-27 23:18:25 +0100 |
---|---|---|
committer | Mikael Magnusson <mikma@users.sourceforge.net> | 2019-04-02 00:27:38 +0200 |
commit | 5ac8017fb8c79fd044cb28d72f03fcdeb033f715 (patch) | |
tree | d46f9e95f377308ba77197aa3704f5a5bb37b1c5 /sysdep | |
parent | 7c36eb3e8bd7d06f65dc7319d42b6abe782c5b89 (diff) |
unix: Implement sk_connect_unix
Diffstat (limited to 'sysdep')
-rw-r--r-- | sysdep/unix/io.c | 28 | ||||
-rw-r--r-- | sysdep/unix/unix.h | 1 |
2 files changed, 29 insertions, 0 deletions
diff --git a/sysdep/unix/io.c b/sysdep/unix/io.c index d1d86e3b..10b985d7 100644 --- a/sysdep/unix/io.c +++ b/sysdep/unix/io.c @@ -1509,6 +1509,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) diff --git a/sysdep/unix/unix.h b/sysdep/unix/unix.h index 0e1e98c0..c65d6c77 100644 --- a/sysdep/unix/unix.h +++ b/sysdep/unix/unix.h @@ -103,6 +103,7 @@ void io_init(void); void io_loop(void); void io_log_dump(void); int sk_open_unix(struct birdsock *s, char *name); +int sk_connect_unix(struct birdsock *s, char *name); struct rfile *rf_open(struct pool *, char *name, char *mode); void *rf_file(struct rfile *f); int rf_fileno(struct rfile *f); |