#include "extract.h"
#include "appletalk.h"
-static const char tstr[] = "[|atalk]";
static const struct tok type2str[] = {
{ ddpRTMP, "rtmp" },
{
u_int hdrlen;
+ ndo->ndo_protocol = "ltalk_if";
hdrlen = llap_print(ndo, p, h->len);
if (hdrlen == 0) {
/* Cut short by the snapshot length. */
u_short snet;
u_int hdrlen;
+ ndo->ndo_protocol = "llap";
if (length < sizeof(*lp)) {
ND_PRINT(" [|llap %u]", length);
return (length);
}
if (!ND_TTEST_LEN(bp, sizeof(*lp))) {
- ND_PRINT(" [|llap]");
+ nd_print_trunc(ndo);
return (0); /* cut short by the snapshot length */
}
lp = (const struct LAP *)bp;
const struct atDDP *dp;
u_short snet;
+ ndo->ndo_protocol = "atalk";
if(!ndo->ndo_eflag)
ND_PRINT("AT ");
#define AT(member) ataddr_string(ndo, (ap->member[1]<<8)|ap->member[2],ap->member[3])
+ ndo->ndo_protocol = "aarp";
ND_PRINT("aarp ");
ap = (const struct aarp *)bp;
if (!ND_TTEST_SIZE(ap)) {
/* Just bail if we don't have the whole chunk. */
- ND_PRINT(" [|aarp]");
+ nd_print_trunc(ndo);
return;
}
if (length < sizeof(*ap)) {
if ((const u_char *)(ap + 1) > ndo->ndo_snapend) {
/* Just bail if we don't have the whole chunk. */
- ND_PRINT("%s", tstr);
+ nd_print_trunc(ndo);
return;
}
if (length < sizeof(*ap)) {
/* ep points to end of available data */
ep = ndo->ndo_snapend;
if ((const u_char *)tp > ep) {
- ND_PRINT("%s", tstr);
+ nd_print_trunc(ndo);
return;
}
control = EXTRACT_U_1(np->control);
case nbpLkUp:
ND_PRINT(i == nbpLkUp? " nbp-lkup %u:":" nbp-brRq %u:", EXTRACT_U_1(np->id));
if ((const u_char *)(tp + 1) > ep) {
- ND_PRINT("%s", tstr);
+ nd_print_trunc(ndo);
return;
}
(void)nbp_name_print(ndo, tp, ep);
}
/* print a counted string */
-static const char *
+static const u_char *
print_cstring(netdissect_options *ndo,
- const char *cp, const u_char *ep)
+ const u_char *cp, const u_char *ep)
{
u_int length;
- if (cp >= (const char *)ep) {
- ND_PRINT("%s", tstr);
+ if (cp >= ep) {
+ nd_print_trunc(ndo);
return (0);
}
length = EXTRACT_U_1(cp);
return (0);
}
while (length != 0) {
- if (cp >= (const char *)ep) {
- ND_PRINT("%s", tstr);
+ if (cp >= ep) {
+ nd_print_trunc(ndo);
return (0);
}
- ND_PRINT("%c", EXTRACT_U_1(cp));
+ fn_print_char(ndo, EXTRACT_U_1(cp));
cp++;
length--;
}
const struct atNBPtuple *tpn;
if ((const u_char *)(tp + 1) > ep) {
- ND_PRINT("%s", tstr);
+ nd_print_trunc(ndo);
return 0;
}
tpn = nbp_name_print(ndo, tp, ep);
nbp_name_print(netdissect_options *ndo,
const struct atNBPtuple *tp, const u_char *ep)
{
- const char *cp = (const char *)tp + nbpTupleSize;
+ const u_char *cp = (const u_char *)tp + nbpTupleSize;
ND_PRINT(" ");
FILE *fp;
/*
- * if this is the first call, see if there's an AppleTalk
- * number to name map file.
+ * Are we doing address to name resolution?
*/
- if (first && (first = 0, !ndo->ndo_nflag)
- && (fp = fopen("/etc/atalk.names", "r"))) {
- char line[256];
- u_int i1, i2;
-
- while (fgets(line, sizeof(line), fp)) {
- if (line[0] == '\n' || line[0] == 0 || line[0] == '#')
- continue;
- if (sscanf(line, "%u.%u %256s", &i1, &i2, nambuf) == 3)
- /* got a hostname. */
- i2 |= (i1 << 8);
- else if (sscanf(line, "%u %256s", &i1, nambuf) == 2)
- /* got a net name */
- i2 = (i1 << 8) | 255;
- else
- continue;
-
- for (tp = &hnametable[i2 & (HASHNAMESIZE-1)];
- tp->nxt; tp = tp->nxt)
- ;
- tp->addr = i2;
- tp->nxt = newhnamemem(ndo);
- tp->name = strdup(nambuf);
- if (tp->name == NULL)
- (*ndo->ndo_error)(ndo,
- "ataddr_string: strdup(nambuf)");
+ if (!ndo->ndo_nflag) {
+ /*
+ * Yes. Have we tried to open and read an AppleTalk
+ * number to name map file?
+ */
+ if (!first) {
+ /*
+ * No; try to do so.
+ */
+ first = 0;
+ fp = fopen("/etc/atalk.names", "r");
+ if (fp != NULL) {
+ char line[256];
+ u_int i1, i2;
+
+ while (fgets(line, sizeof(line), fp)) {
+ if (line[0] == '\n' || line[0] == 0 ||
+ line[0] == '#')
+ continue;
+ if (sscanf(line, "%u.%u %256s", &i1,
+ &i2, nambuf) == 3)
+ /* got a hostname. */
+ i2 |= (i1 << 8);
+ else if (sscanf(line, "%u %256s", &i1,
+ nambuf) == 2)
+ /* got a net name */
+ i2 = (i1 << 8) | 255;
+ else
+ continue;
+
+ for (tp = &hnametable[i2 & (HASHNAMESIZE-1)];
+ tp->nxt; tp = tp->nxt)
+ ;
+ tp->addr = i2;
+ tp->nxt = newhnamemem(ndo);
+ tp->name = strdup(nambuf);
+ if (tp->name == NULL)
+ (*ndo->ndo_error)(ndo,
+ S_ERR_ND_MEM_ALLOC,
+ "ataddr_string: strdup(nambuf)");
+ }
+ fclose(fp);
+ }
}
- fclose(fp);
}
+ /*
+ * Now try to look up the address in the table.
+ */
for (tp = &hnametable[i & (HASHNAMESIZE-1)]; tp->nxt; tp = tp->nxt)
if (tp->addr == i)
return (tp->name);
if (tp2->addr == i) {
tp->addr = (atnet << 8) | athost;
tp->nxt = newhnamemem(ndo);
- (void)snprintf(nambuf, sizeof(nambuf), "%s.%u",
+ (void)nd_snprintf(nambuf, sizeof(nambuf), "%s.%u",
tp2->name, athost);
tp->name = strdup(nambuf);
if (tp->name == NULL)
- (*ndo->ndo_error)(ndo,
- "ataddr_string: strdup(nambuf)");
+ (*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
+ "ataddr_string: strdup(nambuf)");
return (tp->name);
}
tp->addr = (atnet << 8) | athost;
tp->nxt = newhnamemem(ndo);
if (athost != 255)
- (void)snprintf(nambuf, sizeof(nambuf), "%u.%u", atnet, athost);
+ (void)nd_snprintf(nambuf, sizeof(nambuf), "%u.%u", atnet, athost);
else
- (void)snprintf(nambuf, sizeof(nambuf), "%u", atnet);
+ (void)nd_snprintf(nambuf, sizeof(nambuf), "%u", atnet);
tp->name = strdup(nambuf);
if (tp->name == NULL)
- (*ndo->ndo_error)(ndo, "ataddr_string: strdup(nambuf)");
+ (*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
+ "ataddr_string: strdup(nambuf)");
return (tp->name);
}
static char buf[8];
if (ndo->ndo_nflag) {
- (void)snprintf(buf, sizeof(buf), "%u", skt);
+ (void)nd_snprintf(buf, sizeof(buf), "%u", skt);
return (buf);
}
return (tok2str(skt2str, "%u", skt));