Manual Pages for Linux CentOS command on man rtnetlink
MyWebUniversity

Manual Pages for Linux CentOS command on man rtnetlink

RTNETLINK(3) Linux Programmer's Manual RTNETLINK(3)

NAME

rtnetlink - macros to manipulate rtnetlink messages SYNOPSIS

#include

#include

#include

#include rtnetlinksocket = socket(AFNETLINK, int sockettype, NETLINKROUTE); int RTAOK(struct rtattr *rta, int rtabuflen); void *RTADATA(struct rtattr *rta); unsigned int RTAPAYLOAD(struct rtattr *rta); struct rtattr *RTANEXT(struct rtattr *rta, unsigned int rtabuflen); unsigned int RTALENGTH(unsigned int length); unsigned int RTASPACE(unsigned int length); DESCRIPTION All rtnetlink(7) messages consist of a netlink(7) message header and appended attributes. The attributes should be manipulated only using the macros provided here. RTAOK(rta, attrlen) returns true if rta points to a valid routing attribute; attrlen is the running length of the attribute buffer. When not true then you must assume there are no more attributes in the mes‐ sage, even if attrlen is nonzero. RTADATA(rta) returns a pointer to the start of this attribute's data. RTAPAYLOAD(rta) returns the length of this attribute's data. RTANEXT(rta, attrlen) gets the next attribute after rta. Calling this macro will update attrlen. You should use RTAOK to check the validity of the returned pointer. RTALENGTH(len) returns the length which is required for len bytes of data plus the header. RTASPACE(len) returns the amount of space which will be needed in a message with len bytes of data. CONFORMING TO These macros are nonstandard Linux extensions. BUGS This manual page is incomplete. EXAMPLE Creating a rtnetlink message to set the MTU of a device:

#include ... struct { struct nlmsghdr nh; struct ifinfomsg if; char attrbuf[512]; } req; struct rtattr *rta; unsigned int mtu = 1000; int rtnetlinksk = socket(AFNETLINK, SOCKDGRAM, NETLINKROUTE); memset(&req, 0, sizeof(req)); req.nh.nlmsglen = NLMSGLENGTH(sizeof(struct ifinfomsg)); req.nh.nlmsgflags = NLMFREQUEST; req.nh.nlmsgtype = RTMNEWLINK; req.if.ififamily = AFUNSPEC; req.if.ifiindex = INTERFACEINDEX; req.if.ifichange = 0xffffffff; /* ??? */ rta = (struct rtattr *)(((char *) &req) + NLMSGALIGN(req.nh.nlmsglen));

rta->rtatype = IFLAMTU;

rta->rtalen = RTALENGTH(sizeof(unsigned int)); req.n.nlmsglen = NLMSGALIGN(req.nh.nlmsglen) + RTALENGTH(sizeof(mtu)); memcpy(RTADATA(rta), &mtu, sizeof(mtu)); send(rtnetlinksk, &req, req.nh.nlmsglen); SEE ALSO netlink(3), netlink(7), rtnetlink(7) COLOPHON

This page is part of release 3.53 of the Linux man-pages project. A description of the project, and information about reporting bugs, can

be found at http://www.kernel.org/doc/man-pages/.

GNU 2012-03-24 RTNETLINK(3)




Contact us      |      About us      |      Term of use      |       Copyright © 2000-2019 MyWebUniversity.com ™