Linux |
CentOS 4.8 |
|
![]() |
rtnetlink(3) |
![]() |
|
rtnetlink − Macros manipulant des messages rtnetlink |
|
#include <asm/types.h> rtnetlink_socket = socket(PF_NETLINK, int
socket_type, NETLINK_ROUTE); |
|
Tous les messages rtnetlink(7) consistent en un en-tête de message netlink(7) et des attributs. Ceux-ci ne devraient être manipulés que par les macros fournies ici. RTA_OK(rta,
attrlongueurr) renvoie vrai si rta
pointe sur un attribut de routage valide;
attrlongueurr est la longueur courrante du tampon
d’attributs. Si elle renvoie 0, vous devez supposer
qu’il n’y a pas d’autre attributs dans le
message, même si attrlongueurr
n’est pas nulle. |
|
Créer un message rtnetlink pour choisir le MTU d’un périphérique. |
|
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_longueurr = 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_longueurr)); |
|||||
|
rta->rta_type = IFLA_MTU; |
|||||
|
rta->rta_longueurr = sizeof(unsigned int); |
|||||
|
req.n.nlmsg_longueurr = NLMSG_ALIGN(req.n.nlmsg_longueurr) + |
|||||
|
RTA_LENGTH(sizeof(mtu)); |
|||||
|
memcpy(RTA_DATA(rta), &mtu, sizeof (mtu)); |
|||||
|
send(rtnetlink_sk, &req, req.n.nlmsg_longueurr); |
|
Cette page de manuel est incomplète. |
|
rtnetlink(7), netlink(7), netlink(3) |
|
Thierry Vignaud <tvignaud@mandrakesoft.com>, 2000 |
![]() |
rtnetlink(3) | ![]() |