Bonjour à tous

Voila je vous explique mon problème: j'utilise libnetfilter_queue pour capturer des paquet dans des queues(sans blague), j'en extrait ensuite le payload grâce a la fonction nfq_get_payload() (un truc du genre).
celui ci contient struct iphdr + une struct udphdr + la data (pour moi une chaine de caractére) jusque la c'est bon...
ensuite je change l'adresse ip de destination (elle est vers 192.6.1.237 quand je la reçois et je la change en 192.6.1.236) je change également le destport dans l'entête udp MAIS... il le port ne se change pas... il reste a la valeur qu'il était lorceque j'ai reçu le paquet, je ne comprend pas pourquoi rien n'y fait...

voilà la fonction qui est appellé par la fonction callback:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
static void build_copy_pkt (unsigned char *data)
{
    int one = 1;
    const int *val = &one;
 
    int numbytes;
    int sockfd, optval;
    unsigned char *cpy_data = data;
 
    struct iphdr *ip_hdr;
    struct udphdr *udp_hdr;
    ip_hdr=(struct iphdr *)cpy_data;
//tcp_hdr=(struct tcphdr *)(cpy_data + (sizeof(struct iphdr)));
    if(ip_hdr->protocol == IPPROTO_UDP)
    {
        udp_hdr = ((struct udphdr *)cpy_data) + (sizeof (struct iphdr));
 
    }
    struct sockaddr_in dconn;
    char test[16], test2[16];
 
    udp_hdr->dest = htons(51064);
    inet_pton(AF_INET, "192.6.1.236", &ip_hdr->daddr);
 
    printf("Création du socket\n");
    sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_UDP);
    if(sockfd <0)
    {
        printf("erreur durant la création du socket");
    }
 
    dconn.sin_port  = htons(51064);
    dconn.sin_family = AF_INET;
    dconn.sin_addr.s_addr = ip_hdr->daddr;
 
    printf("protocol : %d\n", ip_hdr->protocol);
    printf("ttl: %d\n", ip_hdr->ttl);
    inet_ntop(AF_INET, &(ip_hdr->saddr), test, sizeof(test));
    printf("source : %s\n", test);
    inet_ntop(AF_INET, &(ip_hdr->daddr), test2, sizeof(test2));
    printf("destination : %s\n", test2);
 
 
    ip_hdr->tot_len= sizeof(struct iphdr)+ sizeof(struct udphdr) +10;
    printf("tot len : %d\n", ip_hdr->tot_len);
 
    printf("ip_len: %d\n", sizeof(ip_hdr));
    printf("payload : %d \n", sizeof(cpy_data));
    printf("payload value: %s\n", cpy_data);
 
 
    printf("dport : %d\n\n", ntohs(udp_hdr->dest));
    udp_hdr->source = htons(2102);
    printf("sport : %d\n\n", ntohs(udp_hdr->source));
    udp_hdr->len = sizeof(struct udphdr) + 11;//+ sizeof(ip_hdr));
 
 
    if (setsockopt (sockfd, IPPROTO_IP, IP_HDRINCL, val, sizeof (one)) < 0)
    {
        printf ("Warning: Cannot set HDRINCL!\n");
    }
 
    numbytes=sendto(sockfd, cpy_data,ip_hdr->tot_len, 0,(struct sockaddr *)&dconn, sizeof(struct sockaddr));
    if(numbytes <0)
    {
        printf("erreur durant l'envoi \n");
        exit(1);
    }
    printf("pkt sent : %d", numbytes);
 
 
}

merci de votre aide