Re: I need help with libnetfilter_queue

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



i> Hi again! I need help with libnetfilter_queue, I searched examples,
i> but I only found one simple test. My problem is that i need source ip
i> and source port, but i don't know how can i get from struct nfq_data
i> *pkt in the callback function.

#include <netinet/in.h>
#include <arpa/inet.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>

static int ob_netfilter_callback(struct nfq_q_handle *qh, struct nfgenmsg *nfmsg,
              struct nfq_data *nfa, void *data)
{
............
u_int16_t ip_packet_len = 0;
struct ip *ip_packet = NULL;
struct tcphdr *tcp_packet = NULL;

char *payload;
..........

nfq_get_payload(nfa, &payload);

ip_packet = ((struct ip *)payload);
ip_packet_len = ntohs(ip_packet->ip_len);

printf("Source IP %s\n",inet_ntoa(ip_packet->ip_src));

if (ip_packet->ip_p == IPPROTO_TCP) {
   tcp_packet = (struct tcphdr *)(payload + sizeof(struct ip));
   if (ntohs(tcp_packet->dest) == 25) { // SMTP PORT
      printf("this is SMTP");
   };
};

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netfitler Users]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux