
despen at verizon
Nov 14, 2009, 1:56 PM
Post #5 of 6
(1560 views)
Permalink
|
David Woodhouse <dwmw2 [at] infradead> writes: > On Sat, 2009-11-14 at 09:27 -0500, despen [at] verizon wrote: >> >> I'm thinking of modifying the source to save a copy of the >> routing table after it's set up, then periodically getting a new >> copy and comparing the 2 tables. I'd rather be able to directly >> detect changes but I don't see any API for that. > > Netlink. Hmm, never heard of it. Just gave it a quick try, (code below). What does it do? I found some sample code then added groups for route add, delete, get, then did some route, route add, route del commands but got no messages. #include <stdio.h> #include <string.h> #include <stdlib.h> #include <asm/types.h> #include <sys/socket.h> #include <linux/netlink.h> #include <linux/rtnetlink.h> struct sockaddr_nl sa; #define handle_error(msg) \ do { perror(msg); exit(EXIT_FAILURE); } while (0) void read_msgs( ); int fd; int main (int argc, char *argv[]) { int rc; memset (&sa, 0, sizeof(sa)); sa.nl_family = AF_NETLINK; sa.nl_groups = RTMGRP_LINK | RTMGRP_IPV4_IFADDR | RTM_NEWROUTE | RTM_DELROUTE | RTM_GETROUTE; fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); rc = bind(fd, (struct sockaddr*)&sa, sizeof(sa)); if (rc == -1) { handle_error("bind"); } read_msgs(); return 0; } void read_msgs(void) { int len; char buf[4096]; struct iovec iov = { buf, sizeof(buf) }; struct msghdr msg = { (void *)&sa, sizeof(sa), &iov, 1, NULL, 0, 0 }; struct nlmsghdr *nh; printf("enter recvmsg\n"); len = recvmsg (fd, &msg, 0); printf("got recvmsg"); for (nh = (struct nlmsghdr *) buf; NLMSG_OK (nh, len); nh = NLMSG_NEXT (nh, len)) { /* The end of multipart message. */ if (nh->nlmsg_type == NLMSG_DONE) return; if (nh->nlmsg_type == NLMSG_ERROR) { printf("Error\n"); /* Do some error handling. */ /* Continue with parsing payload. */ } } } _______________________________________________ vpnc-devel mailing list vpnc-devel [at] unix-ag https://lists.unix-ag.uni-kl.de/mailman/listinfo/vpnc-devel http://www.unix-ag.uni-kl.de/~massar/vpnc/
|