Movatterモバイル変換


[0]ホーム

URL:


man7.org > Linux >man-pages

Linux/UNIX system programming training


rtnetlink(3) — Linux manual page

NAME |LIBRARY |SYNOPSIS |DESCRIPTION |STANDARDS |BUGS |EXAMPLES |SEE ALSO |COLOPHON

rtnetlink(3)             Library Functions Manualrtnetlink(3)

NAME        top

       rtnetlink - macros to manipulate rtnetlink messages

LIBRARY        top

       Standard C library (libc,-lc)

SYNOPSIS        top

#include <asm/types.h>#include <linux/netlink.h>#include <linux/rtnetlink.h>#include <sys/socket.h>rtnetlink_socket = socket(AF_NETLINK, intsocket_type, NETLINK_ROUTE);int RTA_OK(struct rtattr *rta, intsize);void *RTA_DATA(struct rtattr *rta);unsigned int RTA_PAYLOAD(struct rtattr *rta);struct rtattr *RTA_NEXT(struct rtattr *rta, unsigned intsize);unsigned int RTA_LENGTH(unsigned intsize);unsigned int RTA_SPACE(unsigned intsize);

DESCRIPTION        top

       Allrtnetlink(7) messages consist of anetlink(7) message header       and appended attributes.  The attributes should be manipulated       only using the macros provided here.RTA_OK(rta,size)returns true ifrta points to a valid routing       attribute;size is the running size of the attribute buffer.  When       not true then you must assume there are no more attributes in the       message, even ifsize is nonzero.RTA_DATA(rta)returns a pointer to the start of this attribute's       data.RTA_PAYLOAD(rta)returns the size of this attribute's data.RTA_NEXT(rta,size)gets the next attribute afterrta.  Calling       this macro will updatesize.  You should useRTA_OKto check the       validity of the returned pointer.RTA_LENGTH(size)returns the size which is required forsize bytes       of data plus the header.RTA_SPACE(size)returns the amount of space which will be needed       in a message withsize bytes of data.

STANDARDS        top

       Linux.

BUGS        top

       This manual page is incomplete.

EXAMPLES        top

       Creating a rtnetlink message to set the MTU of a device:           #include <linux/rtnetlink.h>           ...           struct {               struct nlmsghdr  nh;               struct ifinfomsg if;               char             attrbuf[512];           } req;           struct rtattr *rta;           unsigned int mtu = 1000;           int rtnetlink_sk = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE);           memset(&req, 0, sizeof(req));           req.nh.nlmsg_len = NLMSG_LENGTH(sizeof(req.if));           req.nh.nlmsg_flags = NLM_F_REQUEST;           req.nh.nlmsg_type = RTM_NEWLINK;           req.if.ifi_family = AF_UNSPEC;           req.if.ifi_index = INTERFACE_INDEX;           req.if.ifi_change = 0xffffffff; /* ??? */           rta = (struct rtattr *) ((char *) &req +                                    NLMSG_ALIGN(req.nh.nlmsg_len));           rta->rta_type = IFLA_MTU;           rta->rta_len = RTA_LENGTH(sizeof(mtu));           req.nh.nlmsg_len = NLMSG_ALIGN(req.nh.nlmsg_len) +                                         RTA_LENGTH(sizeof(mtu));           memcpy(RTA_DATA(rta), &mtu, sizeof(mtu));           send(rtnetlink_sk, &req, req.nh.nlmsg_len, 0);

SEE ALSO        top

netlink(3),netlink(7),rtnetlink(7)

COLOPHON        top

       This page is part of theman-pages (Linux kernel and C library       user-space interface documentation) project.  Information about       the project can be found at        ⟨https://www.kernel.org/doc/man-pages/⟩.  If you have a bug report       for this manual page, see       ⟨https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/tree/CONTRIBUTING⟩.       This page was obtained from the tarball man-pages-6.15.tar.gz       fetched from       ⟨https://mirrors.edge.kernel.org/pub/linux/docs/man-pages/⟩ on       2025-08-11.  If you discover any rendering problems in this HTML       version of the page, or you believe there is a better or more up-       to-date source for the page, or you have corrections or       improvements to the information in this COLOPHON (which isnot       part of the original manual page), send a mail to       man-pages@man7.orgLinux man-pages 6.15            2025-05-17rtnetlink(3)

Pages that refer to this page:libnetlink(3)rtnetlink(7)sock_diag(7)



HTML rendering created 2025-09-06 byMichael Kerrisk, author ofThe Linux Programming Interface.

For details of in-depthLinux/UNIX system programming training courses that I teach, lookhere.

Hosting byjambit GmbH.

Cover of TLPI


[8]ページ先頭

©2009-2025 Movatter.jp