1 #include "../src/utils.h" 2 3 static void change_cb(struct nl_cache *cache, struct nl_object *obj, 4 int action) 5 { 6 struct nfnl_ct *ct = (struct nfnl_ct *) obj; 7 static struct nl_addr *hack = NULL; 8 9 if (!hack) 10 hack = nl_addr_parse("194.88.212.233", AF_INET); 11 12 if (!nl_addr_cmp(hack, nfnl_ct_get_src(ct, 1)) || 13 !nl_addr_cmp(hack, nfnl_ct_get_dst(ct, 1))) { 14 struct nl_dump_params dp = { 15 .dp_type = NL_DUMP_LINE, 16 .dp_fd = stdout, 17 }; 18 19 printf("UPDATE "); 20 nl_object_dump(obj, &dp); 21 } 22 } 23 24 int main(int argc, char *argv[]) 25 { 26 struct nl_cache_mngr *mngr; 27 struct nl_sock *sock; 28 struct nl_cache *ct; 29 30 sock = nlt_socket_alloc(); 31 32 mngr = nl_cache_mngr_alloc(sock, NETLINK_NETFILTER, NL_AUTO_PROVIDE); 33 if (!mngr) { 34 nl_perror("nl_cache_mngr_alloc"); 35 return -1; 36 } 37 38 ct = nl_cache_mngr_add(mngr, "netfilter/ct", &change_cb); 39 if (ct == NULL) { 40 nl_perror("nl_cache_mngr_add(netfilter/ct)"); 41 return -1; 42 } 43 44 for (;;) { 45 int err = nl_cache_mngr_poll(mngr, 5000); 46 if (err < 0) { 47 nl_perror("nl_cache_mngr_poll()"); 48 return -1; 49 } 50 51 } 52 53 nl_cache_mngr_free(mngr); 54 55 return 0; 56 } 57