probleme de case avec un u_short
Bonjour,
Je suis entrain de creer un Analyseur de Paquets sous linux avec libpcap.
lorsque je recupère mon paquet, je le met deja sous forme d'une structure representant ma trame ethernet :
Code:
1 2 3 4 5 6
|
struct sniff_ethernet {
u_char ether_dhost[ETHER_ADDR_LEN]; /* destination host address */
u_char ether_shost[ETHER_ADDR_LEN]; /* source host address */
u_short ether_type; /* IP? ARP? RARP? etc */
}; |
Ensuite j'affiche comme ça :
Code:
1 2 3 4 5 6 7 8
| void affich_ether(struct sniff_ethernet* ethernet){
int i;
printf("\nEther : =================== Ethernet Datalink Layer =================\n");
[...]
printf("\n\tTYPE: 0x%x\n",ntohs(ethernet->ether_type))
resolve_ether_type(ethernet->ether_type);
} |
le probleme se situe au niveau de la fonction resolve_ether_type en fait cette fonction à comme argument
Code:
u_short ether_type;
et doit , en fonction du type afficher si c'est du DoD IP ARP RARP etc...
voici la fonction :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
void resolve_ether_type(u_short ether_type){
printf("resolve :");
switch(ether_type){
case 800:
printf("DoD IP\n");
break;
default: printf("Unknown\n");
break;
}
} |
en fait le probleme c'est que ça affiche toujours Unknown ... il entre jamai dans mon case 800 surmt pck je le compare a un int et que c'est un u_short...
il ya t'il une solution ?? (autre que de faire plein de if ... then ... else a la suite ;))
Re: probleme de case avec un u_short
Citation:
Envoyé par [thebadskull
]
Code:
1 2 3 4 5
| void affich_ether(struct sniff_ethernet* ethernet){
int i;
printf("\n\tTYPE: 0x%x\n",ntohs(ethernet->ether_type))
resolve_ether_type(ethernet->ether_type);
} |
La valeur réseau doit être convertie en host avec ntohs().
Code:
1 2 3 4
|
unsigned short ether_type = ntohs(ethernet->ether_type);
printf("\n\tTYPE: 0x%x\n",ether_type)
resolve_ether_type(ether_type); |