/* \summary: DECnet printer */
#ifdef HAVE_CONFIG_H
-#include "config.h"
+#include <config.h>
#endif
#include "netdissect-stdinc.h"
#include <stdlib.h>
#include <string.h>
-struct mbuf;
-struct rtentry;
-
#ifdef HAVE_DNET_HTOA
#ifdef HAVE_NETDNET_DN_H
#include <netdnet/dn.h>
#include "extract.h"
#include "addrtoname.h"
-static const char tstr[] = "[|decnet]";
#ifndef _WIN32
typedef nd_uint8_t byte; /* single byte field */
/* Forwards */
static int print_decnet_ctlmsg(netdissect_options *, const union routehdr *, u_int, u_int);
static void print_t_info(netdissect_options *, u_int);
-static int print_l1_routes(netdissect_options *, const char *, u_int);
-static int print_l2_routes(netdissect_options *, const char *, u_int);
+static int print_l1_routes(netdissect_options *, const u_char *, u_int);
+static int print_l2_routes(netdissect_options *, const u_char *, u_int);
static void print_i_info(netdissect_options *, u_int);
-static int print_elist(const char *, u_int);
+static int print_elist(const u_char *, u_int);
static int print_nsp(netdissect_options *, const u_char *, u_int);
static void print_reason(netdissect_options *, u_int);
u_int nsplen, pktlen;
const u_char *nspp;
+ ndo->ndo_protocol = "decnet";
if (length < sizeof(struct shorthdr)) {
- ND_PRINT("%s", tstr);
+ nd_print_trunc(ndo);
return;
}
ND_TCHECK_LEN(ap, sizeof(short));
pktlen = EXTRACT_LE_U_2(ap);
if (pktlen < sizeof(struct shorthdr)) {
- ND_PRINT("%s", tstr);
+ nd_print_trunc(ndo);
return;
}
if (pktlen > length) {
- ND_PRINT("%s", tstr);
+ nd_print_trunc(ndo);
return;
}
length = pktlen;
rhp = (const union routehdr *)(ap + sizeof(short));
- ND_TCHECK(rhp->rh_short.sh_flags);
+ ND_TCHECK_1(rhp->rh_short.sh_flags);
mflags = EXTRACT_U_1(rhp->rh_short.sh_flags);
if (mflags & RMF_PAD) {
if (ndo->ndo_vflag)
ND_PRINT("[pad:%u] ", padlen);
if (length < padlen + 2) {
- ND_PRINT("%s", tstr);
+ nd_print_trunc(ndo);
return;
}
ND_TCHECK_LEN(ap + sizeof(short), padlen);
length -= padlen;
caplen -= padlen;
rhp = (const union routehdr *)(ap + sizeof(short));
- ND_TCHECK(rhp->rh_short.sh_flags);
+ ND_TCHECK_1(rhp->rh_short.sh_flags);
mflags = EXTRACT_U_1(rhp->rh_short.sh_flags);
}
switch (mflags & RMF_MASK) {
case RMF_LONG:
if (length < sizeof(struct longhdr)) {
- ND_PRINT("%s", tstr);
+ nd_print_trunc(ndo);
return;
}
- ND_TCHECK(rhp->rh_long);
+ ND_TCHECK_SIZE(&rhp->rh_long);
dst =
EXTRACT_LE_U_2(rhp->rh_long.lg_dst.dne_remote.dne_nodeaddr);
src =
nsplen = length - sizeof(struct longhdr);
break;
case RMF_SHORT:
- ND_TCHECK(rhp->rh_short);
+ ND_TCHECK_SIZE(&rhp->rh_short);
dst = EXTRACT_LE_U_2(rhp->rh_short.sh_dst);
src = EXTRACT_LE_U_2(rhp->rh_short.sh_src);
hops = (EXTRACT_U_1(rhp->rh_short.sh_visits) & VIS_MASK)+1;
return;
trunc:
- ND_PRINT("%s", tstr);
+ nd_print_trunc(ndo);
return;
}
u_int mflags = EXTRACT_U_1(rhp->rh_short.sh_flags);
const union controlmsg *cmp = (const union controlmsg *)rhp;
u_int src, dst, info, blksize, eco, ueco, hello, other, vers;
- etheraddr srcea, rtea;
u_int priority;
- const char *rhpx = (const char *)rhp;
+ const u_char *rhpx = (const u_char *)rhp;
int ret;
switch (mflags & RMF_CTLMASK) {
ND_PRINT("init ");
if (length < sizeof(struct initmsg))
goto trunc;
- ND_TCHECK(cmp->cm_init);
+ ND_TCHECK_SIZE(&cmp->cm_init);
src = EXTRACT_LE_U_2(cmp->cm_init.in_src);
info = EXTRACT_U_1(cmp->cm_init.in_info);
blksize = EXTRACT_LE_U_2(cmp->cm_init.in_blksize);
ND_PRINT("verification ");
if (length < sizeof(struct verifmsg))
goto trunc;
- ND_TCHECK(cmp->cm_ver);
+ ND_TCHECK_SIZE(&cmp->cm_ver);
src = EXTRACT_LE_U_2(cmp->cm_ver.ve_src);
other = EXTRACT_U_1(cmp->cm_ver.ve_fcnval);
ND_PRINT("src %s fcnval %o", dnaddr_string(ndo, src), other);
ND_PRINT("test ");
if (length < sizeof(struct testmsg))
goto trunc;
- ND_TCHECK(cmp->cm_test);
+ ND_TCHECK_SIZE(&cmp->cm_test);
src = EXTRACT_LE_U_2(cmp->cm_test.te_src);
other = EXTRACT_U_1(cmp->cm_test.te_data);
ND_PRINT("src %s data %o", dnaddr_string(ndo, src), other);
ND_PRINT("lev-1-routing ");
if (length < sizeof(struct l1rout))
goto trunc;
- ND_TCHECK(cmp->cm_l1rou);
+ ND_TCHECK_SIZE(&cmp->cm_l1rou);
src = EXTRACT_LE_U_2(cmp->cm_l1rou.r1_src);
ND_PRINT("src %s ", dnaddr_string(ndo, src));
ret = print_l1_routes(ndo, &(rhpx[sizeof(struct l1rout)]),
ND_PRINT("lev-2-routing ");
if (length < sizeof(struct l2rout))
goto trunc;
- ND_TCHECK(cmp->cm_l2rout);
+ ND_TCHECK_SIZE(&cmp->cm_l2rout);
src = EXTRACT_LE_U_2(cmp->cm_l2rout.r2_src);
ND_PRINT("src %s ", dnaddr_string(ndo, src));
ret = print_l2_routes(ndo, &(rhpx[sizeof(struct l2rout)]),
ND_PRINT("router-hello ");
if (length < sizeof(struct rhellomsg))
goto trunc;
- ND_TCHECK(cmp->cm_rhello);
+ ND_TCHECK_SIZE(&cmp->cm_rhello);
vers = EXTRACT_U_1(cmp->cm_rhello.rh_vers);
eco = EXTRACT_U_1(cmp->cm_rhello.rh_eco);
ueco = EXTRACT_U_1(cmp->cm_rhello.rh_ueco);
- memcpy((char *)&srcea, (const char *)&(cmp->cm_rhello.rh_src),
- sizeof(srcea));
- src = EXTRACT_LE_U_2(srcea.dne_remote.dne_nodeaddr);
+ src =
+ EXTRACT_LE_U_2(cmp->cm_rhello.rh_src.dne_remote.dne_nodeaddr);
info = EXTRACT_U_1(cmp->cm_rhello.rh_info);
blksize = EXTRACT_LE_U_2(cmp->cm_rhello.rh_blksize);
priority = EXTRACT_U_1(cmp->cm_rhello.rh_priority);
ND_PRINT("endnode-hello ");
if (length < sizeof(struct ehellomsg))
goto trunc;
- ND_TCHECK(cmp->cm_ehello);
+ ND_TCHECK_SIZE(&cmp->cm_ehello);
vers = EXTRACT_U_1(cmp->cm_ehello.eh_vers);
eco = EXTRACT_U_1(cmp->cm_ehello.eh_eco);
ueco = EXTRACT_U_1(cmp->cm_ehello.eh_ueco);
- memcpy((char *)&srcea, (const char *)&(cmp->cm_ehello.eh_src),
- sizeof(srcea));
- src = EXTRACT_LE_U_2(srcea.dne_remote.dne_nodeaddr);
+ src =
+ EXTRACT_LE_U_2(cmp->cm_ehello.eh_src.dne_remote.dne_nodeaddr);
info = EXTRACT_U_1(cmp->cm_ehello.eh_info);
blksize = EXTRACT_LE_U_2(cmp->cm_ehello.eh_blksize);
/*seed*/
- memcpy((char *)&rtea, (const char *)&(cmp->cm_ehello.eh_router),
- sizeof(rtea));
- dst = EXTRACT_LE_U_2(rtea.dne_remote.dne_nodeaddr);
+ dst =
+ EXTRACT_LE_U_2(cmp->cm_ehello.eh_router.dne_remote.dne_nodeaddr);
hello = EXTRACT_LE_U_2(cmp->cm_ehello.eh_hello);
other = EXTRACT_U_1(cmp->cm_ehello.eh_data);
print_i_info(ndo, info);
static int
print_l1_routes(netdissect_options *ndo,
- const char *rp, u_int len)
+ const u_char *rp, u_int len)
{
u_int count;
u_int id;
static int
print_l2_routes(netdissect_options *ndo,
- const char *rp, u_int len)
+ const u_char *rp, u_int len)
{
u_int count;
u_int area;
}
static int
-print_elist(const char *elp _U_, u_int len _U_)
+print_elist(const u_char *elp _U_, u_int len _U_)
{
/* Not enough examples available for me to debug this */
return (1);
if (nsplen < data_off)
goto trunc;
- ND_TCHECK(shp->sh_seq[0]);
+ ND_TCHECK_2(shp->sh_seq[0]);
ack = EXTRACT_LE_U_2(shp->sh_seq[0]);
if (ack & SGQ_ACK) { /* acknum field */
if ((ack & SGQ_NAK) == SGQ_NAK)
data_off += sizeof(short);
if (nsplen < data_off)
goto trunc;
- ND_TCHECK(shp->sh_seq[1]);
+ ND_TCHECK_2(shp->sh_seq[1]);
ack = EXTRACT_LE_U_2(shp->sh_seq[1]);
if (ack & SGQ_OACK) { /* ackoth field */
if ((ack & SGQ_ONAK) == SGQ_ONAK)
data_off += sizeof(short);
if (nsplen < data_off)
goto trunc;
- ND_TCHECK(shp->sh_seq[2]);
+ ND_TCHECK_2(shp->sh_seq[2]);
ack = EXTRACT_LE_U_2(shp->sh_seq[2]);
}
}
if (nsplen < data_off)
goto trunc;
- ND_TCHECK(shp->sh_seq[0]);
+ ND_TCHECK_2(shp->sh_seq[0]);
ack = EXTRACT_LE_U_2(shp->sh_seq[0]);
if (ack & SGQ_ACK) { /* acknum field */
if ((ack & SGQ_NAK) == SGQ_NAK)
data_off += sizeof(short);
if (nsplen < data_off)
goto trunc;
- ND_TCHECK(shp->sh_seq[1]);
+ ND_TCHECK_2(shp->sh_seq[1]);
ack = EXTRACT_LE_U_2(shp->sh_seq[1]);
if (ack & SGQ_OACK) { /* ackdat field */
if ((ack & SGQ_ONAK) == SGQ_ONAK)
data_off += sizeof(short);
if (nsplen < data_off)
goto trunc;
- ND_TCHECK(shp->sh_seq[2]);
+ ND_TCHECK_2(shp->sh_seq[2]);
ack = EXTRACT_LE_U_2(shp->sh_seq[2]);
}
}
if (nsplen < sizeof(struct seghdr) + sizeof(struct lsmsg))
goto trunc;
- ND_TCHECK(shp->sh_seq[0]);
+ ND_TCHECK_2(shp->sh_seq[0]);
ack = EXTRACT_LE_U_2(shp->sh_seq[0]);
if (ack & SGQ_ACK) { /* acknum field */
if ((ack & SGQ_NAK) == SGQ_NAK)
ND_PRINT("nak %u ", ack & SGQ_MASK);
else
ND_PRINT("ack %u ", ack & SGQ_MASK);
- ND_TCHECK(shp->sh_seq[1]);
+ ND_TCHECK_2(shp->sh_seq[1]);
ack = EXTRACT_LE_U_2(shp->sh_seq[1]);
if (ack & SGQ_OACK) { /* ackdat field */
if ((ack & SGQ_ONAK) == SGQ_ONAK)
ND_PRINT("nakdat %u ", ack & SGQ_MASK);
else
ND_PRINT("ackdat %u ", ack & SGQ_MASK);
- ND_TCHECK(shp->sh_seq[2]);
+ ND_TCHECK_2(shp->sh_seq[2]);
ack = EXTRACT_LE_U_2(shp->sh_seq[2]);
}
}
ND_PRINT("nak %u ", ack & SGQ_MASK);
else
ND_PRINT("ack %u ", ack & SGQ_MASK);
- ND_TCHECK(amp->ak_acknum[1]);
+ ND_TCHECK_2(amp->ak_acknum[1]);
ack = EXTRACT_LE_U_2(amp->ak_acknum[1]);
if (ack & SGQ_OACK) { /* ackdat field */
if ((ack & SGQ_ONAK) == SGQ_ONAK)
u_int area = (u_short)(dnaddr & AREAMASK) >> AREASHIFT;
u_int node = dnaddr & NODEMASK;
+ /* malloc() return used by the 'dnaddrtable' hash table: do not free() */
str = (char *)malloc(siz = sizeof("00.0000"));
if (str == NULL)
- (*ndo->ndo_error)(ndo, "dnnum_string: malloc");
- snprintf(str, siz, "%u.%u", area, node);
+ (*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC, "dnnum_string: malloc");
+ nd_snprintf(str, siz, "%u.%u", area, node);
return(str);
}