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
|
const struct etherhdr* etherhdr;
const struct ip* iphdr;
const struct tcphdr* tcphdr;
int etherhdr_size = sizeof(struct etherhdr);
int iphdr_size = sizeof(struct ip);
int tcphdr_size = sizeof(struct tcphdr);
etherhdr = (struct etherhdr *) packet;
iphdr = (struct ip *) (packet + etherhdr_size);
tcphdr = (struct tcphdr *) (packet + etherhdr_size + iphdr_size);
if (tcphdr->doff > 5) {
const u_char* tcpOptions = packet + etherhdr_size + iphdr_size + 20;
char kind[4];
sprintf(kind, "%3d", *tcpOptions);
int optType = atoi(kind);
while (optType != 0) {
if (optType != 2) {
switch (optType) {
case 1 : tcpOptions++; break;
// Autres options à gérer pour être complet
}
}
else {
tcpOptions += 2;
char mss_hexa[5];
sprintf(mss_hexa, "%2x%2x", *tcpOptions, *(tcpOptions + 1));
int mss = hex2Dec(mss_hexa);
break;
}
sprintf(kind, "%3d", *tcpOptions);
optType = atoi(kind);
}
} |