📄 _ospf.c
字号:
PRINTF (" rtr rtrid %s",
ipaddr_string (&mcp->mcla_vid));
break;
case MCLA_VERTEX_NETWORK:
PRINTF (" net dr %s",
ipaddr_string (&mcp->mcla_vid));
break;
default:
PRINTF (" ??VertexType %u??",
(u_int) ntohl (mcp->mcla_vtype));
break;
}
}
}
PUTS (" }");
return (0);
}
void ospf_print (const u_char *bp, u_int length, const u_char *bp2)
{
const struct ospfhdr *op;
const struct ip *ip;
const struct lsa *lsap;
const struct lsa_hdr *lshp;
const struct in_addr *ap;
const struct lsr *lsrp;
const caddr_t end = (caddr_t) snapend;
char sep;
int i, j;
op = (struct ospfhdr *) bp;
ip = (struct ip *) bp2;
/* Print the source and destination address */
PRINTF ("%s > %s:",
ipaddr_string (&ip->ip_src),
ipaddr_string (&ip->ip_dst));
if ((caddr_t) (&op->ospf_len + 1) > end)
goto trunc_test;
/* If the type is valid translate it, or just print the type */
/* value. If it's not valid, say so and return */
if (op->ospf_type || op->ospf_type < OSPF_TYPE_MAX)
{
PRINTF (" OSPFv%d-%s %d:",
op->ospf_version, ospf_types[op->ospf_type], length);
}
else
{
PRINTF (" ospf-v%d-??type %d?? %d:",
op->ospf_version, op->ospf_type, length);
return;
}
if (length != ntohs (op->ospf_len))
{
PRINTF (" ??len %d??", ntohs (op->ospf_len));
goto trunc_test;
}
if ((caddr_t) (&op->ospf_routerid + 1) > end)
goto trunc_test;
/* Print the routerid if it is not the same as the source */
if (ip->ip_src.s_addr != op->ospf_routerid.s_addr)
PRINTF (" rtrid %s", ipaddr_string (&op->ospf_routerid));
if ((caddr_t) (&op->ospf_areaid + 1) > end)
goto trunc_test;
if (op->ospf_areaid.s_addr)
PRINTF (" area %s", ipaddr_string (&op->ospf_areaid));
else PUTS (" backbone");
if ((caddr_t) (op->ospf_authdata + OSPF_AUTH_SIZE) > end)
goto trunc_test;
if (vflag)
{
/* Print authentication data (should we really do this?) */
switch (ntohs (op->ospf_authtype))
{
case OSPF_AUTH_NONE:
break;
case OSPF_AUTH_SIMPLE:
PUTS (" auth ");
j = 0;
for (i = 0; i < sizeof(op->ospf_authdata); i++)
{
if (!isprint (op->ospf_authdata[i]))
{
j = 1;
break;
}
}
if (j)
{
/* Print the auth-data as a string of octets */
PRINTF ("%s.%s",
ipaddr_string ((struct in_addr *) op->ospf_authdata),
ipaddr_string ((struct in_addr *) &op->ospf_authdata[sizeof(struct in_addr)]));
}
else
{
/* Print the auth-data as a text string */
PRINTF ("'%.8s'", op->ospf_authdata);
}
break;
default:
PRINTF (" ??authtype-%d??", ntohs (op->ospf_authtype));
return;
}
}
/* Do rest according to version. */
switch (op->ospf_version)
{
case 2:
/* ospf version 2 */
switch (op->ospf_type)
{
case OSPF_TYPE_UMD: /* Rob Coltun's special monitoring packets; do nothing */
break;
case OSPF_TYPE_HELLO:
if ((caddr_t) (&op->ospf_hello.hello_deadint + 1) > end)
break;
if (vflag)
{
ospf_print_bits (ospf_option_bits,
op->ospf_hello.hello_options);
PRINTF (" mask %s int %d pri %d dead %u",
ipaddr_string (&op->ospf_hello.hello_mask),
ntohs (op->ospf_hello.hello_helloint),
op->ospf_hello.hello_priority,
(u_int) ntohl (op->ospf_hello.hello_deadint));
}
if ((caddr_t)(&op->ospf_hello.hello_dr + 1) > end)
break;
if (op->ospf_hello.hello_dr.s_addr)
PRINTF (" dr %s", ipaddr_string (&op->ospf_hello.hello_dr));
if ((caddr_t) (&op->ospf_hello.hello_bdr + 1) > end)
break;
if (op->ospf_hello.hello_bdr.s_addr)
PRINTF (" bdr %s", ipaddr_string (&op->ospf_hello.hello_bdr));
if (vflag)
{
if ((caddr_t) (op->ospf_hello.hello_neighbor + 1) > end)
break;
PUTS (" nbrs");
for (ap = op->ospf_hello.hello_neighbor;
(caddr_t) (ap + 1) <= end; ap++)
{
PUTCHAR (' ');
PUTS (ipaddr_string (ap));
}
}
break; /* HELLO */
case OSPF_TYPE_DB:
if ((caddr_t) (&op->ospf_db.db_seq + 1) > end)
break;
ospf_print_bits (ospf_option_bits, op->ospf_db.db_options);
sep = ' ';
if (op->ospf_db.db_flags & OSPF_DB_INIT)
{
PRINTF ("%cI", sep);
sep = '/';
}
if (op->ospf_db.db_flags & OSPF_DB_MORE)
{
PRINTF ("%cM", sep);
sep = '/';
}
if (op->ospf_db.db_flags & OSPF_DB_MASTER)
{
PRINTF ("%cMS", sep);
sep = '/';
}
PRINTF (" S %X", (u_int)ntohl (op->ospf_db.db_seq));
if (vflag)
{
/* Print all the LS adv's */
lshp = op->ospf_db.db_lshdr;
while (!ospf_print_lshdr (lshp, end))
{
PUTS (" }");
lshp++;
}
}
break;
case OSPF_TYPE_LSR:
if (vflag)
{
for (lsrp = op->ospf_lsr; (caddr_t)(lsrp + 1) <= end; lsrp++)
{
long type;
if ((caddr_t) (lsrp + 1) > end)
break;
PUTS (" {");
if ((type = ntohl (lsrp->ls_type)) != 0 || type >= LS_TYPE_MAX)
{
PRINTF (" ??LinkStateType %ld } }", type);
break;
}
LS_PRINT (lsrp, type);
PUTS (" }");
}
}
break;
case OSPF_TYPE_LSU:
if (vflag)
{
lsap = op->ospf_lsu.lsu_lsa;
i = ntohl (op->ospf_lsu.lsu_count);
while (i-- &&
!ospf_print_lsa (lsap, end))
lsap = (struct lsa*) ((caddr_t)lsap +
ntohs(lsap->ls_hdr.ls_length));
}
break;
case OSPF_TYPE_LSA:
if (vflag)
{
lshp = op->ospf_lsa.lsa_lshdr;
while (!ospf_print_lshdr (lshp, end))
{
PUTS (" }");
lshp++;
}
break;
}
}
break;
default:
PRINTF (" ospf [version %d]", op->ospf_version);
break;
}
trunc_test:
if (snapend - bp < length)
PUTS (" [|]");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -