|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Senior Member
Iscritto dal: Mar 2009
Messaggi: 753
|
[- C linux - Header TCP - Options field]
Ciao a tutti,
sono alle prese con un problema di questo tipo: il mio programma deve eseguire una stampa dell'intestazione TCP compreso il campo opzioni. Questo campo non è definito nella struttura tcphdr in netinet/tcp.h, quindi devo accedervi manualmente (a meno che io ignori l'esistenza di un'altro modo). Lo faccio definendo le varie strutture, posto il codice in modo che sia chiaro: Codice:
typedef struct timestp { // Timestamp structure
u_char code;
u_char length;
u_int32_t tsval;
u_int32_t tsecr;
};
typedef struct wscale { // Window scale structure
u_char code;
u_char length;
u_char scalefactor;
};
typedef struct mms { // MMS structure
u_char code;
u_char length;
u_int16_t value;
};
(data punta dove inizia il campo relativo, su questo non dovrei sbagliarmi) Codice:
//questa è la main che chiama le altre seguenti:
void
Print_TCPOptions(const u_char* data, int options_length)
{
u_char* options;
int i;
strncat(options,data,options_length);
printf("\t%d bytes options found:\n",options_length);
for(i=1;i<options_length;i++)
{
switch(options[i])
{
case 0x1: printf("\t- NOP\n");break;
case 0x2: printf("\t- MMS:\n");mms_viewer(&options[i]);i=i+3;break;
case 0x3: printf("\t- Window scale:\n");wscale_viewer(&options[i]);i=i+2;break;
case 0x4: printf("\t- Sack permitted\n");i++;break;
case 0x8: printf("\t- Timestamp:\n");Timestamp_viewer(&options[i]);i=i+9;break;
default: printf("\t%x",options[i]); break;
}
printf(" ");
}
printf("\n");
}
void
Timestamp_viewer(const u_char* data)
{
struct timestp* ts = (struct timestamp *)data;
printf("\t\tLength: %d\n\t",ts->length);
printf("\tTS Value: %u\n\t",htons(ts->tsval));
printf("\tTS Echo Reply: %u\n",htons(ts->tsecr));
}
void
wscale_viewer(const u_char* data)
{
struct wscale* ws = (struct wscale *)data;
printf("\t\tLength: %d\n\t",ws->length);
printf("\tScale factor: %d\n",htons(ws->scalefactor));
}
void
mms_viewer(const u_char* data)
{
struct mms* _mms = (struct mms *)data;
printf("\t\tLength: %d\n\t",_mms->length);
printf("\tValue: %d\n",htons(_mms->value));
}
24 bytes options found: - NOP - NOP - Timestamp: Length: 10 TS Value: 22829 TS Echo Reply: 46848 0 0 0 c0 3f 0 0 2c 0 0 0 come vedete i primi campi di NOP sono corretti! come la lunghezza dell'opzione timestamp, perchè il mio programma fallisce il riconoscimento del window scale?? (che dovrebbe seguire dopo timestamp in questo pacchetto), inoltre i valori TS di timestamp non credo siano corretti.... qualcuno è in grado di darmi un consiglio? Grazie mille! |
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 19:25.



















