.\" This man page is Copyright (C) 1999 Andi Kleen . .\" Permission is granted to distribute possibly modified copies .\" of this page provided the header is included verbatim, .\" and in case of nontrivial modification author and date .\" of the modification is added to the header. .\" $Id: rtnetlink.3,v 1.1 2004/07/14 11:21:45 pepin.jimenez Exp $ .\" .\" Translated on Sun Jun 27 1999 by Juan Piernas .\" .TH RTNETLINK 3 "14 mayo 1999" "Página man de Linux" "Manual del Programador de Linux" .SH NOMBRE rtnetlink \- Macros para manipular mensajes rtnetlink .SH SINOPSIS .B #include .br .B #include .br .B #include .br .B #include .BI "rtnetlink_socket = socket(PF_NETLINK, int " socket_type ", NETLINK_ROUTE);" .br .B int RTA_OK(struct rtattr *rta, int rtabuflen); .br .B void *RTA_DATA(struct rtattr *rta); .br .B unsigned int RTA_PAYLOAD(struct rtattr *rta); .br .B struct rtattr *RTA_NEXT(struct rtattr *rta, unsigned int rtabuflen); .br .B unsigned int RTA_LENGTH(unsigned int length); .br .B unsigned int RTA_SPACE(unsigned int length); .br .SH DESCRIPCIÓN Todos los mensajes .BR rtnetlink (7) están formados por una cabecera de mensaje .BR netlink (7) y atributos añadidos. Los atributos sólo deberían ser manipulados usando las macros suministradas aquí. .PP .BI RTA_OK( rta ", " attrlen ) devuelve verdadero si .I rta apunta a un atributo de enrutamiento válido. .I attrlen es la longitud actual del buffer de atributos. Cuando es falso debe asumir que no hay más atributos en el mensaje, aunque .I attrlen no sea cero. .br .BI RTA_DATA( rta ) devuelve un puntero al principio de los datos de este atributo. .br .BI RTA_PAYLOAD( rta ) devuelve la longitud de los datos de este atributo. .br .BI RTA_NEXT( rta ", " attrlen ) obtiene el siguiente atributo después de .IR rta . Al llamar a esta macro se actualizará .IR attrlen . Debería usar .B RTA_OK para comprobar la validez del puntero devuelto. .br .BI RTA_LENGTH( len ) devuelve la longitud que se necesita para .I len bytes de datos más la cabecera. .br .BI RTA_SPACE( len ) devuelve la cantidad de espacio que se necesitarán en el mensaje con .I len bytes de datos. .SH EJEMPLO .\" XXX would be better to use libnetlink here Crear un mensaje rtnetlink para configurar la MTU de un dispositivo. .nf 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) + 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_sk, &req, req.n.nlmsg_len); .fi .SH FALLOS Esta página de manual es escasa e incompleta. .SH VÉASE TAMBIÉN .BR rtnetlink (7), .BR netlink (7), .BR netlink (3)