Esempio n. 1
0
int AnalyzePacket(u_char *data,int size)
{
u_char	*ptr;
int	lest;
struct ether_header	*eh;

	ptr=data;
	lest=size;

	if(lest<sizeof(struct ether_header)){
		fprintf(stderr,"lest(%d)<sizeof(struct ether_header)\n",lest);
		return(-1);
	}
	eh=(struct ether_header *)ptr;
	ptr+=sizeof(struct ether_header);
	lest-=sizeof(struct ether_header);

	if(ntohs(eh->ether_type)==ETHERTYPE_ARP){
		fprintf(stderr,"Packet[%dbytes]\n",size);
		PrintEtherHeader(eh,stdout);
		AnalyzeArp(ptr,lest);
	}
	else if(ntohs(eh->ether_type)==ETHERTYPE_IP){
		fprintf(stderr,"Packet[%dbytes]\n",size);
		PrintEtherHeader(eh,stdout);
		AnalyzeIp(ptr,lest);
	}
	else if(ntohs(eh->ether_type)==ETHERTYPE_IPV6){
		fprintf(stderr,"Packet[%dbytes]\n",size);
		PrintEtherHeader(eh,stdout);
		AnalyzeIpv6(ptr,lest);
	}

	return(0);
}
Esempio n. 2
0
int AnalyzePacket(u_char *data, int size) {
  u_char *ptr = NULL;
  int lest = 0;
  struct ether_header *eh = NULL;

  /*

  struct ether_header
  {
    u_int8_t  ether_dhost[ETH_ALEN];   // destination eth addr
    u_int8_t  ether_shost[ETH_ALEN];   // source ether addr
    u_int16_t ether_type;              // packet type ID field
  } __attribute__ ((__packed__));

  */

  ptr = data;
  lest = size;

  if (lest < sizeof(struct ether_header)) {
    ExitWithTooLittleLengthError("ether_header", lest);
  }

  eh = (struct ether_header *) ptr;
  ptr += sizeof(struct ether_header);
  lest -= sizeof(struct ether_header);

  if (ntohs(eh->ether_type) == ETHERTYPE_ARP) {
    fprintf(stderr, "Packet[%dbytes]\n", size);
    PrintEtherHeader(eh, stdout);
    AnalyzeArp(ptr, lest);
  }
  else if (ntohs(eh->ether_type) == ETHERTYPE_IP) {
    fprintf(stderr, "Packet[%dbytes]\n", size);
    PrintEtherHeader(eh, stdout);
    AnalyzeIp(ptr, lest);
  }
  else if (ntohs(eh->ether_type) == ETHERTYPE_IPV6) {
    fprintf(stderr, "Packet[%dbytes]\n", size);
    PrintEtherHeader(eh, stderr);
    AnalyzeIpv6(ptr, lest);
  }

  return 0;
}