#!/usr/bin/perl


        use IPTables::IPv4::IPQueue qw(:constants);
	use NetPacket::IP;
	use NetPacket::UDP;
	use Net::RawIP;
        
        my ($queue, $msg,$my_ip);
	$my_ip = "192.168.222.2";
        
        $queue = new IPTables::IPv4::IPQueue(copy_mode => IPQ_COPY_PACKET,copy_range => 65535)
                or die IPTables::IPv4::IPQueue->errstr;
                        
	while (1){
        $msg = $queue->get_message()
                or die IPTables::IPv4::IPQueue->errstr;
	$ip_pkt  = NetPacket::IP->decode($msg->payload);
	$udp_pkt = NetPacket::UDP->decode($ip_pkt->{data});
	$test = $udp_pkt->{data};

	if ($ip_pkt->{dest_ip} =~ $my_ip){
		$test = $udp_pkt->{data};
		if ($test =~ /&c\w\w\w/){
		$test =~ s/&c\w\w\w//g;
        	$queue->set_verdict($msg->packet_id(), NF_DROP) > 0
		       or die IPTables::IPv4::IPQueue->errstr;
		raw_send($ip_pkt->{src_ip}, $udp_pkt->{src_port}, $ip_pkt->{dest_ip}, $udp_pkt->{dest_port},$test);

		}else{
        		$queue->set_verdict($msg->packet_id(), NF_ACCEPT) > 0
		               or die IPTables::IPv4::IPQueue->errstr;
		}
		
	}else{
	      	$queue->set_verdict($msg->packet_id(), NF_ACCEPT) > 0
	              	or die IPTables::IPv4::IPQueue->errstr;
	}
                
	}

sub raw_send {
        my ($from_ip, $from_port, $to_ip, $to_port,$data ) = @_;

        my $ip = new Net::RawIP({
                                ip =>{
                                        saddr => $from_ip,
                                        daddr => $to_ip
                                        },
                                udp => {
                                        source => $from_port,
                                        dest => $to_port,
                                        data => $data
                                }
        });
        $ip->send;
}
