void handle_ether(const u_char * pkt, int len, void *userdata) { struct ether_header *e = (struct ether_header *)pkt; unsigned short etype; if (len < ETHER_HDR_LEN) return; etype = nptohs(&e->ether_type); if (callback_ether) if (0 != callback_ether(pkt, len, userdata)) return; pkt += ETHER_HDR_LEN; len -= ETHER_HDR_LEN; if (ETHERTYPE_8021Q == etype) { unsigned short vlan = nptohs((unsigned short *) pkt); if (callback_vlan) if (0 != callback_vlan(vlan, userdata)) return; etype = nptohs((unsigned short *)(pkt + 2)); pkt += 4; len -= 4; } if (len < 0) return; /* fprintf(stderr, "Ethernet packet of len %d ethertype %#04x\n", len, etype); */ if (is_ethertype_ip(etype)) { handle_ip((struct ip *)pkt, len, userdata); } }
void handle_ppp(const u_char * pkt, int len, void *userdata) { char buf[PCAP_SNAPLEN]; unsigned short proto; if (len < 2) return NULL; if (*pkt == PPP_ADDRESS_VAL && *(pkt + 1) == PPP_CONTROL_VAL) { pkt += 2; /* ACFC not used */ len -= 2; } if (len < 2) return NULL; if (*pkt % 2) { proto = *pkt; /* PFC is used */ pkt++; len--; } else { proto = nptohs(pkt); pkt += 2; len -= 2; } if (is_ethertype_ip(proto)) handle_ip((struct ip *)pkt, len, userdata); }
dns_message * handle_ether(const u_char * pkt, int len) { char buf[PCAP_SNAPLEN]; struct ether_header *e = (void *) pkt; unsigned short etype = ntohs(e->ether_type); if (len < ETHER_HDR_LEN) return NULL; pkt += ETHER_HDR_LEN; len -= ETHER_HDR_LEN; if (ETHERTYPE_8021Q == etype) { if (!match_vlan(pkt)) return NULL; etype = ntohs(*(unsigned short *) (pkt + 2)); pkt += 4; len -= 4; } if (len < 0) return NULL; if (is_ethertype_ip(etype)) { memcpy(buf, pkt, len); return handle_ip((struct ip *) buf, len); } return NULL; }
dns_message * handle_ppp(const u_char * pkt, int len) { char buf[PCAP_SNAPLEN]; unsigned short us; unsigned short proto; if (len < 2) return NULL; if (*pkt == PPP_ADDRESS_VAL && *(pkt + 1) == PPP_CONTROL_VAL) { pkt += 2; /* ACFC not used */ len -= 2; } if (len < 2) return NULL; if (*pkt % 2) { proto = *pkt; /* PFC is used */ pkt++; len--; } else { memcpy(&us, pkt, sizeof(us)); proto = ntohs(us); pkt += 2; len -= 2; } if (is_ethertype_ip(proto)) { memcpy(buf, pkt, len); return handle_ip((struct ip *) buf, len); } return NULL; }
void handle_gre(const u_char * gre, int len, void *userdata) { int grelen = 4; unsigned short flags = nptohs(gre); unsigned short etype = nptohs(gre + 2); if (len < grelen) return; if (callback_gre) callback_gre(gre, len, userdata); if (flags & 0x0001) /* checksum present? */ grelen += 4; if (flags & 0x0004) /* key present? */ grelen += 4; if (flags & 0x0008) /* sequence number present? */ grelen += 4; if (is_ethertype_ip(etype)) handle_ip((struct ip *) (gre + grelen), len - grelen, userdata); }