Hello,

I am working with iptables and libipq in Ubuntu right now and try to modify payload. How can I change some data in payload which I get from buffer? What should I do if I want to modify every 5th bit in payload? Also what should I do if I want to modify bits starting from bit No. 100 or later. Do I need to work not with bits but chars or smth else if I want modify payload of video packets.
Any help will be appreciated.

MC

Code:
/*
 *  T.c
 *
 *  compile: gcc -Wall T.c -o T -lipq
 */

#include <netinet/in.h>
#include <libipq.h>
#include <linux/netfilter.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <netinet/ip.h>
#include <netinet/udp.h>
#include <netinet/tcp.h>

#define BUFSIZE 65536




static void die(struct ipq_handle *h) {
    
    ipq_perror("passer");
    ipq_destroy_handle(h);
    
}


void start_packet_engine() {
   
        int status;
    unsigned char buf[BUFSIZE];
    struct ipq_handle *h;

    
    printf("\nWaiting for packets\n");
    

    h = ipq_create_handle(0, PF_INET);
    
    if (!h)
        die(h);
    
    
    status = ipq_set_mode(h, IPQ_COPY_PACKET, 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 *iph = ((struct iphdr *)m->payload);
 

  struct tcphdr *tcp = (struct tcphdr *)(m->payload + (iph->ihl << 2));    
 
  struct udphdr *udp = (struct udphdr *) (m->payload + (iph->ihl << 2));
 
  int unsigned payload_offset = ((iph->ihl << 2) + (tcp->doff << 2));

    int unsigned payload_length = (unsigned int) ntohs(iph->tot_len) - 
payload_offset;


status = ipq_set_verdict(h, m->packet_id,NF_ACCEPT, 0, NULL); 
    
  break;
     }
    }

              
       
    }
    while (1);
    
    printf("Engine Stopped...\n");
    
    ipq_destroy_handle(h);
    
}

int main() {
    start_packet_engine();
    return 0;
}