rtnetlink

Section: C Library Functions (3)
Updated: 2026-02-08
Index JM Home Page roff page
 

名前

rtnetlink - rtnetlink メッセージを操作するマクロ  

ライブラリ

標準 C ライブラリ (libc,~-lc)  

書式

#include <asm/types.h>
#include <linux/netlink.h>
#include <linux/rtnetlink.h>
#include <sys/socket.h>

rtnetlink_socket = socket(AF_NETLINK, int socket_type, NETLINK_ROUTE);

int RTA_OK(struct rtattr *rta, int size);

void *RTA_DATA(struct rtattr *rta);
unsigned int RTA_PAYLOAD(struct rtattr *rta);

struct rtattr *RTA_NEXT(struct rtattr *rta, unsigned int size);

unsigned int RTA_LENGTH(unsigned int size);
unsigned int RTA_SPACE(unsigned int size);
 

説明

全ての rtnetlink(7) メッセージは netlink(7) メッセージヘッダーと追加属性からなる。 属性の操作は、必ずここに挙げたマクロだけを使って行うべきである。

RTA_OK(rta, size) returns true if rta 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 if size is nonzero.

RTA_DATA(rta) はこの属性データの先頭へのポインターを返す。

RTA_PAYLOAD(rta) はこの属性データのサイズを返す。

RTA_NEXT(rta, size) gets the next attribute after rta. Calling this macro will update size. You should use RTA_OK to check the validity of the returned pointer.

RTA_LENGTH(len) は size バイトのデータ + ヘッダーに必要なサイズを返す。

RTA_SPACE(size) は size バイトのデータを持つメッセージに必要とされる容量を返す。  

標準規格

Linux.  

バグ

このマニュアルは完全ではない。  

例

デバイスの MTU をセットする rtnetlink メッセージを生成する

#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);
 

関連項目

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


 

Index

名前
ライブラリ
書式
説明
標準規格
バグ
例
関連項目

This document was created by man2html, using the manual pages.