*nix Documentation Project
·  Home
 +   man pages
·  Linux HOWTOs
·  FreeBSD Tips
·  *niX Forums

  man pages->Linux man pages -> rtnetlink (3)              



NAME    [Toc]    [Back]

       rtnetlink - Macros to manipuate rtnetlink messages

SYNOPSIS    [Toc]    [Back]

       #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);
       int RTA_OK(struct rtattr *rta, int rtabuflen);
       void *RTA_DATA(struct rtattr *rta);
       unsigned int RTA_PAYLOAD(struct rtattr *rta);
       struct rtattr *RTA_NEXT(struct rtattr *rta, unsigned int rtabuflen);
       unsigned int RTA_LENGTH(unsigned int length);
       unsigned int RTA_SPACE(unsigned int length);

DESCRIPTION    [Toc]    [Back]

       All  rtnetlink(7)  messages  consist of a netlink(7) 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.
       RTA_DATA(rta) returns a pointer to the start of this attribute's  data.
       RTA_PAYLOAD(rta) returns the length of this attribute's data.
       RTA_NEXT(rta, attrlen) gets the next attribute after rta.  Calling this
       macro will update attrlen.  You should use  RTA_OK  to  check  for  the
       validity of the returned pointer.
       RTA_LENGTH(len)	returns  the length which is required for len bytes of
       data plus the header.
       RTA_SPACE(len) returns the amount of space which will be needed in  the
       message with len bytes of data.

EXAMPLE    [Toc]    [Back]

       Creating 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_sk = 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) +
	    rta->rta_type = IFLA_MTU;
	    rta->rta_len = sizeof(unsigned int);
	    req.n.nlmsg_len = NLMSG_ALIGN(req.n.nlmsg_len) +
	    memcpy(RTA_DATA(rta), &mtu, sizeof (mtu));
	    send(rtnetlink_sk, &req, req.n.nlmsg_len);

BUGS    [Toc]    [Back]

       This manual page is lacking and incomplete.

SEE ALSO    [Toc]    [Back]

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

Linux Man Page			  1999-05-14			  RTNETLINK(3)
[ Back ]
 Similar pages
Name OS Title
msg IRIX Text formatting macros for UNICOS and IRIX messages
writesrv Tru64 Lets users send messages to and receive messages from a remote system
groff_ms FreeBSD groff ms macros
mm FreeBSD groff mm macros
groff_mm FreeBSD groff mm macros
groff_mm OpenBSD groff mm macros
groff_mm NetBSD groff mm macros
mm NetBSD groff mm macros
groff_ms NetBSD groff ms macros
ms FreeBSD groff ms macros
Copyright © 2004-2005 DeniX Solutions SRL
newsletter delivery service