]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-ah.c
Bring in KAME IPv6 tcpdump. replaces esp/ah/isakmp decoder.
[tcpdump] / print-ah.c
index b4fae2eb338f152a47cf811d10a08c5646a3c98c..525e32a0fc8ae387c79452062518b72280acb382 100644 (file)
@@ -31,70 +31,69 @@ static char rcsid[] =
 #include <sys/types.h>
 #include <sys/socket.h>
 
+#include <net/route.h>
+#include <net/if.h>
+
 #include <netinet/in.h>
+#include <netinet/if_ether.h>
 #include <netinet/in_systm.h>
 #include <netinet/ip.h>
+#include <netinet/ip_icmp.h>
 #include <netinet/ip_var.h>
 #include <netinet/udp.h>
 #include <netinet/udp_var.h>
+#include <netinet/tcp.h>
 
-#undef NOERROR                                 /* Solaris sucks */
-#include <arpa/nameser.h>
-#include <arpa/tftp.h>
-
-#ifdef SOLARIS
-#include <tiuser.h>
-#endif
-#include <rpc/rpc.h>
-
-#include <errno.h>
 #include <stdio.h>
 
+/* there's no standard definition so we are on our own */
+struct ah {
+       u_int8_t        ah_nxt;         /* Next Header */
+       u_int8_t        ah_len;         /* Length of data, in 32bit */
+       u_int16_t       ah_reserve;     /* Reserved for future use */
+       u_int32_t       ah_spi;         /* Security parameter index */
+       /* variable size, 32bit bound*/ /* Authentication data */
+};
+
+struct newah {
+       u_int8_t        ah_nxt;         /* Next Header */
+       u_int8_t        ah_len;         /* Length of data + 1, in 32bit */
+       u_int16_t       ah_reserve;     /* Reserved for future use */
+       u_int32_t       ah_spi;         /* Security parameter index */
+       u_int32_t       ah_seq;         /* Sequence number field */
+       /* variable size, 32bit bound*/ /* Authentication data */
+};
+
 #include "interface.h"
 #include "addrtoname.h"
 
-extern int packettype;
-
-
-void
-ah_print(register const u_char *bp, int length, register const u_char *bp2)
+int
+ah_print(register const u_char *bp, register const u_char *bp2)
 {
-  register const struct ip *ip;
-  register const u_char *cp, *nh;
-  u_short nextheader;
-  u_short ahlen, authlen;
-  u_long  spi, seqno;
-
-  ip = (struct ip *)bp2;
-
-  (void)printf("AH %s > %s\n\t\t",
-              ipaddr_string(&ip->ip_src),
-              ipaddr_string(&ip->ip_dst));
-
-  if (length < 8) {
-    (void)printf(" [|ah] truncated-ah %d", length);
-    return;
-  }
-
-  nextheader = bp[0];
-  ahlen      = bp[1];
-  spi        = ntohl(*((u_long *)(bp+4)));
-  seqno      = ntohl(*((u_long *)(bp+8)));
-  authlen    = ahlen - 12;
-
-  nh         = bp+ahlen;
-
-  if(authlen > length || authlen == 0)
-    {
-      authlen = length;
-    }
-
-  (void)printf("spi:%08x seqno:%d authlen: %d authdata: ", spi,
-              seqno, authlen);
-  (void)default_print_unaligned(bp+12, authlen);
-
-  /* PRINT rest of packet, requires some reorg of print-ip.c */
-#if XXX  
-  (void)ip_print(nextheader, ip, nh, length-authlen);
-#endif
+       register const struct ah *ah;
+       register const u_char *ep;
+       int sumlen;
+       u_int32_t spi;
+
+       ah = (struct ah *)bp;
+       ep = snapend;           /* 'ep' points to the end of avaible data. */
+
+       if ((u_char *)(ah + 1) >= ep - sizeof(struct ah))
+               goto trunc;
+
+       sumlen = ah->ah_len << 2;
+       spi = (u_int32_t)ntohl(ah->ah_spi);
+
+       printf("AH(spi=%u", spi);
+       if (vflag)
+               printf(",sumlen=%d", sumlen);
+       printf(",seq=0x%x", (u_int32_t)ntohl(*(u_int32_t *)(ah + 1)));
+       if (bp + sizeof(struct ah) + sumlen > ep)
+               fputs("[truncated]", stdout);
+       fputs("): ", stdout);
+       
+       return sizeof(struct ah) + sumlen;
+ trunc:
+       fputs("[|AH]", stdout);
+       return 65535;
 }