Man page - mnl_socket_open2(3)
Packages contains this manual
- mnl_nlmsg_batch_next(3)
- mnl_attr_put_str(3)
- mnl_attr_put(3)
- mnl_attr_next(3)
- mnl_attr_get_str(3)
- mnl_attr_ok(3)
- mnl_nlmsg_ok(3)
- mnl_nlmsg_batch_reset(3)
- mnl_nlmsg_next(3)
- mnl_nlmsg_portid_ok(3)
- mnl_nlmsg_batch_is_empty(3)
- mnl_attr_nest_cancel(3)
- mnl_attr_get_u16(3)
- mnl_nlmsg_batch_stop(3)
- mnl_attr_parse_payload(3)
- mnl_nlmsg_seq_ok(3)
- mnl_socket_sendto(3)
- mnl_attr_get_u64(3)
- mnl_attr_put_strz_check(3)
- mnl_cb_run2(3)
- mnl_attr_parse(3)
- mnl_attr_parse_nested(3)
- mnl_nlmsg_put_header(3)
- mnl_nlmsg_fprintf(3)
- mnl_socket_get_portid(3)
- mnl_attr_validate(3)
- mnl_attr_get_u8(3)
- mnl_socket_open(3)
- mnl_nlmsg_put_extra_header(3)
- mnl_attr_put_u64(3)
- mnl_attr_put_str_check(3)
- mnl_attr_put_strz(3)
- mnl_attr_validate2(3)
- mnl_nlmsg_get_payload_len(3)
- mnl_nlmsg_get_payload(3)
- mnl_attr_get_payload(3)
- mnl_socket_fdopen(3)
- mnl_nlmsg_get_payload_offset(3)
- mnl_attr_get_payload_len(3)
- mnl_attr_put_u8_check(3)
- mnl_nlmsg_batch_head(3)
- mnl_attr_nest_end(3)
- mnl_attr_put_u8(3)
- mnl_attr_get_u32(3)
- mnl_attr_type_valid(3)
- mnl_socket_setsockopt(3)
- mnl_socket_close(3)
- mnl_attr_put_u16_check(3)
- mnl_socket_open2(3)
- mnl_cb_run(3)
- mnl_socket_bind(3)
- mnl_attr_put_u32_check(3)
- mnl_socket_getsockopt(3)
- mnl_nlmsg_get_payload_tail(3)
- mnl_attr_nest_start(3)
- mnl_nlmsg_size(3)
- mnl_attr_put_u16(3)
- mnl_socket_get_fd(3)
- mnl_attr_put_check(3)
- mnl_nlmsg_batch_current(3)
- mnl_attr_put_u32(3)
- mnl_attr_put_u64_check(3)
- mnl_attr_get_len(3)
- mnl_nlmsg_batch_size(3)
- mnl_nlmsg_batch_start(3)
- mnl_attr_nest_start_check(3)
- mnl_attr_get_type(3)
- mnl_socket_recvfrom(3)
apt-get install libmnl-doc
Manual
socket
NAMESYNOPSIS
Functions
Detailed Description
Function Documentation
int mnl_socket_bind (struct mnl_socket * nl, unsigned int groups, pid_tpid)
int mnl_socket_close (struct mnl_socket * nl)
struct mnl_socket * mnl_socket_fdopen (int fd)
int mnl_socket_get_fd (const struct mnl_socket * nl)
unsigned int mnl_socket_get_portid (const struct mnl_socket * nl)
int mnl_socket_getsockopt (const struct mnl_socket * nl, int type, void *buf, socklen_t * len)
struct mnl_socket * mnl_socket_open (int bus)
struct mnl_socket * mnl_socket_open2 (int bus, int flags)
ssize_t mnl_socket_recvfrom (const struct mnl_socket * nl, void * buf,size_t bufsiz)
ssize_t mnl_socket_sendto (const struct mnl_socket * nl, const void * buf,size_t len)
int mnl_socket_setsockopt (const struct mnl_socket * nl, int type, void *buf, socklen_t len)
Author
NAME
socket - Netlink socket helpers
SYNOPSIS
Functions
int
mnl_socket_get_fd
(const struct mnl_socket *nl)
unsigned int
mnl_socket_get_portid
(const struct
mnl_socket *nl)
struct mnl_socket *
mnl_socket_open
(int bus)
struct mnl_socket *
mnl_socket_open2
(int bus, int
flags)
struct mnl_socket *
mnl_socket_fdopen
(int fd)
int
mnl_socket_bind
(struct mnl_socket *nl, unsigned
int groups, pid_t pid)
ssize_t
mnl_socket_sendto
(const struct mnl_socket
*nl, const void *buf, size_t len)
ssize_t
mnl_socket_recvfrom
(const struct mnl_socket
*nl, void *buf, size_t bufsiz)
int
mnl_socket_close
(struct mnl_socket *nl)
int
mnl_socket_setsockopt
(const struct mnl_socket
*nl, int type, void *buf, socklen_t len)
int
mnl_socket_getsockopt
(const struct mnl_socket
*nl, int type, void *buf, socklen_t *len)
Detailed Description
Function Documentation
int mnl_socket_bind (struct mnl_socket * nl, unsigned int groups, pid_tpid)
mnl_socket_bind - bind netlink socket
Parameters
nl
netlink socket
obtained via
mnl_socket_open()
groups
the group of message youβre interested in
pid
the port ID you want to use (use zero for automatic
selection)
On error, this function returns -1 and errno is appropriately set. On success, 0 is returned. You can use MNL_SOCKET_AUTOPID which is 0 for automatic port ID selection.
Definition at line 193 of file socket.c .
int mnl_socket_close (struct mnl_socket * nl)
mnl_socket_close - close a given netlink socket
Parameters
nl netlink socket obtained via mnl_socket_open()
On error, this function returns -1 and errno is appropriately set. On success, it returns 0.
Definition at line 296 of file socket.c .
struct mnl_socket * mnl_socket_fdopen (int fd)
mnl_socket_fdopen - associates a mnl_socket object with pre-existing socket.
Parameters
fd pre-existing socket descriptor.
On error, it returns NULL and errno is appropriately set. Otherwise, it returns a valid pointer to the mnl_socket structure. It also sets the portID if the socket fd is already bound and it is AF_NETLINK.
Note that mnl_socket_get_portid() returns 0 if this function is used with non-netlink socket.
Definition at line 161 of file socket.c .
int mnl_socket_get_fd (const struct mnl_socket * nl)
mnl_socket_get_fd - obtain file descriptor from netlink socket
Parameters
nl netlink socket obtained via mnl_socket_open()
This function returns the file descriptor of a given netlink socket.
Definition at line 85 of file socket.c .
unsigned int mnl_socket_get_portid (const struct mnl_socket * nl)
mnl_socket_get_portid - obtain Netlink PortID from netlink socket
Parameters
nl netlink socket obtained via mnl_socket_open()
This function returns the Netlink PortID of a given netlink socket. Itβs a common mistake to assume that this PortID equals the process ID which is not always true. This is the case if you open more than one socket that is binded to the same Netlink subsystem from the same process.
Definition at line 99 of file socket.c .
int mnl_socket_getsockopt (const struct mnl_socket * nl, int type, void *buf, socklen_t * len)
mnl_socket_getsockopt - get a Netlink socket option
Parameters
nl
netlink socket
obtained via
mnl_socket_open()
type
type of Netlink socket options
buf
pointer to the buffer to store the value of this
option
len
size of the information written in the buffer
On error, this function returns -1 and errno is appropriately set.
Definition at line 343 of file socket.c .
struct mnl_socket * mnl_socket_open (int bus)
mnl_socket_open - open a netlink socket
Parameters
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.
Definition at line 128 of file socket.c .
struct mnl_socket * mnl_socket_open2 (int bus, int flags)
mnl_socket_open2 - open a netlink socket with appropriate flags
Parameters
bus
the netlink socket
bus ID (see NETLINK_* constants)
flags
the netlink socket flags (see SOCK_* constants in
socket(2))
This is similar to mnl_socket_open() , but allows one 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.
Definition at line 145 of file socket.c .
ssize_t mnl_socket_recvfrom (const struct mnl_socket * nl, void * buf,size_t bufsiz)
mnl_socket_recvfrom - receive a netlink message
Parameters
nl
netlink socket
obtained via
mnl_socket_open()
buf
buffer that you want to use to store the netlink
message
bufsiz
size of the buffer passed to store the netlink
message
On error, it returns -1 and errno is appropriately set. If errno is set to ENOSPC, it means that the buffer that you have passed to store the netlink message is too small, so you have received a truncated message. To avoid this, you have to allocate a buffer of MNL_SOCKET_BUFFER_SIZE (which is 8KB, see linux/netlink.h for more information). Using this buffer size ensures that your buffer is big enough to store the netlink message without truncating it.
Definition at line 256 of file socket.c .
ssize_t mnl_socket_sendto (const struct mnl_socket * nl, const void * buf,size_t len)
mnl_socket_sendto - send a netlink message of a certain size
Parameters
nl
netlink socket
obtained via
mnl_socket_open()
buf
buffer containing the netlink message to be sent
len
number of bytes in the buffer that you want to
send
On error, it returns -1 and errno is appropriately set. Otherwise, it returns the number of bytes sent.
Definition at line 232 of file socket.c .
int mnl_socket_setsockopt (const struct mnl_socket * nl, int type, void *buf, socklen_t len)
mnl_socket_setsockopt - set Netlink socket option
Parameters
nl
netlink socket
obtained via
mnl_socket_open()
type
type of Netlink socket options
buf
the buffer that contains the data about this option
len
the size of the buffer passed
This function allows you to set some Netlink socket option. As of writing this (see linux/netlink.h), the existing options are:
- \#define
NETLINK_ADD_MEMBERSHIP 1
- \#define NETLINK_DROP_MEMBERSHIP 2
- \#define NETLINK_PKTINFO 3
- \#define NETLINK_BROADCAST_ERROR 4
- \#define NETLINK_NO_ENOBUFS 5
In the early days, Netlink only supported 32 groups expressed in a 32-bits mask. However, since 2.6.14, Netlink may have up to 2Λ32 multicast groups but you have to use setsockopt() with NETLINK_ADD_MEMBERSHIP to join a given multicast group. This function internally calls setsockopt() to join a given netlink multicast group. You can still use mnl_bind() and the 32-bit mask to join a set of Netlink multicast groups.
On error, this function returns -1 and errno is appropriately set.
Definition at line 328 of file socket.c .
Author
Generated automatically by Doxygen for libmnl from the source code.