/* Bail out if "*(p)" was not captured */
#define ND_TCHECK_SIZE(p) ND_TCHECK_LEN(p, sizeof(*(p)))
+/*
+ * Number of bytes remaining in the captured data, starting at the
+ * byte pointed to by the argument.
+ */
+#define ND_BYTES_AVAILABLE_AFTER(p) ((u_int)(ndo->ndo_snapend - (p)))
+
#define ND_PRINT(...) (ndo->ndo_printf)(ndo, __VA_ARGS__)
#define ND_DEFAULTPRINT(ap, length) (*ndo->ndo_default_print)(ndo, ap, length)
extern const char *dnname_string(netdissect_options *, u_short);
extern const char *dnnum_string(netdissect_options *, u_short);
-extern int decode_prefix4(netdissect_options *, const u_char *, u_int, char *, u_int);
-extern int decode_prefix6(netdissect_options *, const u_char *, u_int, char *, u_int);
+extern int decode_prefix4(netdissect_options *, const u_char *, u_int, char *, size_t);
+extern int decode_prefix6(netdissect_options *, const u_char *, u_int, char *, size_t);
extern void esp_print_decodesecret(netdissect_options *);
extern int esp_print_decrypt_buffer_by_ikev2(netdissect_options *, int,
u_char s;
ndo->ndo_protocol = "ascii";
- caplength = (ndo->ndo_snapend > cp) ? ndo->ndo_snapend - cp : 0;
+ caplength = (ndo->ndo_snapend > cp) ? ND_BYTES_AVAILABLE_AFTER(cp) : 0;
if (length > caplength)
length = caplength;
ND_PRINT("\n");
char hexstuff[HEXDUMP_SHORTS_PER_LINE*HEXDUMP_HEXSTUFF_PER_SHORT+1], *hsp;
char asciistuff[ASCII_LINELENGTH+1], *asp;
- caplength = (ndo->ndo_snapend > cp) ? ndo->ndo_snapend - cp : 0;
+ caplength = (ndo->ndo_snapend > cp) ? ND_BYTES_AVAILABLE_AFTER(cp) : 0;
if (length > caplength)
length = caplength;
nshorts = length / sizeof(u_short);
u_int i, s;
u_int nshorts;
- caplength = (ndo->ndo_snapend > cp) ? ndo->ndo_snapend - cp : 0;
+ caplength = (ndo->ndo_snapend > cp) ? ND_BYTES_AVAILABLE_AFTER(cp) : 0;
if (length > caplength)
length = caplength;
nshorts = length / sizeof(u_short);
int
decode_prefix4(netdissect_options *ndo,
- const u_char *pptr, u_int itemlen, char *buf, u_int buflen)
+ const u_char *pptr, u_int itemlen, char *buf, size_t buflen)
{
struct in_addr addr;
u_int plen, plenbytes;
static int
decode_labeled_prefix4(netdissect_options *ndo,
- const u_char *pptr, u_int itemlen, char *buf, u_int buflen)
+ const u_char *pptr, u_int itemlen, char *buf,
+ size_t buflen)
{
struct in_addr addr;
u_int plen, plenbytes;
*/
static u_int
bgp_vpn_sg_print(netdissect_options *ndo,
- const u_char *pptr, char *buf, u_int buflen)
+ const u_char *pptr, char *buf, size_t buflen)
{
uint8_t addr_length;
u_int total_length, offset;
/* Source address */
ND_TCHECK_LEN(pptr, (addr_length >> 3));
total_length += (addr_length >> 3) + 1;
- offset = strlen(buf);
+ offset = (u_int)strlen(buf);
if (addr_length) {
nd_snprintf(buf + offset, buflen - offset, ", Source %s",
bgp_vpn_ip_print(ndo, pptr, addr_length));
/* Group address */
ND_TCHECK_LEN(pptr, (addr_length >> 3));
total_length += (addr_length >> 3) + 1;
- offset = strlen(buf);
+ offset = (u_int)strlen(buf);
if (addr_length) {
nd_snprintf(buf + offset, buflen - offset, ", Group %s",
bgp_vpn_ip_print(ndo, pptr, addr_length));
static int
decode_labeled_vpn_prefix4(netdissect_options *ndo,
- const u_char *pptr, char *buf, u_int buflen)
+ const u_char *pptr, char *buf, size_t buflen)
{
struct in_addr addr;
u_int plen;
static int
decode_mdt_vpn_nlri(netdissect_options *ndo,
- const u_char *pptr, char *buf, u_int buflen)
+ const u_char *pptr, char *buf, size_t buflen)
{
const u_char *rd;
const u_char *vpn_ip;
switch(route_type) {
case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI:
ND_TCHECK_LEN(pptr, BGP_VPN_RD_LEN);
- offset = strlen(buf);
+ offset = (u_int)strlen(buf);
nd_snprintf(buf + offset, buflen - offset, ", RD: %s, Originator %s",
bgp_vpn_rd_print(ndo, pptr),
bgp_vpn_ip_print(ndo, pptr + BGP_VPN_RD_LEN,
break;
case BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI:
ND_TCHECK_LEN(pptr, BGP_VPN_RD_LEN + 4);
- offset = strlen(buf);
+ offset = (u_int)strlen(buf);
nd_snprintf(buf + offset, buflen - offset, ", RD: %s, Source-AS %s",
bgp_vpn_rd_print(ndo, pptr),
as_printf(ndo, astostr, sizeof(astostr),
case BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI:
ND_TCHECK_LEN(pptr, BGP_VPN_RD_LEN);
- offset = strlen(buf);
+ offset = (u_int)strlen(buf);
nd_snprintf(buf + offset, buflen - offset, ", RD: %s",
bgp_vpn_rd_print(ndo, pptr));
pptr += BGP_VPN_RD_LEN;
addr_length = route_length - sg_length;
ND_TCHECK_LEN(pptr, addr_length);
- offset = strlen(buf);
+ offset = (u_int)strlen(buf);
nd_snprintf(buf + offset, buflen - offset, ", Originator %s",
bgp_vpn_ip_print(ndo, pptr, addr_length << 3));
break;
case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE:
ND_TCHECK_LEN(pptr, BGP_VPN_RD_LEN);
- offset = strlen(buf);
+ offset = (u_int)strlen(buf);
nd_snprintf(buf + offset, buflen - offset, ", RD: %s",
bgp_vpn_rd_print(ndo, pptr));
pptr += BGP_VPN_RD_LEN;
case BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN: /* fall through */
case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN:
ND_TCHECK_LEN(pptr, BGP_VPN_RD_LEN + 4);
- offset = strlen(buf);
+ offset = (u_int)strlen(buf);
nd_snprintf(buf + offset, buflen - offset, ", RD: %s, Source-AS %s",
bgp_vpn_rd_print(ndo, pptr),
as_printf(ndo, astostr, sizeof(astostr),
static int
decode_labeled_vpn_l2(netdissect_options *ndo,
- const u_char *pptr, char *buf, u_int buflen)
+ const u_char *pptr, char *buf, size_t buflen)
{
u_int plen, tlen, tlv_type, tlv_len, ttlv_len;
int stringlen;
int
decode_prefix6(netdissect_options *ndo,
- const u_char *pd, u_int itemlen, char *buf, u_int buflen)
+ const u_char *pd, u_int itemlen, char *buf, size_t buflen)
{
struct in6_addr addr;
u_int plen, plenbytes;
static int
decode_labeled_prefix6(netdissect_options *ndo,
- const u_char *pptr, u_int itemlen, char *buf, u_int buflen)
+ const u_char *pptr, u_int itemlen, char *buf, size_t buflen)
{
struct in6_addr addr;
u_int plen, plenbytes;
static int
decode_labeled_vpn_prefix6(netdissect_options *ndo,
- const u_char *pptr, char *buf, u_int buflen)
+ const u_char *pptr, char *buf, size_t buflen)
{
struct in6_addr addr;
u_int plen;
static int
decode_clnp_prefix(netdissect_options *ndo,
- const u_char *pptr, char *buf, u_int buflen)
+ const u_char *pptr, char *buf, size_t buflen)
{
uint8_t addr[19];
u_int plen;
static int
decode_labeled_vpn_clnp_prefix(netdissect_options *ndo,
- const u_char *pptr, char *buf, u_int buflen)
+ const u_char *pptr, char *buf, size_t buflen)
{
uint8_t addr[19];
u_int plen;
trunc:
nd_print_trunc(ndo);
- return ndo->ndo_snapend - bp;
+ return (ND_BYTES_AVAILABLE_AFTER(bp));
}
/*
if (ethertype_print(ndo, extracted_ethertype,
p+addr_len+ETHERTYPE_LEN,
length-addr_len-ETHERTYPE_LEN,
- ndo->ndo_snapend-p-addr_len-ETHERTYPE_LEN,
+ ND_BYTES_AVAILABLE_AFTER(p)-addr_len-ETHERTYPE_LEN,
NULL, NULL) == 0)
/* ether_type not known, probably it wasn't one */
ND_PRINT("UI %02x! ", GET_U_1(p + addr_len));
break;
case NLPID_SNAP:
- if (snap_print(ndo, p, length, ndo->ndo_snapend - p, NULL, NULL, 0) == 0) {
+ if (snap_print(ndo, p, length, ND_BYTES_AVAILABLE_AFTER(p), NULL, NULL, 0) == 0) {
/* ether_type not known, print raw packet */
if (!ndo->ndo_eflag)
fr_hdr_print(ndo, length + hdr_len, hdr_len,
else
ND_PRINT("\n\t");
- if (ethertype_print(ndo, prot, bp, len, ndo->ndo_snapend - bp, NULL, NULL) == 0) {
+ if (ethertype_print(ndo, prot, bp, len, ND_BYTES_AVAILABLE_AFTER(bp), NULL, NULL) == 0) {
if (prot == ETHERTYPE_TEB)
- ether_print(ndo, bp, len, ndo->ndo_snapend - bp, NULL, NULL);
+ ether_print(ndo, bp, len, ND_BYTES_AVAILABLE_AFTER(bp), NULL, NULL);
else
ND_PRINT("geneve-proto-0x%x", prot);
}
isoclns_print(ndo, bp, len);
break;
case ETHERTYPE_TEB:
- ether_print(ndo, bp, len, ndo->ndo_snapend - bp, NULL, NULL);
+ ether_print(ndo, bp, len, ND_BYTES_AVAILABLE_AFTER(bp), NULL, NULL);
break;
default:
ND_PRINT("gre-proto-0x%x", prot);
/* Check if packet isn't over yet */
if (packet_iterator + packet_offset < ndo->ndo_snapend) {
hex_print_with_offset(ndo, "\n Data: ", packet_iterator + packet_offset,
- (ndo->ndo_snapend - (packet_iterator + packet_offset)), 0);
+ ND_BYTES_AVAILABLE_AFTER(packet_iterator + packet_offset), 0);
}
}
return;
}
p++; /* skip terminating \0 */
- return p - p0;
+ return (int)(p - p0);
trunc:
return -1;
ND_PRINT("%02x", GET_U_1(p));
p++;
}
- return p - p0;
+ return (int)(p - p0);
trunc:
return -1;
* returned length, however, as it breaks out of the
* header-processing loop.
*/
- mhlen = ep - bp;
+ mhlen = (unsigned)(ep - bp);
goto trunc;
}
mhlen = (GET_U_1(mh->ip6m_len) + 1) << 3;
ip6_print(ndo, bp, next_len);
break;
case 0x3:
- ether_print(ndo, bp, next_len, ndo->ndo_snapend - bp, NULL, NULL);
+ ether_print(ndo, bp, next_len, ND_BYTES_AVAILABLE_AFTER(bp), NULL, NULL);
break;
default:
ND_PRINT("ERROR: unknown-next-protocol");
case OLSR_MID_MSG:
{
- size_t addr_size = sizeof(nd_ipv4);
+ u_int addr_size = (u_int)sizeof(nd_ipv4);
if (is_ipv6)
- addr_size = sizeof(nd_ipv6);
+ addr_size = (u_int)sizeof(nd_ipv6);
while (msg_tlen >= addr_size) {
ND_TCHECK_LEN(msg_data, addr_size);
ND_TCHECK_LEN(cp, len);
ndo->ndo_vflag -= 3;
ND_PRINT(", frame decoding below\n");
- ether_print(ndo, cp, len, ndo->ndo_snapend - cp, NULL, NULL);
+ ether_print(ndo, cp, len, ND_BYTES_AVAILABLE_AFTER(cp), NULL, NULL);
ndo->ndo_vflag += 3;
return cp + len;
ND_TCHECK_1(bp);
bp += 1;
- ether_print(ndo, bp, len - OTV_HDR_LEN, ndo->ndo_snapend - bp, NULL, NULL);
+ ether_print(ndo, bp, len - OTV_HDR_LEN, ND_BYTES_AVAILABLE_AFTER(bp), NULL, NULL);
return;
trunc:
ND_PRINT("%02x", GET_U_1(p));
p++;
}
- name_size = len - (p - p0);
+ name_size = len - (u_int)(p - p0);
ND_PRINT(", Name ");
for (i = 0; i < name_size; i++) {
ND_TCHECK_1(p);
break;
case CHAP_SUCC:
case CHAP_FAIL:
- msg_size = len - (p - p0);
+ msg_size = len - (u_int)(p - p0);
ND_PRINT(", Msg ");
for (i = 0; i< msg_size; i++) {
ND_TCHECK_1(p);
*/
se = ndo->ndo_snapend;
ndo->ndo_snapend = t;
- length = t - b;
+ length = ND_BYTES_AVAILABLE_AFTER(b);
/* now lets guess about the payload codepoint format */
if (length < 1)
nd_print_trunc(ndo);
return;
}
- len = ndo->ndo_snapend - dat;
+ len = ND_BYTES_AVAILABLE_AFTER(dat);
if (len > length)
len = length;
if (len < sizeof(*rp)) {
}
done:
- return sp - osp;
+ return (int)(sp - osp);
trunc:
nd_print_trunc(ndo);
if (ndo->ndo_Xflag && 2 < ndo->ndo_vflag) {
if (first)
ND_PRINT("\nTelnet:");
- hex_print_with_offset(ndo, "\n", sp, l, sp - osp);
+ hex_print_with_offset(ndo, "\n", sp, l, (u_int)(sp - osp));
if (l > 8)
ND_PRINT("\n\t\t\t\t");
else
ip6_print(ndo, bp, len - VXLAN_GPE_HDR_LEN);
break;
case 0x3:
- ether_print(ndo, bp, len - VXLAN_GPE_HDR_LEN, ndo->ndo_snapend - bp, NULL, NULL);
+ ether_print(ndo, bp, len - VXLAN_GPE_HDR_LEN, ND_BYTES_AVAILABLE_AFTER(bp), NULL, NULL);
break;
case 0x4:
nsh_print(ndo, bp, len - VXLAN_GPE_HDR_LEN);
ND_PRINT("flags [%s] (0x%02x), ", flags & 0x08 ? "I" : ".", flags);
ND_PRINT("vni %u\n", vni);
- ether_print(ndo, bp, len - VXLAN_HDR_LEN, ndo->ndo_snapend - bp, NULL, NULL);
+ ether_print(ndo, bp, len - VXLAN_HDR_LEN, ND_BYTES_AVAILABLE_AFTER(bp), NULL, NULL);
return;