- while (1) {
- char buf[4000], *payload;
- struct nlmsghdr *nlh;
- ssize_t len, this_len;
- socklen_t socklen = sizeof(sa);
-
- if ((len = recvfrom(sock, buf, sizeof(buf), 0,
- (struct sockaddr *) &sa, &socklen)) <= 0)
- break;
- for (nlh = (struct nlmsghdr *) buf; NLMSG_OK(nlh, len); nlh = NLMSG_NEXT(nlh, len)) {
- struct nlattr *nla;
-
- if (nlh->nlmsg_type == NLMSG_DONE)
- break;
- else if (nlh->nlmsg_type == NLMSG_ERROR)
- break;
-
- this_len = NLMSG_ALIGN((nlh)->nlmsg_len) - NLMSG_LENGTH(0);
- payload = NLMSG_DATA(nlh);
- if (sa.nl_groups == RTMGRP_IPV6_PREFIX) {
- struct prefixmsg *prefixmsg;
- struct in6_addr *prefix;
- struct prefix_cacheinfo *cacheinfo;
-
- prefixmsg = (struct prefixmsg *) payload;
- prefix = NULL;
- cacheinfo = NULL;
- for (nla = (struct nlattr *)(payload + sizeof(*prefixmsg)); nla < payload + this_len; nla = (char *) nla + nla->nla_len) {
- if (nla->nla_type == PREFIX_ADDRESS)
- prefix = (struct in6_addr *)(((char *) nla) + sizeof(*nla));
- else if (nla->nla_type == PREFIX_CACHEINFO)
- cacheinfo = (struct prefix_cacheinfo *)(((char *) nla) + sizeof(*nla));
- }
- if (add_prefix(&head, prefixmsg, prefix, cacheinfo) == -1) {
- printf("Adding prefix failed!\n");
- }
- }
- else if (sa.nl_groups == RTMGRP_IPV6_IFADDR) {
- struct ifaddrmsg *ifaddrmsg;
- struct in6_addr *address;
- struct ifa_cacheinfo *cacheinfo;
-
- ifaddrmsg = (struct ifaddrmsg *) payload;
- address = NULL;
- cacheinfo = NULL;
- for (nla = (struct nlattr *)(payload + sizeof(*ifaddrmsg)); nla < payload + this_len; nla = (char *) nla + nla->nla_len) {
- if (nla->nla_type == IFA_ADDRESS)
- address = (struct in6_addr *)(((char *) nla) + sizeof(*nla));
- else if (nla->nla_type == IFA_CACHEINFO)
- cacheinfo = (struct ifa_cacheinfo *)(((char *) nla) + sizeof(*nla));
- }
- if (add_address(&head, ifaddrmsg, address, cacheinfo) == -1) {
- printf("Adding address failed!\n");
- }
- }
- }
+ return 0;
+}
+
+int handle_error_msg(struct sockaddr_nl *source, struct nlmsgerr *err,
+ void *arg)
+{
+ syslog(LOG_ERR, "%s", strerror(err->error));
+ return 0;
+}
+
+int handle_no_op(struct nl_msg *msg, void *arg)
+{
+ return 0;
+}
+
+/* only for access in the signal handler */
+struct prefix_list head;
+void signal_handler(int signal)
+{
+ switch (signal) {
+ case SIGUSR1: