NA01
13-11-2005, 10:16
sto usand le libipq copiando pari pari quello che c'è nel man libipq:
#include <linux/netfilter.h>
#include <libipq/libipq.h>
#include <stdio.h>
#include <netinet/tcp.h>
#include <netinet/ip.h>
#define BUFSIZE 2048
static void die(struct ipq_handle *h){
ipq_perror("passer");
ipq_destroy_handle(h);
exit(1);
}
int main(int argc, char **argv){
int status;
unsigned char buf[BUFSIZE];
struct ipq_handle *h;
h = ipq_create_handle(0, PF_INET);
if (!h)
die(h);
status = ipq_set_mode(h, IPQ_COPY_META, BUFSIZE);
if (status < 0)
die(h);
do{
status = ipq_read(h, buf, BUFSIZE, 0);
if (status < 0)
die(h);
switch (ipq_message_type(buf)) {
case NLMSG_ERROR:
fprintf(stderr, "Received error message %d\n",
ipq_get_msgerr(buf));
break;
case IPQM_PACKET: {
ipq_packet_msg_t *m = ipq_get_packet(buf);
struct iphdr *ip = ((struct iphdr *)m->payload);
struct tcphdr *tcp = (struct tcphdr*) (m->payload + (4 * ip->ihl));
int port = htons(tcp->dest);
int addr = ip->daddr;
fprintf(stderr,"a %d, %x, %x\n",port, addr, ip->saddr);
status = ipq_set_verdict(h, m->packet_id, NF_ACCEPT, 0, NULL);
if (status < 0)
die(h);
break;
}
default:
fprintf(stderr, "Unknown message type!\n");
break;
}
} while (1);
ipq_destroy_handle(h);
return 0;
}
come unica cosa ho aggiunto l'accesso a ip->saddr e a daddr, i problemi sono due:
la porta risulta essere SEMPRE la stessa, indipendentemente da cosa metto su queue, e gli indirizzi SEMPRE nuli :(
idee?
graziie, ciao!
#include <linux/netfilter.h>
#include <libipq/libipq.h>
#include <stdio.h>
#include <netinet/tcp.h>
#include <netinet/ip.h>
#define BUFSIZE 2048
static void die(struct ipq_handle *h){
ipq_perror("passer");
ipq_destroy_handle(h);
exit(1);
}
int main(int argc, char **argv){
int status;
unsigned char buf[BUFSIZE];
struct ipq_handle *h;
h = ipq_create_handle(0, PF_INET);
if (!h)
die(h);
status = ipq_set_mode(h, IPQ_COPY_META, BUFSIZE);
if (status < 0)
die(h);
do{
status = ipq_read(h, buf, BUFSIZE, 0);
if (status < 0)
die(h);
switch (ipq_message_type(buf)) {
case NLMSG_ERROR:
fprintf(stderr, "Received error message %d\n",
ipq_get_msgerr(buf));
break;
case IPQM_PACKET: {
ipq_packet_msg_t *m = ipq_get_packet(buf);
struct iphdr *ip = ((struct iphdr *)m->payload);
struct tcphdr *tcp = (struct tcphdr*) (m->payload + (4 * ip->ihl));
int port = htons(tcp->dest);
int addr = ip->daddr;
fprintf(stderr,"a %d, %x, %x\n",port, addr, ip->saddr);
status = ipq_set_verdict(h, m->packet_id, NF_ACCEPT, 0, NULL);
if (status < 0)
die(h);
break;
}
default:
fprintf(stderr, "Unknown message type!\n");
break;
}
} while (1);
ipq_destroy_handle(h);
return 0;
}
come unica cosa ho aggiunto l'accesso a ip->saddr e a daddr, i problemi sono due:
la porta risulta essere SEMPRE la stessa, indipendentemente da cosa metto su queue, e gli indirizzi SEMPRE nuli :(
idee?
graziie, ciao!