File: rtnetlink.3

package info (click to toggle)
manpages-es 1.55-9
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 7,468 kB
  • ctags: 6
  • sloc: sh: 1,629; makefile: 64
file content (116 lines) | stat: -rw-r--r-- 3,378 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
.\" This man page is Copyright (C) 1999 Andi Kleen <ak@muc.de>.
.\" 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 <piernas@ditec.um.es>
.\"
.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 <asm/types.h>
.br
.B #include <linux/netlink.h>
.br
.B #include <linux/rtnetlink.h>
.br
.B #include <sys/socket.h>

.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)