int packet_ok(buf, cc, from, seq) u_char *buf; int cc; struct sockaddr_in *from; int seq; { register struct icmp *icp; u_char type, code; int hlen; #ifndef ARCHAIC struct ip *ip;
ip = (struct ip *) buf; hlen = ip->ip_hl << 2; if (cc < hlen + ICMP_MINLEN) { if (verbose) Printf("packet too short (%d bytes) from %s\n", cc, inet_ntoa(from->sin_addr)); return (0); } cc -= hlen; icp = (struct icmp *)(buf + hlen); #else icp = (struct icmp *)buf; #endif /* ARCHAIC */ type = icp->icmp_type; code = icp->icmp_code; if ((type == ICMP_TIMXCEED && code == ICMP_TIMXCEED_INTRANS) || type == ICMP_UNREACH) { struct ip *hip; struct udphdr *up;
hip = &icp->icmp_ip; hlen = hip->ip_hl << 2; up = (struct udphdr *)((u_char *)hip + hlen); if (hlen + 12 <= cc && hip->ip_p == IPPROTO_UDP && up->uh_sport == htons(ident) && up->uh_dport == htons(port+seq)) return (type == ICMP_TIMXCEED? -1 : code+1); }
... } 在上面的代码中,if (hlen + 12 <= cc && hip->ip_p == IPPROTO_UDP && up->uh_sport == htons(ident) && up->uh_dport == htons(port+seq)), if语句中 hlen + 12 <= cc, 为什么 是加 12?是不是这12Byte中有8Byte的ICMP首部,剩下的 4Byte是UDP首部? 请高手指教!谢谢先!