rtnetlink(3) Library Functions Manual rtnetlink(3) rtnetlink - rtnetlink C (libc, -lc) #include #include #include #include rtnetlink_socket = socket(AF_NETLINK, int socket_type, NETLINK_ROUTE); int RTA_OK(struct rtattr *rta, int rtabuflen); void *RTA_DATA(struct rtattr *rta); unsigned int RTA_PAYLOAD(struct rtattr *rta); struct rtattr *RTA_NEXT(struct rtattr *rta, unsigned int rtabuflen); unsigned int RTA_LENGTH(unsigned int length); unsigned int RTA_SPACE(unsigned int length); rtnetlink(7) netlink(7) . . RTA_OK(rta, attrlen) , rta ; attrlen -- . , , attrlen . RTA_DATA(rta) . RTA_PAYLOAD(rta) . RTA_NEXT(rta, attrlen) rta . attrlen. RTA_OK. RTA_LENGTH(len) , len . RTA_SPACE(len) , len . Linux. . rtnetlink MTU : #include ... struct { struct nlmsghdr nh; struct ifinfomsg if; char attrbuf[512]; } req; struct rtattr *rta; unsigned int mtu = 1000; int rtnetlink_sk = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE); memset(&req, 0, sizeof(req)); req.nh.nlmsg_len = NLMSG_LENGTH(sizeof(req.if)); req.nh.nlmsg_flags = NLM_F_REQUEST; req.nh.nlmsg_type = RTM_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(req.nh.nlmsg_len)); rta->rta_type = IFLA_MTU; rta->rta_len = RTA_LENGTH(sizeof(mtu)); req.nh.nlmsg_len = NLMSG_ALIGN(req.nh.nlmsg_len) + RTA_LENGTH(sizeof(mtu)); memcpy(RTA_DATA(rta), &mtu, sizeof(mtu)); send(rtnetlink_sk, &req, req.nh.nlmsg_len, 0); netlink(3), netlink(7), rtnetlink(7) () aereiae , Azamat Hackimov , Dmitriy S. Seregin , Katrin Kutepova , Lockal , Yuri Kozlov , ; GNU (GNU General Public License - GPL, 3 ) , - . - , , () () () <>. Linux 6.9.1 2 2024 . rtnetlink(3)