/* \summary: IP printer */
#ifdef HAVE_CONFIG_H
-#include "config.h"
+#include <config.h>
#endif
-#include <netdissect-stdinc.h>
+#include "netdissect-stdinc.h"
#include <string.h>
ip_finddst(netdissect_options *ndo,
const struct ip *ip)
{
- int length;
- int len;
+ u_int length;
+ u_int len;
const u_char *cp;
cp = (const u_char *)(ip + 1);
- length = (IP_HL(ip) << 2) - sizeof(struct ip);
+ length = (IP_HL(ip) << 2);
+ if (length < sizeof(struct ip))
+ goto trunc;
+ length -= sizeof(struct ip);
- for (; length > 0; cp += len, length -= len) {
+ for (; length != 0; cp += len, length -= len) {
int tt;
ND_TCHECK_1(cp);
if (len < 2)
break;
}
+ if (length < len)
+ goto trunc;
ND_TCHECK_LEN(cp, len);
switch (tt) {
{
u_int ptr;
u_int len;
- int hoplen;
+ u_int hoplen;
const char *type;
if (length < 4) {
ND_PRINT("PRESPEC");
break;
default:
- ND_PRINT("[bad ts type %d]", EXTRACT_U_1(cp + 3)&0xF);
+ ND_PRINT("[bad ts type %u]", EXTRACT_U_1(cp + 3)&0xF);
goto done;
}
if (ptr == len)
type = " ^ ";
ND_TCHECK_LEN(cp + len, hoplen);
- ND_PRINT("%s%d@%s", type, EXTRACT_BE_U_4(cp + len + hoplen - 4),
+ ND_PRINT("%s%u@%s", type, EXTRACT_BE_U_4(cp + len + hoplen - 4),
hoplen!=8 ? "" : ipaddr_string(ndo, cp + len));
type = " ";
}
ND_PRINT("%s", ptr == len ? " ^ " : "");
if (EXTRACT_U_1(cp + 3) >> 4)
- ND_PRINT(" [%d hops not recorded]} ", EXTRACT_U_1(cp + 3)>>4);
+ ND_PRINT(" [%u hops not recorded]} ", EXTRACT_U_1(cp + 3)>>4);
else
ND_PRINT("}");
return (0);
break;
case IPPROTO_ND:
- ND_PRINT(" nd %d", ipds->len);
+ ND_PRINT(" nd %u", ipds->len);
break;
case IPPROTO_EGP:
if (ndo->ndo_nflag==0 && (p_name = netdb_protoname(ipds->nh)) != NULL)
ND_PRINT(" %s", p_name);
else
- ND_PRINT(" ip-proto-%d", ipds->nh);
- ND_PRINT(" %d", ipds->len);
+ ND_PRINT(" ip-proto-%u", ipds->nh);
+ ND_PRINT(" %u", ipds->len);
break;
}
}
ipN_print(netdissect_options *ndo, const u_char *bp, u_int length)
{
if (length < 1) {
- ND_PRINT("truncated-ip %d", length);
+ ND_PRINT("truncated-ip %u", length);
return;
}