Lines Matching +full:multi +full:- +full:socket
2 * (C) 2008-2010 by Pablo Neira Ayuso <pablo@netfilter.org>
11 #include <sys/socket.h>
22 * libmnl is a minimalistic user-space library oriented to Netlink developers.
26 * re-inventing the wheel in common Netlink tasks.
29 "Simplify, simplify" -- Henry David Thoureau. Walden (1854)
38 * - Small: the shared library requires around 30KB for an x86-based computer.
39 * - Simple: this library avoids complex abstractions that tend to hide Netlink
40 * details. It avoids elaborated object-oriented infrastructure and complex
41 * callback-based workflow.
42 * - Easy to use: the library simplifies the work for Netlink-wise developers.
43 * It provides functions to make socket handling, message building,
45 * - Easy to re-use: you can use this library to build your own abstraction
48 * - Decoupling: the interdependency of the main bricks that compose this
62 * http://git.netfilter.org/cgi-bin/gitweb.cgi?p=libmnl.git;a=summary
75 * \defgroup socket Netlink socket helpers
80 * mnl_socket_get_fd - obtain file descriptor from netlink socket
81 * \param nl netlink socket obtained via mnl_socket_open()
83 * This function returns the file descriptor of a given netlink socket.
87 return nl->fd; in mnl_socket_get_fd()
91 * mnl_socket_get_portid - obtain Netlink PortID from netlink socket
92 * \param nl netlink socket obtained via mnl_socket_open()
94 * This function returns the Netlink PortID of a given netlink socket.
97 * socket that is binded to the same Netlink subsystem from the same process.
101 return nl->addr.nl_pid; in mnl_socket_get_portid()
112 nl->fd = socket(AF_NETLINK, SOCK_RAW | flags, bus); in __mnl_socket_open()
113 if (nl->fd == -1) { in __mnl_socket_open()
122 * mnl_socket_open - open a netlink socket
123 * \param bus the netlink socket bus ID (see NETLINK_* constants)
134 * mnl_socket_open2 - open a netlink socket with appropriate flags
135 * \param bus the netlink socket bus ID (see NETLINK_* constants)
136 * \param flags the netlink socket flags (see SOCK_* constants in socket(2))
139 * SOCK_CLOEXEC at socket creation time (useful for multi-threaded programs
151 * mnl_socket_fdopen - associates a mnl_socket object with pre-existing socket.
152 * \param fd pre-existing socket descriptor.
156 * if the socket fd is already bound and it is AF_NETLINK.
159 * non-netlink socket.
169 if (ret == -1) in mnl_socket_fdopen()
176 nl->fd = fd; in mnl_socket_fdopen()
178 nl->addr = addr; in mnl_socket_fdopen()
184 * mnl_socket_bind - bind netlink socket
185 * \param nl netlink socket obtained via mnl_socket_open()
189 * On error, this function returns -1 and errno is appropriately set. On
199 nl->addr.nl_family = AF_NETLINK; in mnl_socket_bind()
200 nl->addr.nl_groups = groups; in mnl_socket_bind()
201 nl->addr.nl_pid = pid; in mnl_socket_bind()
203 ret = bind(nl->fd, (struct sockaddr *) &nl->addr, sizeof (nl->addr)); in mnl_socket_bind()
207 addr_len = sizeof(nl->addr); in mnl_socket_bind()
208 ret = getsockname(nl->fd, (struct sockaddr *) &nl->addr, &addr_len); in mnl_socket_bind()
212 if (addr_len != sizeof(nl->addr)) { in mnl_socket_bind()
214 return -1; in mnl_socket_bind()
216 if (nl->addr.nl_family != AF_NETLINK) { in mnl_socket_bind()
218 return -1; in mnl_socket_bind()
224 * mnl_socket_sendto - send a netlink message of a certain size
225 * \param nl netlink socket obtained via mnl_socket_open()
229 * On error, it returns -1 and errno is appropriately set. Otherwise, it
238 return sendto(nl->fd, buf, len, 0, in mnl_socket_sendto()
243 * mnl_socket_recvfrom - receive a netlink message
244 * \param nl netlink socket obtained via mnl_socket_open()
248 * On error, it returns -1 and errno is appropriately set. If errno is set
274 ret = recvmsg(nl->fd, &msg, 0); in mnl_socket_recvfrom()
275 if (ret == -1) in mnl_socket_recvfrom()
280 return -1; in mnl_socket_recvfrom()
284 return -1; in mnl_socket_recvfrom()
290 * mnl_socket_close - close a given netlink socket
291 * \param nl netlink socket obtained via mnl_socket_open()
293 * On error, this function returns -1 and errno is appropriately set.
298 int ret = close(nl->fd); in mnl_socket_close()
304 * mnl_socket_setsockopt - set Netlink socket option
305 * \param nl netlink socket obtained via mnl_socket_open()
306 * \param type type of Netlink socket options
310 * This function allows you to set some Netlink socket option. As of writing
313 * - \#define NETLINK_ADD_MEMBERSHIP 1
314 * - \#define NETLINK_DROP_MEMBERSHIP 2
315 * - \#define NETLINK_PKTINFO 3
316 * - \#define NETLINK_BROADCAST_ERROR 4
317 * - \#define NETLINK_NO_ENOBUFS 5
320 * 32-bits mask. However, since 2.6.14, Netlink may have up to 2^32 multicast
324 * and the 32-bit mask to join a set of Netlink multicast groups.
326 * On error, this function returns -1 and errno is appropriately set.
331 return setsockopt(nl->fd, SOL_NETLINK, type, buf, len); in mnl_socket_setsockopt()
335 * mnl_socket_getsockopt - get a Netlink socket option
336 * \param nl netlink socket obtained via mnl_socket_open()
337 * \param type type of Netlink socket options
341 * On error, this function returns -1 and errno is appropriately set.
346 return getsockopt(nl->fd, SOL_NETLINK, type, buf, len); in mnl_socket_getsockopt()