| Red Hat Documentation: man pages: man3: Linux Programmer's Manual (3) |
RTNETLINKSection: Linux Programmer's Manual (3)Updated: 14 May 2025 Index NAMErtnetlink - Macros to manipuate rtnetlink messagesSYNOPSISSYNOPSIS#include <asm/types.h>#include <linux/netlink.h> #include <linux/rtnetlink.h> #include <sys/socket.h>
rtnetlink_socket = socket(PF_NETLINK, int socket_type, NETLINK_ROUTE);
DESCRIPTIONAll messages consist of a message header and appended attributes. The attributes should be only manipulated using the macros provided here.
RTA_OK(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
message, even if
attrlen
is non-zero.
EXAMPLECreating a rtnetlink message to set a MTU of a device.
struct {
struct nlmsghdr nh;
struct ifinfomsg if;
char attrbuf[512];
} req;
struct rtattr *rta;
unsigned int mtu = 1000;
int rtnetlink_socket = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE);
memset(&req, 0, sizeof(req));
req.nh.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
req.nh.nlmsg_flags = NLM_F_REQUEST;
req.nh.nlmsg_type = RTML_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(n->nlmsg_len));
rta->rta_type = IFLA_MTU;
rta->rta_len = sizeof(unsigned int);
req.n.nlmsg_len = NLMSG_ALIGN(req.n.nlmsg_len) + RTA_LENGTH(sizeof(mtu));
memcpy(RTA_DATA(rta), &mtu, sizeof (mtu));
send(rtnetlink_socket, &req, req.n.nlmsg_len);
SEE ALSO
IndexThis document was created by using the manual pages. Time: 11:58:05 GMT, March 24, 2025 |
|
© 2001 Red Hat, Inc. All rights reserved. About Red Hat : Legal statement : Privacy statement : Y2K statement : Contact Red Hat |