diff options
author | Thomas Haller <thaller@redhat.com> | 2015-03-05 09:39:43 (GMT) |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2015-03-05 11:10:28 (GMT) |
commit | 2d61e890379888907a93ddd0a04187b130629f6f (patch) | |
tree | 5ff06ee6e8aa229615012961d5fe6617684da2ed /lib/nl.c | |
parent | 9614acf4c4354892b5b734cace4778acfc019999 (diff) | |
parent | f91e6959eae3a819decaa2cc20d2af9d827060f3 (diff) | |
download | libnl-2d61e890379888907a93ddd0a04187b130629f6f.zip libnl-2d61e890379888907a93ddd0a04187b130629f6f.tar.gz libnl-2d61e890379888907a93ddd0a04187b130629f6f.tar.bz2 |
lib/socket: add nl_socket_set_fd() function
This is based on the patch by sagil@infinidat.com, but heavily modified.
Add a function nl_socket_set_fd(), I renamed it from nl_connect_fd().
Now nl_connect() and nl_socket_set_fd() are implemented independently as
they share little code. But they have similar functionality:
to initialize a libnl socket and set it's file descriptor.
A user who wants libnl to setup the socket can continue to use nl_connect().
A user with special requirements should setup the socket entirely. That includes
calling socket() (with or without SOCK_CLOEXEC), bind(), setting buffer size.
For the same reason I dropped nl_create_fd(). It didn't do much more then
calling socket() -- which the user can do directly.
https://github.com/thom311/libnl/pull/68
Signed-off-by: Thomas Haller <thaller@redhat.com>
Diffstat (limited to 'lib/nl.c')
-rw-r--r-- | lib/nl.c | 9 |
1 files changed, 7 insertions, 2 deletions
@@ -86,8 +86,13 @@ * This capability is indicated by * `%NL_CAPABILITY_NL_CONNECT_RETRY_GENERATE_PORT_ON_ADDRINUSE`. * + * @note nl_connect() creates and sets the file descriptor. You can setup the file + * descriptor yourself by creating and binding it, and then calling + * nl_socket_set_fd(). The result will be the same. + * * @see nl_socket_alloc() * @see nl_close() + * @see nl_socket_set_fd() * * @return 0 on success or a negative error code. * @@ -105,8 +110,8 @@ int nl_connect(struct nl_sock *sk, int protocol) flags |= SOCK_CLOEXEC; #endif - if (sk->s_fd != -1) - return -NLE_BAD_SOCK; + if (sk->s_fd != -1) + return -NLE_BAD_SOCK; sk->s_fd = socket(AF_NETLINK, SOCK_RAW | flags, protocol); if (sk->s_fd < 0) { |