Scroll to navigation

libnetlink(3) Library Functions Manual libnetlink(3)

НАИМЕНОВАНИЕ

libnetlink - библиотека для доступа к сервису netlink

ОБЗОР

#include <asm/types.h>

#include <libnetlink.h>
#include <linux/netlink.h>
#include <linux/rtnetlink.h> int rtnl_open(struct rtnl_handle *rth, unsigned subscriptions) int rtnl_wilddump_request(struct rtnl_handle *rth, int family, int type) int rtnl_send(struct rtnl_handle *rth, char *buf, int len) int rtnl_dump_request(struct rtnl_handle *rth, int type, void *req, int len) int rtnl_dump_filter(struct rtnl_handle *rth, int (*filter)(struct sockaddr_nl *, struct nlmsghdr *n, void *), void *arg1, int (*junk)(struct sockaddr_nl *,struct nlmsghdr *n, void *), void *arg2) int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer, unsigned groups, struct nlmsghdr *answer,
int (*junk)(struct sockaddr_nl *,struct nlmsghdr *n, void *),
void *jarg) int rtnl_listen(struct rtnl_handle *rtnl, int (*handler)(struct sockaddr_nl *, struct rtnl_ctrl_data *, struct nlmsghdr *n, void *), void *jarg) int rtnl_from_file(FILE *rtnl, int (*handler)(struct sockaddr_nl *,struct nlmsghdr *n, void *), void *jarg) int addattr32(struct nlmsghdr *n, int maxlen, int type, __u32 data) int addattr_l(struct nlmsghdr *n, int maxlen, int type, void *data, int alen) int rta_addattr32(struct rtattr *rta, int maxlen, int type, __u32 data) int rta_addattr_l(struct rtattr *rta, int maxlen, int type, void *data, int alen)

ОПИСАНИЕ

libnetlink предоставляет интерфейс более высокого уровня к rtnetlink(7). Функции чтения возвращают 0 при успешном завершении, и отрицательный код errno в случае ошибки. Функции отправки возвращают объем отправленной информации, или -1 в случае ошибки.

Open a rtnetlink socket and save the state into the rth handle. This handle is passed to all subsequent calls. subscriptions is a bitmap of the rtnetlink multicast groups the socket will be a member of.

Request a full dump of the type database for family addresses. type is a rtnetlink message type.

Request a full dump of the type data buffer into buf with maximum length of len. type is a rtnetlink message type.

Receive netlink data after a request and filter it. The filter callback checks if the received message is wanted. It gets the source address of the message, the message itself and arg1 as arguments. 0 as return means that the filter passed, a negative value is returned by rtnl_dump_filter in case of error. NULL for filter means to not use a filter. junk is used to filter messages not destined to the local socket. Only one message bundle is received. If there is a message pending, this function does not block.

Receive netlink data after a request and pass it to handler. handler is a callback that gets the message source address, anscillary data, the message itself, and the jarg cookie as arguments. It will get called for all received messages. Only one message bundle is received. If there is a message pending this function does not block.

Работает как rtnl_listen, но считывает набор (bundle) сообщений netlink из файла file и передает сообщения обработчику handler для обработки. Файл содержит "сырые" данные в том виде, в каком они были получены из сокета rtnetlink.

The following functions are useful to construct custom rtnetlink messages. For simple database dumping with filtering it is better to use the higher level functions above. See rtnetlink(3) and netlink(3) on how to generate a rtnetlink message. The following utility functions require a continuous buffer that already contains a netlink message header and a rtnetlink request.

Send the rtnetlink message in buf of length len to handle rth.

Добавить __u32-атрибут типа type со значением data к netlink-сообщению n, которое является частью буфера длиной maxlen.

Добавить атрибут переменной длины типа type со значением data и длиной alen к netlink-сообщению n, которое являются частью буфера длиной maxlen. Содержимое data копируется.

Инициализировать rtnetlink-атрибут rta __u32-значением.

Инициализировать rtnetlink-атрибут rta значением переменной длины.

ОШИБКИ

This library is meant for internal use, use libmnl for new programs.

Функции иногда используют fprintf и завершаются при возникновении фатальной ошибки. Эта библиотека должна быть названа librtnetlink.

АВТОРЫ

netlink/rtnetlink был спроектирован и написан Алексеем Кузнецовым. Энди Клеен (Andi Kleen) написал страницу руководства.

СМОТРИТЕ ТАКЖЕ

netlink(7), rtnetlink(7)
/usr/include/linux/rtnetlink.h

ПЕРЕВОД

Русский перевод этой страницы руководства разработал(и) Виктор Ерёмин <ErV2005@rambler.ru>

Этот перевод является свободной программной документацией; он распространяется на условиях общедоступной лицензии GNU (GNU General Public License - GPL, https://www.gnu.org/licenses/gpl-3.0.html версии 3 или более поздней) в отношении авторского права, но БЕЗ КАКИХ-ЛИБО ГАРАНТИЙ.

Если вы обнаружите какие-либо ошибки в переводе этой страницы руководства, пожалуйста, сообщите об этом разработчику(ам) по его(их) адресу(ам) электронной почты или по адресу списка рассылки русских переводчиков.