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
| //Standard//
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
//Réseau//
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
int main()
{
// Déscripteur de la Socket : //
int sock = socket(AF_INET, SOCK_RAW, IPPROTO_TCP);
struct sockaddr_in adresse;
adresse.sin_family = AF_INET;
adresse.sin_port = htons(80);
adresse.sin_addr.s_addr = inet_addr("178.32.94.206");
char * packet;
packet = malloc(sizeof(struct ip) + sizeof(struct tcphdr));
// En-tête TCP //
struct tcphdr tcph;
tcph.source = 30000; // Port source //
tcph.dest = 80; // Port destination //
tcph.seq = 2500; // Numéro de séquence //
tcph.syn = 1; // Flag SYN 1 = armé , 0 = désarmé //
tcph.ack_seq = 0;
tcph.th_win = htons(32767);
// En-tête IP //
struct ip iph;
iph.ip_hl = 4;
iph.ip_v = 4;
iph.ip_tos = 0;
iph.ip_len = sizeof(struct ip) + sizeof(struct tcphdr);
iph.ip_ttl = 60; // Time to live : nombre de routage maximum //
iph.ip_p = IPPROTO_TCP; // Protocole de transport //
iph.ip_src.s_addr = inet_addr("192.168.42.252"); // IP source //
iph.ip_dst.s_addr = inet_addr("178.32.94.206"); // IP Destination //
// Envoi du paquet //
int one = 1;
const int *val = &one;
setsockopt(sock, IPPROTO_IP, IP_HDRINCL, val, sizeof(one));
sendto(sock, packet, sizeof(packet), 0, (struct sockaddr *) &adresse, sizeof(adresse));
return 0;
} |
Partager