diff options
author | Guillaume Nault <g.nault@alphalink.fr> | 2015-10-02 22:12:33 +0200 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2015-10-04 21:15:53 +0200 |
commit | 1891e0e2cefced50e7bfdacd50942cefe5bf73ba (patch) | |
tree | abf710804b97f442659ca628050027e37c00869f /src | |
parent | b180a6ee27674b5060cf54a0149a9109da9d9fd1 (diff) | |
download | libmnl-1891e0e2cefced50e7bfdacd50942cefe5bf73ba.tar.gz libmnl-1891e0e2cefced50e7bfdacd50942cefe5bf73ba.zip |
socket: introduce mnl_socket_open2()
Define mnl_socket_open2() so that user can pass a set of SOCK_* flags
at socket creation time.
Signed-off-by: Guillaume Nault <g.nault@alphalink.fr>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/libmnl.map | 1 | ||||
-rw-r--r-- | src/socket.c | 41 |
2 files changed, 33 insertions, 9 deletions
diff --git a/src/libmnl.map b/src/libmnl.map index 3c147a7..e5920e5 100644 --- a/src/libmnl.map +++ b/src/libmnl.map @@ -74,5 +74,6 @@ LIBMNL_1.1 { } LIBMNL_1.0; LIBMNL_1.2 { + mnl_socket_open2; mnl_socket_fdopen; } LIBMNL_1.1; diff --git a/src/socket.c b/src/socket.c index 86657d4..d63ab87 100644 --- a/src/socket.c +++ b/src/socket.c @@ -103,14 +103,7 @@ unsigned int mnl_socket_get_portid(const struct mnl_socket *nl) } EXPORT_SYMBOL(mnl_socket_get_portid); -/** - * mnl_socket_open - open a netlink socket - * \param bus the netlink socket bus ID (see NETLINK_* constants) - * - * On error, it returns NULL and errno is appropriately set. Otherwise, it - * returns a valid pointer to the mnl_socket structure. - */ -struct mnl_socket *mnl_socket_open(int bus) +static struct mnl_socket *__mnl_socket_open(int bus, int flags) { struct mnl_socket *nl; @@ -118,7 +111,7 @@ struct mnl_socket *mnl_socket_open(int bus) if (nl == NULL) return NULL; - nl->fd = socket(AF_NETLINK, SOCK_RAW, bus); + nl->fd = socket(AF_NETLINK, SOCK_RAW | flags, bus); if (nl->fd == -1) { free(nl); return NULL; @@ -126,9 +119,39 @@ struct mnl_socket *mnl_socket_open(int bus) return nl; } + +/** + * mnl_socket_open - open a netlink socket + * \param bus the netlink socket bus ID (see NETLINK_* constants) + * + * On error, it returns NULL and errno is appropriately set. Otherwise, it + * returns a valid pointer to the mnl_socket structure. + */ +struct mnl_socket *mnl_socket_open(int bus) +{ + return __mnl_socket_open(bus, 0); +} EXPORT_SYMBOL(mnl_socket_open); /** + * mnl_socket_open2 - open a netlink socket with appropriate flags + * \param bus the netlink socket bus ID (see NETLINK_* constants) + * \param flags the netlink socket flags (see SOCK_* constants in socket(2)) + * + * This is similar to mnl_socket_open(), but allows to set flags like + * SOCK_CLOEXEC at socket creation time (useful for multi-threaded programs + * performing exec calls). + * + * On error, it returns NULL and errno is appropriately set. Otherwise, it + * returns a valid pointer to the mnl_socket structure. + */ +struct mnl_socket *mnl_socket_open2(int bus, int flags) +{ + return __mnl_socket_open(bus, flags); +} +EXPORT_SYMBOL(mnl_socket_open2); + +/** * mnl_socket_fdopen - associates a mnl_socket object with pre-existing socket. * \param fd pre-existing socket descriptor. * |