- printf(" (");
- if (ip->ip_ttl > 1) {
- (void)printf("%sttl %d", sep, (int)ip->ip_ttl);
- sep = ", ";
- }
- if ((off & 0x3fff) == 0) {
- (void)printf("%sid %d", sep, (int)ntohs(ip->ip_id));
- sep = ", ";
- }
- (void)printf("%slen %d", sep, (int)ntohs(ip->ip_len));
- sep = ", ";
- if ((u_char *)ip + hlen <= snapend) {
- sum = in_cksum((const u_short *)ip, hlen, 0);
- if (sum != 0) {
- (void)printf("%sbad cksum %x (->%x)!", sep,
- ntohs(ip->ip_sum),
- ntohs(ip->ip_sum)-sum);
- sep = ", ";
- }
+ /*
+ * Cut off the snapshot length to the end of the IP payload.
+ */
+ ipend = bp + ipds->len;
+ if (ipend < snapend)
+ snapend = ipend;
+
+ ipds->len -= hlen;
+
+ ipds->off = EXTRACT_16BITS(&ipds->ip->ip_off);
+
+ if (vflag) {
+ (void)printf("(tos 0x%x", (int)ipds->ip->ip_tos);
+ /* ECN bits */
+ if (ipds->ip->ip_tos & 0x03) {
+ switch (ipds->ip->ip_tos & 0x03) {
+ case 1:
+ (void)printf(",ECT(1)");
+ break;
+ case 2:
+ (void)printf(",ECT(0)");
+ break;
+ case 3:
+ (void)printf(",CE");
+ }
+ }
+
+ if (ipds->ip->ip_ttl >= 1)
+ (void)printf(", ttl %u", ipds->ip->ip_ttl);
+
+ /*
+ * for the firewall guys, print id, offset.
+ * On all but the last stick a "+" in the flags portion.
+ * For unfragmented datagrams, note the don't fragment flag.
+ */
+
+ (void)printf(", id %u, offset %u, flags [%s], proto %s (%u)",
+ EXTRACT_16BITS(&ipds->ip->ip_id),
+ (ipds->off & 0x1fff) * 8,
+ bittok2str(ip_frag_values, "none", ipds->off&0xe000),
+ tok2str(ipproto_values,"unknown",ipds->ip->ip_p),
+ ipds->ip->ip_p);
+
+ (void)printf(", length %u", EXTRACT_16BITS(&ipds->ip->ip_len));
+
+ if ((hlen - sizeof(struct ip)) > 0) {
+ printf(", options (");
+ ip_optprint((u_char *)(ipds->ip + 1), hlen - sizeof(struct ip));
+ printf(")");
+ }
+
+ if (!Kflag && (u_char *)ipds->ip + hlen <= snapend) {
+ sum = in_cksum((const u_short *)ipds->ip, hlen, 0);
+ if (sum != 0) {
+ ip_sum = EXTRACT_16BITS(&ipds->ip->ip_sum);
+ (void)printf(", bad cksum %x (->%x)!", ip_sum,
+ in_cksum_shouldbe(ip_sum, sum));