int if_info_save_interface(struct nlmsghdr *hdr, void *arg) { struct rtattr *attrs[IFLA_MAX + 1]; struct ifinfomsg *info = NLMSG_DATA(hdr); parse_rtattrs(attrs, IFLA_MAX, IFLA_RTA(info), IFLA_PAYLOAD(hdr)); return if_info_update_interface(hdr, attrs) ? 0 : -1; }
/* * parse_route_msg */ int parse_route_msg (netlink_msg_ctx_t *ctx) { int len; struct rtattr **rtattrs, *rtattr, *gateway, *oif; int if_index; ctx->rtmsg = NLMSG_DATA(ctx->hdr); len = ctx->hdr->nlmsg_len - NLMSG_LENGTH(sizeof(struct rtmsg)); if (len < 0) { netlink_msg_ctx_set_err(ctx, "Bad message length"); return 0; } if (!parse_rtattrs(ctx, RTM_RTA(ctx->rtmsg), len)) { return 0; } rtattrs = ctx->rtattrs; ctx->dest = rtattrs[RTA_DST]; ctx->src = rtattrs[RTA_PREFSRC]; rtattr = rtattrs[RTA_PRIORITY]; if (rtattr) { ctx->metric = (int *) RTA_DATA(rtattr); } gateway = rtattrs[RTA_GATEWAY]; oif = rtattrs[RTA_OIF]; if (gateway || oif) { if_index = 0; if (oif) { if_index = *((int *) RTA_DATA(oif)); } netlink_msg_ctx_add_nh(ctx, if_index, gateway); } rtattr = rtattrs[RTA_MULTIPATH]; if (rtattr) { parse_multipath_attr(ctx, rtattr); } return 1; }