📄 _atalk.c
字号:
/* there shouldn't be any control flags */
if (ap->control & (atpXO | atpEOM | atpSTS))
{
c = '[';
if (ap->control & atpXO)
{
PRINTF ("%cXO", c);
c = ',';
}
if (ap->control & atpEOM)
{
PRINTF ("%cEOM", c);
c = ',';
}
if (ap->control & atpSTS)
{
PRINTF ("%cSTS", c);
c = ',';
}
PUTCHAR (']');
}
break;
default:
PRINTF (" atp-0x%x %d (%d)", ap->control,
EXTRACT_16BITS (&ap->transID), length);
break;
}
data = EXTRACT_32BITS (&ap->userData);
if (data)
PRINTF (" 0x%lx", data);
}
static void atp_bitmap_print (u_char bm)
{
char c;
int i;
/*
* The '& 0xff' below is needed for compilers that want to sign
* extend a u_char, which is the case with the Ultrix compiler.
* (gcc is smart enough to eliminate it, at least on the Sparc).
*/
if ((bm + 1) & (bm & 0xff))
{
c = '<';
for (i = 0; bm; ++i)
{
if (bm & 1)
{
PRINTF ("%c%d", c, i);
c = ',';
}
bm >>= 1;
}
PUTCHAR ('>');
}
else
{
for (i = 0; bm; ++i)
bm >>= 1;
if (i > 1)
PRINTF ("<0-%d>", i - 1);
else PUTS ("<0>");
}
}
static void nbp_print (const struct atNBP *np, u_int length, u_short snet,
u_char snode, u_char skt)
{
const struct atNBPtuple *tp = (struct atNBPtuple*) ((u_char*)np + nbpHeaderSize);
const u_char *ep;
int i;
length -= nbpHeaderSize;
if (length < 8)
{
/* must be room for at least one tuple */
PRINTF (" truncated-nbp %d", length + nbpHeaderSize);
return;
}
/* ep points to end of available data */
ep = snapend;
if ((const u_char *) tp > ep)
{
PUTS (tstr);
return;
}
switch (i = np->control & 0xf0)
{
case nbpBrRq:
case nbpLkUp:
PRINTF (i == nbpLkUp ? " nbp-lkup %d:" : " nbp-brRq %d:", np->id);
if ((const u_char *) (tp + 1) > ep)
{
PUTS (tstr);
return;
}
nbp_name_print (tp, ep);
/*
* look for anomalies: the spec says there can only
* be one tuple, the address must match the source
* address and the enumerator should be zero.
*/
if ((np->control & 0xf) != 1)
PRINTF (" [ntup=%d]", np->control & 0xf);
if (tp->enumerator)
PRINTF (" [enum=%d]", tp->enumerator);
if (EXTRACT_16BITS (&tp->net) != snet ||
tp->node != snode || tp->skt != skt)
PRINTF (" [addr=%s.%d]",
ataddr_string(EXTRACT_16BITS(&tp->net),tp->node),tp->skt);
break;
case nbpLkUpReply:
PRINTF (" nbp-reply %d:", np->id);
/* print each of the tuples in the reply */
for (i = np->control & 0xf; --i >= 0 && tp;)
tp = nbp_tuple_print (tp, ep, snet, snode, skt);
break;
default:
PRINTF (" nbp-0x%x %d (%d)", np->control, np->id, length);
break;
}
}
/*
* print a counted string
*/
static const char * print_cstring (const char *cp, const u_char * ep)
{
u_int length;
if (cp >= (const char *) ep)
{
PUTS (tstr);
return (0);
}
length = *cp++;
/* Spec says string can be at most 32 bytes long */
if (length > 32)
{
PRINTF ("[len=%u]", length);
return (0);
}
while ((int)--length >= 0)
{
if (cp >= (char *) ep)
{
PUTS (tstr);
return (0);
}
PUTCHAR (*cp++);
}
return (cp);
}
static const struct atNBPtuple * nbp_tuple_print (
const struct atNBPtuple *tp, const u_char * ep,
u_short snet, u_char snode, u_char skt)
{
const struct atNBPtuple *tpn;
if ((const u_char *) (tp + 1) > ep)
{
PUTS (tstr);
return 0;
}
tpn = nbp_name_print (tp, ep);
/* if the enumerator isn't 1, print it */
if (tp->enumerator != 1)
PRINTF ("(%d)", tp->enumerator);
/* if the socket doesn't match the src socket, print it */
if (tp->skt != skt)
PRINTF (" %d", tp->skt);
/* if the address doesn't match the src address, it's an anomaly */
if (EXTRACT_16BITS (&tp->net) != snet || tp->node != snode)
PRINTF (" [addr=%s]",
ataddr_string(EXTRACT_16BITS(&tp->net),tp->node));
return (tpn);
}
static const struct atNBPtuple *nbp_name_print (
const struct atNBPtuple *tp, const u_char * ep)
{
const char *cp = (const char *) tp + nbpTupleSize;
PUTCHAR (' ');
/* Object */
PUTCHAR ('"');
cp = print_cstring (cp, ep);
if (cp)
{
/* Type */
PUTCHAR (':');
cp = print_cstring (cp, ep);
if (cp)
{
/* Zone */
PUTCHAR ('@');
cp = print_cstring (cp, ep);
if (cp)
PUTCHAR ('"');
}
}
return ((const struct atNBPtuple*) cp);
}
#define HASHNAMESIZE 4096
static struct hnamemem hnametable[HASHNAMESIZE];
static const char *ataddr_string (u_short atnet, u_char athost)
{
struct hnamemem *tp, *tp2;
int i = (atnet << 8) | athost;
char nambuf[256];
static int first = 1;
FILE *fp;
/*
* if this is the first call, see if there's an AppleTalk
* number to name map file.
*/
if (first && (first = 0, !nflag) &&
((fp = fopen(atalk_file, "rt"))) != NULL)
{
char line[256];
int i1, i2, i3;
while (fgets(line,sizeof(line),fp))
{
if (line[0] == '\n' || line[0] == 0 || line[0] == '#')
continue;
if (sscanf(line,"%d.%d.%d %s", &i1, &i2, &i3, nambuf) == 4)
{
/* got a hostname. */
i3 |= ((i1 << 8) | i2) << 8;
}
else if (sscanf (line, "%d.%d %s", &i1, &i2, nambuf) == 3)
{
/* got a net name */
i3 = (((i1 << 8) | i2) << 8) | 255;
}
else
continue;
for (tp = &hnametable[i3 & (HASHNAMESIZE - 1)]; tp->nxt; tp = tp->nxt)
;
tp->addr = i3;
tp->nxt = newhnamemem();
tp->name = savestr (nambuf);
}
fclose (fp);
}
for (tp = &hnametable[i & (HASHNAMESIZE - 1)]; tp->nxt; tp = tp->nxt)
if (tp->addr == i)
return (tp->name);
/* didn't have the node name -- see if we've got the net name */
i |= 255;
for (tp2 = &hnametable[i & (HASHNAMESIZE - 1)]; tp2->nxt; tp2 = tp2->nxt)
if (tp2->addr == i)
{
tp->addr = (atnet << 8) | athost;
tp->nxt = newhnamemem ();
sprintf (nambuf, "%s.%d", tp2->name, athost);
tp->name = savestr (nambuf);
return (tp->name);
}
tp->addr = (atnet << 8) | athost;
tp->nxt = newhnamemem ();
if (athost != 255)
sprintf (nambuf, "%d.%d.%d", atnet >> 8, atnet & 0xff, athost);
else sprintf (nambuf, "%d.%d", atnet >> 8, atnet & 0xff);
tp->name = savestr (nambuf);
return (tp->name);
}
static struct tok skt2str[] = {
{ rtmpSkt, "rtmp" }, /* routing table maintenance */
{ nbpSkt, "nis" }, /* name info socket */
{ echoSkt, "echo" }, /* AppleTalk echo protocol */
{ zipSkt, "zip" }, /* zone info protocol */
{ 0, NULL}
};
static const char *ddpskt_string (int skt)
{
static char buf[8];
if (nflag)
{
sprintf (buf, "%d", skt);
return (buf);
}
return tok2str (skt2str, "%d", skt);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -