本文整理汇总了C++中EXTRACT_16BITS函数的典型用法代码示例。如果您正苦于以下问题:C++ EXTRACT_16BITS函数的具体用法?C++ EXTRACT_16BITS怎么用?C++ EXTRACT_16BITS使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了EXTRACT_16BITS函数的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: chdlc_print
u_int
chdlc_print(netdissect_options *ndo, register const u_char *p, u_int length)
{
u_int proto;
const u_char *bp = p;
if (length < CHDLC_HDRLEN)
goto trunc;
ND_TCHECK2(*p, CHDLC_HDRLEN);
proto = EXTRACT_16BITS(&p[2]);
if (ndo->ndo_eflag) {
ND_PRINT((ndo, "%s, ethertype %s (0x%04x), length %u: ",
tok2str(chdlc_cast_values, "0x%02x", p[0]),
tok2str(ethertype_values, "Unknown", proto),
proto,
length));
}
length -= CHDLC_HDRLEN;
p += CHDLC_HDRLEN;
switch (proto) {
case ETHERTYPE_IP:
ip_print(ndo, p, length);
break;
case ETHERTYPE_IPV6:
ip6_print(ndo, p, length);
break;
case CHDLC_TYPE_SLARP:
chdlc_slarp_print(ndo, p, length);
break;
#if 0
case CHDLC_TYPE_CDP:
chdlc_cdp_print(p, length);
break;
#endif
case ETHERTYPE_MPLS:
case ETHERTYPE_MPLS_MULTI:
mpls_print(ndo, p, length);
break;
case ETHERTYPE_ISO:
/* is the fudge byte set ? lets verify by spotting ISO headers */
if (length < 2)
goto trunc;
ND_TCHECK_16BITS(p);
if (*(p+1) == 0x81 ||
*(p+1) == 0x82 ||
*(p+1) == 0x83)
isoclns_print(ndo, p + 1, length - 1);
else
isoclns_print(ndo, p, length);
break;
default:
if (!ndo->ndo_eflag)
ND_PRINT((ndo, "unknown CHDLC protocol (0x%04x)", proto));
break;
}
return (CHDLC_HDRLEN);
trunc:
ND_PRINT((ndo, "[|chdlc]"));
return ndo->ndo_snapend - bp;
}
开发者ID:RTEMS,项目名称:rtems-libbsd,代码行数:64,代码来源:print-chdlc.c
示例2: dccp_print_option
static int dccp_print_option(netdissect_options *ndo, const u_char *option, u_int hlen)
{
uint8_t optlen, i;
ND_TCHECK(*option);
if (*option >= 32) {
ND_TCHECK(*(option+1));
optlen = *(option +1);
if (optlen < 2) {
if (*option >= 128)
ND_PRINT((ndo, "CCID option %u optlen too short", *option));
else
ND_PRINT((ndo, "%s optlen too short",
tok2str(dccp_option_values, "Option %u", *option)));
return 0;
}
} else
optlen = 1;
if (hlen < optlen) {
if (*option >= 128)
ND_PRINT((ndo, "CCID option %u optlen goes past header length",
*option));
else
ND_PRINT((ndo, "%s optlen goes past header length",
tok2str(dccp_option_values, "Option %u", *option)));
return 0;
}
ND_TCHECK2(*option, optlen);
if (*option >= 128) {
ND_PRINT((ndo, "CCID option %d", *option));
switch (optlen) {
case 4:
ND_PRINT((ndo, " %u", EXTRACT_16BITS(option + 2)));
break;
case 6:
ND_PRINT((ndo, " %u", EXTRACT_32BITS(option + 2)));
break;
default:
break;
}
} else {
ND_PRINT((ndo, "%s", tok2str(dccp_option_values, "Option %u", *option)));
switch (*option) {
case 32:
case 33:
case 34:
case 35:
if (optlen < 3) {
ND_PRINT((ndo, " optlen too short"));
return optlen;
}
if (*(option + 2) < 10){
ND_PRINT((ndo, " %s", dccp_feature_nums[*(option + 2)]));
for (i = 0; i < optlen - 3; i++)
ND_PRINT((ndo, " %d", *(option + 3 + i)));
}
break;
case 36:
if (optlen > 2) {
ND_PRINT((ndo, " 0x"));
for (i = 0; i < optlen - 2; i++)
ND_PRINT((ndo, "%02x", *(option + 2 + i)));
}
break;
case 37:
for (i = 0; i < optlen - 2; i++)
ND_PRINT((ndo, " %d", *(option + 2 + i)));
break;
case 38:
if (optlen > 2) {
ND_PRINT((ndo, " 0x"));
for (i = 0; i < optlen - 2; i++)
ND_PRINT((ndo, "%02x", *(option + 2 + i)));
}
break;
case 39:
if (optlen > 2) {
ND_PRINT((ndo, " 0x"));
for (i = 0; i < optlen - 2; i++)
ND_PRINT((ndo, "%02x", *(option + 2 + i)));
}
break;
case 40:
if (optlen > 2) {
ND_PRINT((ndo, " 0x"));
for (i = 0; i < optlen - 2; i++)
ND_PRINT((ndo, "%02x", *(option + 2 + i)));
}
break;
case 41:
if (optlen == 4)
ND_PRINT((ndo, " %u", EXTRACT_32BITS(option + 2)));
else
ND_PRINT((ndo, " optlen != 4"));
break;
case 42:
if (optlen == 4)
//.........这里部分代码省略.........
开发者ID:EliseuTorres,项目名称:tcpdump,代码行数:101,代码来源:print-dccp.c
示例3: token_print
u_int
token_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen)
{
const struct token_header *trp;
int llc_hdrlen;
struct ether_header ehdr;
u_int route_len = 0, hdr_len = TOKEN_HDRLEN;
int seg;
trp = (const struct token_header *)p;
if (caplen < TOKEN_HDRLEN) {
ND_PRINT((ndo, "%s", tstr));
return hdr_len;
}
/*
* Get the TR addresses into a canonical form
*/
extract_token_addrs(trp, (char*)ESRC(&ehdr), (char*)EDST(&ehdr));
/* Adjust for source routing information in the MAC header */
if (IS_SOURCE_ROUTED(trp)) {
/* Clear source-routed bit */
*ESRC(&ehdr) &= 0x7f;
if (ndo->ndo_eflag)
token_hdr_print(ndo, trp, length, ESRC(&ehdr), EDST(&ehdr));
if (caplen < TOKEN_HDRLEN + 2) {
ND_PRINT((ndo, "%s", tstr));
return hdr_len;
}
route_len = RIF_LENGTH(trp);
hdr_len += route_len;
if (caplen < hdr_len) {
ND_PRINT((ndo, "%s", tstr));
return hdr_len;
}
if (ndo->ndo_vflag) {
ND_PRINT((ndo, "%s ", broadcast_indicator[BROADCAST(trp)]));
ND_PRINT((ndo, "%s", direction[DIRECTION(trp)]));
for (seg = 0; seg < SEGMENT_COUNT(trp); seg++)
ND_PRINT((ndo, " [%d:%d]", RING_NUMBER(trp, seg),
BRIDGE_NUMBER(trp, seg)));
} else {
ND_PRINT((ndo, "rt = %x", EXTRACT_16BITS(&trp->token_rcf)));
for (seg = 0; seg < SEGMENT_COUNT(trp); seg++)
ND_PRINT((ndo, ":%x", EXTRACT_16BITS(&trp->token_rseg[seg])));
}
ND_PRINT((ndo, " (%s) ", largest_frame[LARGEST_FRAME(trp)]));
} else {
if (ndo->ndo_eflag)
token_hdr_print(ndo, trp, length, ESRC(&ehdr), EDST(&ehdr));
}
/* Skip over token ring MAC header and routing information */
length -= hdr_len;
p += hdr_len;
caplen -= hdr_len;
/* Frame Control field determines interpretation of packet */
if (FRAME_TYPE(trp) == TOKEN_FC_LLC) {
/* Try to print the LLC-layer header & higher layers */
llc_hdrlen = llc_print(ndo, p, length, caplen, ESRC(&ehdr),
EDST(&ehdr));
if (llc_hdrlen < 0) {
/* packet type not known, print raw packet */
if (!ndo->ndo_suppress_default_print)
ND_DEFAULTPRINT(p, caplen);
llc_hdrlen = -llc_hdrlen;
}
hdr_len += llc_hdrlen;
} else {
/* Some kinds of TR packet we cannot handle intelligently */
/* XXX - dissect MAC packets if frame type is 0 */
if (!ndo->ndo_eflag)
token_hdr_print(ndo, trp, length + TOKEN_HDRLEN + route_len,
ESRC(&ehdr), EDST(&ehdr));
if (!ndo->ndo_suppress_default_print)
ND_DEFAULTPRINT(p, caplen);
}
return (hdr_len);
}
开发者ID:EliseuTorres,项目名称:tcpdump,代码行数:86,代码来源:print-token.c
示例4: slow_oam_print
static void
slow_oam_print(netdissect_options *ndo,
register const u_char *tptr, register u_int tlen) {
u_int hexdump;
struct slow_oam_common_header_t {
uint8_t flags[2];
uint8_t code;
};
struct slow_oam_tlv_header_t {
uint8_t type;
uint8_t length;
};
union {
const struct slow_oam_common_header_t *slow_oam_common_header;
const struct slow_oam_tlv_header_t *slow_oam_tlv_header;
} ptr;
union {
const struct slow_oam_info_t *slow_oam_info;
const struct slow_oam_link_event_t *slow_oam_link_event;
const struct slow_oam_variablerequest_t *slow_oam_variablerequest;
const struct slow_oam_variableresponse_t *slow_oam_variableresponse;
const struct slow_oam_loopbackctrl_t *slow_oam_loopbackctrl;
} tlv;
ptr.slow_oam_common_header = (struct slow_oam_common_header_t *)tptr;
tptr += sizeof(struct slow_oam_common_header_t);
tlen -= sizeof(struct slow_oam_common_header_t);
ND_PRINT((ndo, "\n\tCode %s OAM PDU, Flags [%s]",
tok2str(slow_oam_code_values, "Unknown (%u)", ptr.slow_oam_common_header->code),
bittok2str(slow_oam_flag_values,
"none",
EXTRACT_16BITS(&ptr.slow_oam_common_header->flags))));
switch (ptr.slow_oam_common_header->code) {
case SLOW_OAM_CODE_INFO:
while (tlen > 0) {
ptr.slow_oam_tlv_header = (const struct slow_oam_tlv_header_t *)tptr;
ND_PRINT((ndo, "\n\t %s Information Type (%u), length %u",
tok2str(slow_oam_info_type_values, "Reserved",
ptr.slow_oam_tlv_header->type),
ptr.slow_oam_tlv_header->type,
ptr.slow_oam_tlv_header->length));
hexdump = FALSE;
switch (ptr.slow_oam_tlv_header->type) {
case SLOW_OAM_INFO_TYPE_END_OF_TLV:
if (ptr.slow_oam_tlv_header->length != 0) {
ND_PRINT((ndo, "\n\t ERROR: illegal length - should be 0"));
}
return;
case SLOW_OAM_INFO_TYPE_LOCAL: /* identical format - fall through */
case SLOW_OAM_INFO_TYPE_REMOTE:
tlv.slow_oam_info = (const struct slow_oam_info_t *)tptr;
if (tlv.slow_oam_info->info_length !=
sizeof(struct slow_oam_info_t)) {
ND_PRINT((ndo, "\n\t ERROR: illegal length - should be %lu",
(unsigned long) sizeof(struct slow_oam_info_t)));
return;
}
ND_PRINT((ndo, "\n\t OAM-Version %u, Revision %u",
tlv.slow_oam_info->oam_version,
EXTRACT_16BITS(&tlv.slow_oam_info->revision)));
ND_PRINT((ndo, "\n\t State-Parser-Action %s, State-MUX-Action %s",
tok2str(slow_oam_info_type_state_parser_values, "Reserved",
tlv.slow_oam_info->state & OAM_INFO_TYPE_PARSER_MASK),
tok2str(slow_oam_info_type_state_mux_values, "Reserved",
tlv.slow_oam_info->state & OAM_INFO_TYPE_MUX_MASK)));
ND_PRINT((ndo, "\n\t OAM-Config Flags [%s], OAM-PDU-Config max-PDU size %u",
bittok2str(slow_oam_info_type_oam_config_values, "none",
tlv.slow_oam_info->oam_config),
EXTRACT_16BITS(&tlv.slow_oam_info->oam_pdu_config) &
OAM_INFO_TYPE_PDU_SIZE_MASK));
ND_PRINT((ndo, "\n\t OUI %s (0x%06x), Vendor-Private 0x%08x",
tok2str(oui_values, "Unknown",
EXTRACT_24BITS(&tlv.slow_oam_info->oui)),
EXTRACT_24BITS(&tlv.slow_oam_info->oui),
EXTRACT_32BITS(&tlv.slow_oam_info->vendor_private)));
break;
case SLOW_OAM_INFO_TYPE_ORG_SPECIFIC:
hexdump = TRUE;
break;
default:
hexdump = TRUE;
break;
}
/* infinite loop check */
if (!ptr.slow_oam_tlv_header->length) {
//.........这里部分代码省略.........
开发者ID:Danielweber7624,项目名称:tcpdump,代码行数:101,代码来源:print-slow.c
示例5: babel_print_v2
static void
babel_print_v2(netdissect_options *ndo,
const u_char *cp, u_int length) {
u_int i;
u_short bodylen;
u_char v4_prefix[16] =
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF, 0, 0, 0, 0 };
u_char v6_prefix[16] = {0};
ND_TCHECK2(*cp, 4);
if (length < 4)
goto corrupt;
bodylen = EXTRACT_16BITS(cp + 2);
ND_PRINT((ndo, " (%u)", bodylen));
/* Process the TLVs in the body */
i = 0;
while(i < bodylen) {
const u_char *message;
u_int type, len;
message = cp + 4 + i;
ND_TCHECK2(*message, 1);
if((type = message[0]) == MESSAGE_PAD1) {
ND_PRINT((ndo, ndo->ndo_vflag ? "\n\tPad 1" : " pad1"));
i += 1;
continue;
}
ND_TCHECK2(*message, 2);
ICHECK(i, 2);
len = message[1];
ND_TCHECK2(*message, 2 + len);
ICHECK(i, 2 + len);
switch(type) {
case MESSAGE_PADN: {
if (!ndo->ndo_vflag)
ND_PRINT((ndo, " padN"));
else
ND_PRINT((ndo, "\n\tPad %d", len + 2));
}
break;
case MESSAGE_ACK_REQ: {
u_short nonce, interval;
if (!ndo->ndo_vflag)
ND_PRINT((ndo, " ack-req"));
else {
ND_PRINT((ndo, "\n\tAcknowledgment Request "));
if(len < 6) goto corrupt;
nonce = EXTRACT_16BITS(message + 4);
interval = EXTRACT_16BITS(message + 6);
ND_PRINT((ndo, "%04x %s", nonce, format_interval(interval)));
}
}
break;
case MESSAGE_ACK: {
u_short nonce;
if (!ndo->ndo_vflag)
ND_PRINT((ndo, " ack"));
else {
ND_PRINT((ndo, "\n\tAcknowledgment "));
if(len < 2) goto corrupt;
nonce = EXTRACT_16BITS(message + 2);
ND_PRINT((ndo, "%04x", nonce));
}
}
break;
case MESSAGE_HELLO: {
u_short seqno, interval;
if (!ndo->ndo_vflag)
ND_PRINT((ndo, " hello"));
else {
ND_PRINT((ndo, "\n\tHello "));
if(len < 6) goto corrupt;
seqno = EXTRACT_16BITS(message + 4);
interval = EXTRACT_16BITS(message + 6);
ND_PRINT((ndo, "seqno %u interval %s", seqno, format_interval(interval)));
}
}
break;
case MESSAGE_IHU: {
unsigned short txcost, interval;
if (!ndo->ndo_vflag)
ND_PRINT((ndo, " ihu"));
else {
u_char address[16];
int rc;
ND_PRINT((ndo, "\n\tIHU "));
if(len < 6) goto corrupt;
txcost = EXTRACT_16BITS(message + 4);
interval = EXTRACT_16BITS(message + 6);
rc = network_address(message[2], message + 8, len - 6, address);
if(rc < 0) { ND_PRINT((ndo, "%s", tstr)); break; }
//.........这里部分代码省略.........
开发者ID:rwdxll,项目名称:tcpdump,代码行数:101,代码来源:print-babel.c
示例6: tcp_print
void
tcp_print(register const u_char *bp, register u_int length,
register const u_char *bp2, int fragmented)
{
register const struct tcphdr *tp;
register const struct ip *ip;
register u_char flags;
register u_int hlen;
register char ch;
u_int16_t sport, dport, win, urp;
u_int32_t seq, ack, thseq, thack;
u_int utoval;
u_int16_t magic;
register int rev;
#ifdef INET6
register const struct ip6_hdr *ip6;
#endif
tp = (struct tcphdr *)bp;
ip = (struct ip *)bp2;
#ifdef INET6
if (IP_V(ip) == 6)
ip6 = (struct ip6_hdr *)bp2;
else
ip6 = NULL;
#endif /*INET6*/
ch = '\0';
if (!TTEST(tp->th_dport)) {
(void)printf("%s > %s: [|tcp]",
ipaddr_string(&ip->ip_src),
ipaddr_string(&ip->ip_dst));
return;
}
sport = EXTRACT_16BITS(&tp->th_sport);
dport = EXTRACT_16BITS(&tp->th_dport);
hlen = TH_OFF(tp) * 4;
#ifdef INET6
if (ip6) {
if (ip6->ip6_nxt == IPPROTO_TCP) {
(void)printf("%s.%s > %s.%s: ",
ip6addr_string(&ip6->ip6_src),
tcpport_string(sport),
ip6addr_string(&ip6->ip6_dst),
tcpport_string(dport));
} else {
(void)printf("%s > %s: ",
tcpport_string(sport), tcpport_string(dport));
}
} else
#endif /*INET6*/
{
if (ip->ip_p == IPPROTO_TCP) {
(void)printf("%s.%s > %s.%s: ",
ipaddr_string(&ip->ip_src),
tcpport_string(sport),
ipaddr_string(&ip->ip_dst),
tcpport_string(dport));
} else {
(void)printf("%s > %s: ",
tcpport_string(sport), tcpport_string(dport));
}
}
if (hlen < sizeof(*tp)) {
(void)printf(" tcp %d [bad hdr length %u - too short, < %lu]",
length - hlen, hlen, (unsigned long)sizeof(*tp));
return;
}
TCHECK(*tp);
seq = EXTRACT_32BITS(&tp->th_seq);
ack = EXTRACT_32BITS(&tp->th_ack);
win = EXTRACT_16BITS(&tp->th_win);
urp = EXTRACT_16BITS(&tp->th_urp);
if (qflag) {
(void)printf("tcp %d", length - hlen);
if (hlen > length) {
(void)printf(" [bad hdr length %u - too long, > %u]",
hlen, length);
}
return;
}
flags = tp->th_flags;
printf("Flags [%s]", bittok2str_nosep(tcp_flag_values, "none", flags));
if (!Sflag && (flags & TH_ACK)) {
/*
* Find (or record) the initial sequence numbers for
* this conversation. (we pick an arbitrary
* collating order so there's only one entry for
* both directions).
*/
rev = 0;
#ifdef INET6
//.........这里部分代码省略.........
开发者ID:anguscc,项目名称:tcpdump,代码行数:101,代码来源:print-tcp.c
示例7: tftp_print
/*
* Print trivial file transfer program requests
*/
void
tftp_print(register const u_char *bp, u_int length)
{
register const struct tftphdr *tp;
register const char *cp;
register const u_char *p;
register int opcode, i;
static char tstr[] = " [|tftp]";
tp = (const struct tftphdr *)bp;
/* Print length */
printf(" %d", length);
/* Print tftp request type */
TCHECK(tp->th_opcode);
opcode = EXTRACT_16BITS(&tp->th_opcode);
cp = tok2str(op2str, "tftp-#%d", opcode);
printf(" %s", cp);
/* Bail if bogus opcode */
if (*cp == 't')
return;
switch (opcode) {
case RRQ:
case WRQ:
case OACK:
/*
* XXX Not all arpa/tftp.h's specify th_stuff as any
* array; use address of th_block instead
*/
#ifdef notdef
p = (u_char *)tp->th_stuff;
#else
p = (u_char *)&tp->th_block;
#endif
putchar(' ');
/* Print filename or first option */
if (opcode != OACK)
putchar('"');
i = fn_print(p, snapend);
if (opcode != OACK)
putchar('"');
/* Print the mode (RRQ and WRQ only) and any options */
while ((p = (const u_char *)strchr((const char *)p, '\0')) != NULL) {
if (length <= (u_int)(p - (const u_char *)&tp->th_block))
break;
p++;
if (*p != '\0') {
putchar(' ');
fn_print(p, snapend);
}
}
if (i)
goto trunc;
break;
case ACK:
case DATA:
TCHECK(tp->th_block);
printf(" block %d", EXTRACT_16BITS(&tp->th_block));
break;
case TFTP_ERROR:
/* Print error code string */
TCHECK(tp->th_code);
printf(" %s \"", tok2str(err2str, "tftp-err-#%d \"",
EXTRACT_16BITS(&tp->th_code)));
/* Print error message string */
i = fn_print((const u_char *)tp->th_data, snapend);
putchar('"');
if (i)
goto trunc;
break;
default:
/* We shouldn't get here */
printf("(unknown #%d)", opcode);
break;
}
return;
trunc:
fputs(tstr, stdout);
return;
}
开发者ID:Claruarius,项目名称:stblinux-2.6.37,代码行数:91,代码来源:print-tftp.c
示例8: switch
/****************************************************************************
*
* Function: TCPOptionValue(Options *o)
*
* Purpose: To return a string representing the value of an TCP option
*
* Arguments: An Options struct.
*
* Returns: char * -- You must free this char * when you are done with it.
*
***************************************************************************/
char *TCPOptionValue(Options *o)
{
char * rval;
char * rvalptr;
u_char tmp[5];
int x;
rval = (char *)malloc(SMALLBUFFER);
rvalptr = rval;
switch(o->code)
{
case TCPOPT_MAXSEG:
bzero((char *)tmp, 5);
strncpy(tmp, o->data, 2);
snprintf(rval, SMALLBUFFER, "%u", EXTRACT_16BITS(tmp));
break;
case TCPOPT_EOL:
rval[0] = '\0';
break;
case TCPOPT_NOP:
rval[0] = '\0';
break;
case TCPOPT_WSCALE:
snprintf(rval, SMALLBUFFER, "%u", o->data[0]);
break;
case TCPOPT_SACK:
bzero((char *)tmp, 5);
memcpy(tmp, o->data, 2);
snprintf(rval, SMALLBUFFER, "%[email protected]", EXTRACT_16BITS(tmp));
x = strlen(rval);
rvalptr += x;
bzero((char *)tmp, 5);
memcpy(tmp, (o->data)+2, 2);
snprintf(rvalptr, SMALLBUFFER - x, "%u", EXTRACT_16BITS(tmp));
break;
case TCPOPT_SACKOK:
rval[0] = '\0';
break;
case TCPOPT_ECHO:
bzero((char *)tmp, 5);
memcpy(tmp, o->data, 4);
snprintf(rval, SMALLBUFFER, "%u", EXTRACT_32BITS(tmp));
break;
case TCPOPT_ECHOREPLY:
bzero((char *)tmp, 5);
memcpy(tmp, o->data, 4);
snprintf(rval, SMALLBUFFER, "%u", EXTRACT_32BITS(tmp));
break;
case TCPOPT_TIMESTAMP:
bzero((char *)tmp, 5);
memcpy(tmp, o->data, 4);
snprintf(rval, SMALLBUFFER, "%u ", EXTRACT_32BITS(tmp));
rvalptr += strlen(rval);
bzero((char *)tmp, 5);
memcpy(tmp, (o->data)+4, 4);
snprintf(rvalptr, SMALLBUFFER, "%u", EXTRACT_32BITS(tmp));
break;
case TCPOPT_CC:
bzero((char *)tmp, 5);
memcpy(tmp, o->data, 4);
snprintf(rval, SMALLBUFFER, "%u", EXTRACT_32BITS(tmp));
break;
case TCPOPT_CCNEW:
bzero((char *)tmp, 5);
memcpy(tmp, o->data, 4);
snprintf(rval, SMALLBUFFER, "%u", EXTRACT_32BITS(tmp));
break;
case TCPOPT_CCECHO:
bzero((char *)tmp, 5);
memcpy(tmp, o->data, 4);
snprintf(rval, SMALLBUFFER, "%u", EXTRACT_32BITS(tmp));
break;
default:
rval[0] = '\0';
if(o->len > 2)
{
//.........这里部分代码省略.........
开发者ID:paraler,项目名称:bashrc,代码行数:101,代码来源:plugbase.c
示例9: dccp_print
/**
* dccp_print - show dccp packet
* @bp - beginning of dccp packet
* @data2 - beginning of enclosing
* @len - lenght of ip packet
*/
void dccp_print(const u_char *bp, const u_char *data2, u_int len)
{
const struct dccp_hdr *dh;
const struct ip *ip;
#ifdef INET6
const struct ip6_hdr *ip6;
#endif
const u_char *cp;
u_short sport, dport;
u_int hlen;
u_int fixed_hdrlen;
dh = (const struct dccp_hdr *)bp;
ip = (struct ip *)data2;
#ifdef INET6
if (IP_V(ip) == 6)
ip6 = (const struct ip6_hdr *)data2;
else
ip6 = NULL;
#endif /*INET6*/
/* make sure we have enough data to look at the X bit */
cp = (const u_char *)(dh + 1);
if (cp > snapend) {
printf("[Invalid packet|dccp]");
return;
}
if (len < sizeof(struct dccp_hdr)) {
printf("truncated-dccp - %u bytes missing!",
len - (u_int)sizeof(struct dccp_hdr));
return;
}
/* get the length of the generic header */
fixed_hdrlen = dccp_basic_hdr_len(dh);
if (len < fixed_hdrlen) {
printf("truncated-dccp - %u bytes missing!",
len - fixed_hdrlen);
return;
}
TCHECK2(*dh, fixed_hdrlen);
sport = EXTRACT_16BITS(&dh->dccph_sport);
dport = EXTRACT_16BITS(&dh->dccph_dport);
hlen = dh->dccph_doff * 4;
#ifdef INET6
if (ip6) {
(void)printf("%s.%d > %s.%d: ",
ip6addr_string(&ip6->ip6_src), sport,
ip6addr_string(&ip6->ip6_dst), dport);
} else
#endif /*INET6*/
{
(void)printf("%s.%d > %s.%d: ",
ipaddr_string(&ip->ip_src), sport,
ipaddr_string(&ip->ip_dst), dport);
}
fflush(stdout);
if (qflag) {
(void)printf(" %d", len - hlen);
if (hlen > len) {
(void)printf("dccp [bad hdr length %u - too long, > %u]",
hlen, len);
}
return;
}
/* other variables in generic header */
if (vflag) {
(void)printf("CCVal %d, CsCov %d, ", DCCPH_CCVAL(dh), DCCPH_CSCOV(dh));
}
/* checksum calculation */
if (vflag && TTEST2(bp[0], len)) {
u_int16_t sum = 0, dccp_sum;
dccp_sum = EXTRACT_16BITS(&dh->dccph_checksum);
(void)printf("cksum 0x%04x ", dccp_sum);
if (IP_V(ip) == 4)
sum = dccp_cksum(ip, dh, len);
#ifdef INET6
else if (IP_V(ip) == 6)
sum = dccp6_cksum(ip6, dh, len);
#endif
if (sum != 0)
(void)printf("(incorrect -> 0x%04x), ",in_cksum_shouldbe(dccp_sum, sum));
else
(void)printf("(correct), ");
}
switch (DCCPH_TYPE(dh)) {
//.........这里部分代码省略.........
开发者ID:supermartian,项目名称:tcpdump,代码行数:101,代码来源:print-dccp.c
示例10: icmp_print
void
icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, const u_char *bp2,
int fragmented)
{
char *cp;
const struct icmp *dp;
const struct icmp_ext_t *ext_dp;
const struct ip *ip;
const char *str, *fmt;
const struct ip *oip;
const struct udphdr *ouh;
const uint8_t *obj_tptr;
uint32_t raw_label;
const u_char *snapend_save;
const struct icmp_mpls_ext_object_header_t *icmp_mpls_ext_object_header;
u_int hlen, dport, mtu, obj_tlen, obj_class_num, obj_ctype;
char buf[MAXHOSTNAMELEN + 100];
struct cksum_vec vec[1];
dp = (const struct icmp *)bp;
ext_dp = (const struct icmp_ext_t *)bp;
ip = (const struct ip *)bp2;
str = buf;
ND_TCHECK(dp->icmp_code);
switch (dp->icmp_type) {
case ICMP_ECHO:
case ICMP_ECHOREPLY:
ND_TCHECK(dp->icmp_seq);
(void)snprintf(buf, sizeof(buf), "echo %s, id %u, seq %u",
dp->icmp_type == ICMP_ECHO ?
"request" : "reply",
EXTRACT_16BITS(&dp->icmp_id),
EXTRACT_16BITS(&dp->icmp_seq));
break;
case ICMP_UNREACH:
ND_TCHECK(dp->icmp_ip.ip_dst);
switch (dp->icmp_code) {
case ICMP_UNREACH_PROTOCOL:
ND_TCHECK(dp->icmp_ip.ip_p);
(void)snprintf(buf, sizeof(buf),
"%s protocol %d unreachable",
ipaddr_string(ndo, &dp->icmp_ip.ip_dst),
dp->icmp_ip.ip_p);
break;
case ICMP_UNREACH_PORT:
ND_TCHECK(dp->icmp_ip.ip_p);
oip = &dp->icmp_ip;
hlen = IP_HL(oip) * 4;
ouh = (const struct udphdr *)(((const u_char *)oip) + hlen);
ND_TCHECK(ouh->uh_dport);
dport = EXTRACT_16BITS(&ouh->uh_dport);
switch (oip->ip_p) {
case IPPROTO_TCP:
(void)snprintf(buf, sizeof(buf),
"%s tcp port %s unreachable",
ipaddr_string(ndo, &oip->ip_dst),
tcpport_string(ndo, dport));
break;
case IPPROTO_UDP:
(void)snprintf(buf, sizeof(buf),
"%s udp port %s unreachable",
ipaddr_string(ndo, &oip->ip_dst),
udpport_string(ndo, dport));
break;
default:
(void)snprintf(buf, sizeof(buf),
"%s protocol %d port %d unreachable",
ipaddr_string(ndo, &oip->ip_dst),
oip->ip_p, dport);
break;
}
break;
case ICMP_UNREACH_NEEDFRAG:
{
register const struct mtu_discovery *mp;
mp = (const struct mtu_discovery *)(const u_char *)&dp->icmp_void;
mtu = EXTRACT_16BITS(&mp->nexthopmtu);
if (mtu) {
(void)snprintf(buf, sizeof(buf),
"%s unreachable - need to frag (mtu %d)",
ipaddr_string(ndo, &dp->icmp_ip.ip_dst), mtu);
} else {
(void)snprintf(buf, sizeof(buf),
"%s unreachable - need to frag",
ipaddr_string(ndo, &dp->icmp_ip.ip_dst));
}
}
break;
default:
fmt = tok2str(unreach2str, "#%d %%s unreachable",
//.........这里部分代码省略.........
开发者ID:RTEMS,项目名称:rtems-libbsd,代码行数:101,代码来源:print-icmp.c
示例11: slow_marker_lacp_print
static void
slow_marker_lacp_print(netdissect_options *ndo,
register const u_char *tptr, register u_int tlen) {
const struct tlv_header_t *tlv_header;
const u_char *tlv_tptr;
u_int tlv_len, tlv_tlen;
union {
const struct lacp_marker_tlv_terminator_t *lacp_marker_tlv_terminator;
const struct lacp_tlv_actor_partner_info_t *lacp_tlv_actor_partner_info;
const struct lacp_tlv_collector_info_t *lacp_tlv_collector_info;
const struct marker_tlv_marker_info_t *marker_tlv_marker_info;
} tlv_ptr;
while(tlen>0) {
/* did we capture enough for fully decoding the tlv header ? */
ND_TCHECK2(*tptr, sizeof(struct tlv_header_t));
tlv_header = (const struct tlv_header_t *)tptr;
tlv_len = tlv_header->length;
ND_PRINT((ndo, "\n\t%s TLV (0x%02x), length %u",
tok2str(slow_tlv_values,
"Unknown",
(slow_com_header->proto_subtype << 8) + tlv_header->type),
tlv_header->type,
tlv_len));
if ((tlv_len < sizeof(struct tlv_header_t) ||
tlv_len > tlen) &&
tlv_header->type != LACP_TLV_TERMINATOR &&
tlv_header->type != MARKER_TLV_TERMINATOR) {
ND_PRINT((ndo, "\n\t-----trailing data-----"));
print_unknown_data(ndo, tptr+sizeof(struct tlv_header_t), "\n\t ", tlen);
return;
}
tlv_tptr=tptr+sizeof(struct tlv_header_t);
tlv_tlen=tlv_len-sizeof(struct tlv_header_t);
/* did we capture enough for fully decoding the tlv ? */
ND_TCHECK2(*tptr, tlv_len);
switch((slow_com_header->proto_subtype << 8) + tlv_header->type) {
/* those two TLVs have the same structure -> fall through */
case ((SLOW_PROTO_LACP << 8) + LACP_TLV_ACTOR_INFO):
case ((SLOW_PROTO_LACP << 8) + LACP_TLV_PARTNER_INFO):
tlv_ptr.lacp_tlv_actor_partner_info = (const struct lacp_tlv_actor_partner_info_t *)tlv_tptr;
ND_PRINT((ndo, "\n\t System %s, System Priority %u, Key %u" \
", Port %u, Port Priority %u\n\t State Flags [%s]",
etheraddr_string(ndo, tlv_ptr.lacp_tlv_actor_partner_info->sys),
EXTRACT_16BITS(tlv_ptr.lacp_tlv_actor_partner_info->sys_pri),
EXTRACT_16BITS(tlv_ptr.lacp_tlv_actor_partner_info->key),
EXTRACT_16BITS(tlv_ptr.lacp_tlv_actor_partner_info->port),
EXTRACT_16BITS(tlv_ptr.lacp_tlv_actor_partner_info->port_pri),
bittok2str(lacp_tlv_actor_partner_info_state_values,
"none",
tlv_ptr.lacp_tlv_actor_partner_info->state)));
break;
case ((SLOW_PROTO_LACP << 8) + LACP_TLV_COLLECTOR_INFO):
tlv_ptr.lacp_tlv_collector_info = (const struct lacp_tlv_collector_info_t *)tlv_tptr;
ND_PRINT((ndo, "\n\t Max Delay %u",
EXTRACT_16BITS(tlv_ptr.lacp_tlv_collector_info->max_delay)));
break;
case ((SLOW_PROTO_MARKER << 8) + MARKER_TLV_MARKER_INFO):
tlv_ptr.marker_tlv_marker_info = (const struct marker_tlv_marker_info_t *)tlv_tptr;
ND_PRINT((ndo, "\n\t Request System %s, Request Port %u, Request Transaction ID 0x%08x",
etheraddr_string(ndo, tlv_ptr.marker_tlv_marker_info->req_sys),
EXTRACT_16BITS(tlv_ptr.marker_tlv_marker_info->req_port),
EXTRACT_32BITS(tlv_ptr.marker_tlv_marker_info->req_trans_id)));
break;
/* those two TLVs have the same structure -> fall through */
case ((SLOW_PROTO_LACP << 8) + LACP_TLV_TERMINATOR):
case ((SLOW_PROTO_MARKER << 8) + LACP_TLV_TERMINATOR):
tlv_ptr.lacp_marker_tlv_terminator = (const struct lacp_marker_tlv_terminator_t *)tlv_tptr;
if (tlv_len == 0) {
tlv_len = sizeof(tlv_ptr.lacp_marker_tlv_terminator->pad) +
sizeof(struct tlv_header_t);
/* tell the user that we modified the length field */
if (ndo->ndo_vflag>1)
ND_PRINT((ndo, " (=%u)", tlv_len));
/* we have messed around with the length field - now we need to check
* again if there are enough bytes on the wire for the hexdump */
ND_TCHECK2(tlv_ptr.lacp_marker_tlv_terminator->pad[0],
sizeof(tlv_ptr.lacp_marker_tlv_terminator->pad));
}
break;
default:
//.........这里部分代码省略.........
开发者ID:Danielweber7624,项目名称:tcpdump,代码行数:101,代码来源:print-slow.c
示例12: udld_print
void
udld_print (const u_char *pptr, u_int length)
{
int code, type, len;
const u_char *tptr;
if (length < UDLD_HEADER_LEN)
goto trunc;
tptr = pptr;
if (!TTEST2(*tptr, UDLD_HEADER_LEN))
goto trunc;
code = UDLD_EXTRACT_OPCODE(*tptr);
printf("UDLDv%u, Code %s (%x), Flags [%s] (0x%02x), length %u",
UDLD_EXTRACT_VERSION(*tptr),
tok2str(udld_code_values, "Reserved", code),
code,
bittok2str(udld_flags_values, "none", *(tptr+1)),
*(tptr+1),
length);
/*
* In non-verbose mode, just print version and opcode type
*/
if (vflag < 1) {
return;
}
printf("\n\tChecksum 0x%04x (unverified)", EXTRACT_16BITS(tptr+2));
tptr += UDLD_HEADER_LEN;
while (tptr < (pptr+length)) {
if (!TTEST2(*tptr, 4))
goto trunc;
type = EXTRACT_16BITS(tptr);
len = EXTRACT_16BITS(tptr+2);
len -= 4;
tptr += 4;
/* infinite loop check */
if (type == 0 || len == 0) {
return;
}
printf("\n\t%s (0x%04x) TLV, length %u",
tok2str(udld_tlv_values, "Unknown", type),
type, len);
switch (type) {
case UDLD_DEVICE_ID_TLV:
case UDLD_PORT_ID_TLV:
case UDLD_ECHO_TLV:
case UDLD_DEVICE_NAME_TLV:
printf(", %s", tptr);
break;
case UDLD_MESSAGE_INTERVAL_TLV:
case UDLD_TIMEOUT_INTERVAL_TLV:
printf(", %us", (*tptr));
break;
case UDLD_SEQ_NUMBER_TLV:
printf(", %u", EXTRACT_32BITS(tptr));
break;
default:
break;
}
tptr += len;
}
return;
trunc:
printf("[|udld]");
}
开发者ID:CriGio,项目名称:platform_external_tcpdump,代码行数:82,代码来源:print-udld.c
示例13: icmp_print
void
icmp_print(const u_char *bp, u_int length, const u_char *bp2)
{
const struct icmp *dp;
const struct ip *ip;
const char *str, *fmt;
const struct ip *oip;
const struct udphdr *ouh;
u_int hlen, dport, mtu;
char buf[MAXHOSTNAMELEN+256];
char buf2[MAXHOSTNAMELEN+256];
dp = (struct icmp *)bp;
ip = (struct ip *)bp2;
str = buf;
(void)printf("%s > %s: ",
ipaddr_string(&ip->ip_src),
ipaddr_string(&ip->ip_dst));
TCHECK(dp->icmp_code);
if (qflag)
(void) snprintf(buf, sizeof buf, "%u %u", dp->icmp_type,
dp->icmp_code);
else switch (dp->icmp_type) {
case ICMP_ECHOREPLY:
case ICMP_ECHO:
if (vflag) {
TCHECK(dp->icmp_seq);
(void)snprintf(buf, sizeof buf,
"echo %s (id:%04x seq:%u)",
(dp->icmp_type == ICMP_ECHO)?
"request": "reply",
ntohs(dp->icmp_id),
ntohs(dp->icmp_seq));
} else
str = tok2str(icmp2str, "type-#%u", dp->icmp_type);
break;
case ICMP_UNREACH:
TCHECK(dp->icmp_ip.ip_dst);
switch (dp->icmp_code) {
case ICMP_UNREACH_PROTOCOL:
TCHECK(dp->icmp_ip.ip_p);
(void)snprintf(buf, sizeof buf,
"%s protocol %u unreachable",
ipaddr_string(&dp->icmp_ip.ip_dst),
dp->icmp_ip.ip_p);
break;
case ICMP_UNREACH_PORT:
TCHECK(dp->icmp_ip.ip_p);
oip = &dp->icmp_ip;
hlen = oip->ip_hl * 4;
ouh = (struct udphdr *)(((u_char *)oip) + hlen);
TCHECK(ouh->uh_dport);
dport = ntohs(ouh->uh_dport);
switch (oip->ip_p) {
case IPPROTO_TCP:
(void)snprintf(buf, sizeof buf,
"%s tcp port %s unreachable",
ipaddr_string(&oip->ip_dst),
tcpport_string(dport));
break;
case IPPROTO_UDP:
(void)snprintf(buf, sizeof buf,
"%s udp port %s unreachable",
ipaddr_string(&oip->ip_dst),
udpport_string(dport));
break;
default:
(void)snprintf(buf, sizeof buf,
"%s protocol %u port %u unreachable",
ipaddr_string(&oip->ip_dst),
oip->ip_p, dport);
break;
}
break;
case ICMP_UNREACH_NEEDFRAG:
{
const struct mtu_discovery *mp;
mp = (struct mtu_discovery *)&dp->icmp_void;
mtu = EXTRACT_16BITS(&mp->nexthopmtu);
if (mtu)
(void)snprintf(buf, sizeof buf,
"%s unreachable - need to frag (mtu %u)",
ipaddr_string(&dp->icmp_ip.ip_dst), mtu);
else
(void)snprintf(buf, sizeof buf,
"%s unreachable - need to frag",
ipaddr_string(&dp->icmp_ip.ip_dst));
}
break;
//.........这里部分代码省略.........
开发者ID:appleorange1,项目名称:bitrig,代码行数:101,代码来源:print-icmp.c
示例14: msdp_print
void
msdp_print(netdissect_options *ndo, const u_char *sp, u_int length)
{
unsigned int type, len;
ND_TCHECK2(*sp, 3);
/* See if we think we're at the beginning of a compound packet */
type = *sp;
len = EXTRACT_16BITS(sp + 1);
if (len > 1500 || len < 3 || type == 0 || type > MSDP_TYPE_MAX)
goto trunc; /* not really truncated, but still not decodable */
ND_PRINT((ndo, " msdp:"));
while (length > 0) {
ND_TCHECK2(*sp, 3);
type = *sp;
len = EXTRACT_16BITS(sp + 1);
if (len > 1400 || ndo->ndo_vflag)
ND_PRINT((ndo, " [len %u]", len));
if (len < 3)
goto trunc;
sp += 3;
length -= 3;
switch (type) {
case 1: /* IPv4 Source-Active */
case 3: /* IPv4 Source-Active Response */
if (type == 1)
ND_PRINT((ndo, " SA"));
else
ND_PRINT((ndo, " SA-Response"));
ND_TCHECK(*sp);
ND_PRINT((ndo, " %u entries", *sp));
if ((u_int)((*sp * 12) + 8) < len) {
ND_PRINT((ndo, " [w/data]"));
if (ndo->ndo_vflag > 1) {
ND_PRINT((ndo, " "));
ip_print(ndo, sp + *sp * 12 + 8 - 3,
len - (*sp * 12 + 8));
}
}
break;
case 2:
ND_PRINT((ndo, " SA-Request"));
ND_TCHECK2(*sp, 5);
ND_PRINT((ndo, " for %s", ipaddr_string(sp + 1)));
break;
case 4:
ND_PRINT((ndo, " Keepalive"));
if (len != 3)
ND_PRINT((ndo, "[len=%d] ", len));
break;
case 5:
ND_PRINT((ndo, " Notification"));
break;
default:
ND_PRINT((ndo, " [type=%d len=%d]", type, len));
break;
}
sp += (len - 3);
length -= (len - 3);
}
return;
trunc:
ND_PRINT((ndo, " [|msdp]"));
}
开发者ID:ecbtnrt,项目名称:tcpdump,代码行数:64,代码来源:print-msdp.c
示例15: dccp_print
/**
* dccp_print - show dccp packet
* @bp - beginning of dccp packet
* @data2 - beginning of enclosing
* @len - lenght of ip packet
*/
void dccp_print(netdissect_options *ndo, const u_char *bp, const u_char *data2,
u_int len)
{
const struct dccp_hdr *dh;
const struct ip *ip;
#ifdef INET6
const struct ip6_hdr *ip6;
#endif
const u_char *cp;
u_short sport, dport;
u_int hlen;
u_int fixed_hdrlen;
uint8_t dccph_type;
dh = (const struct dccp_hdr *)bp;
ip = (const struct ip *)data2;
#ifdef INET6
if (IP_V(ip) == 6)
ip6 = (const struct ip6_hdr *)data2;
else
ip6 = NULL;
#endif /*INET6*/
/* make sure we have enough data to look at the X bit */
cp = (const u_char *)(dh + 1);
if (cp > ndo->ndo_snapend) {
ND_PRINT((ndo, "[Invalid packet|dccp]"));
return;
}
if (len < sizeof(struct dccp_hdr)) {
ND_PRINT((ndo, "truncated-dccp - %u bytes missing!",
len - (u_int)sizeof(struct dccp_hdr)));
return;
}
/* get the length of the generic header */
fixed_hdrlen = dccp_basic_hdr_len(dh);
if (len < fixed_hdrlen) {
ND_PRINT((ndo, "truncated-dccp - %u bytes missing!",
len - fixed_hdrlen));
return;
}
ND_TCHECK2(*dh, fixed_hdrlen);
sport = EXTRACT_16BITS(&dh->dccph_sport);
dport = EXTRACT_16BITS(&dh->dccph_dport);
hlen = dh->dccph_doff * 4;
#ifdef INET6
if (ip6) {
ND_PRINT((ndo, "%s.%d > %s.%d: ",
ip6addr_string(ndo, &ip6->ip6_src), sport,
ip6addr_string(ndo, &ip6->ip6_dst), dport));
} else
#endif /*INET6*/
{
ND_PRINT((ndo, "%s.%d > %s.%d: ",
ipaddr_string(ndo, &ip->ip_src), sport,
ipaddr_string(ndo, &ip->ip_dst), dport));
}
ND_PRINT((ndo, "DCCP"));
if (ndo->ndo_qflag) {
ND_PRINT((ndo, " %d", len - hlen));
if (hlen > len) {
ND_PRINT((ndo, " [bad hdr length %u - too long, > %u]",
hlen, len));
}
return;
}
/* other variables in generic header */
if (ndo->ndo_vflag) {
ND_PRINT((ndo, " (CCVal %d, CsCov %d, ", DCCPH_CCVAL(dh), DCCPH_CSCOV(dh)));
}
/* checksum calculation */
if (ndo->ndo_vflag && ND_TTEST2(bp[0], len)) {
uint16_t sum = 0, dccp_sum;
dccp_sum = EXTRACT_16BITS(&dh->dccph_checksum);
ND_PRINT((ndo, "cksum 0x%04x ", dccp_sum));
if (IP_V(ip) == 4)
sum = dccp_cksum(ndo, ip, dh, len);
#ifdef INET6
else if (IP_V(ip) == 6)
sum = dccp6_cksum(ip6, dh, len);
#endif
if (sum != 0)
ND_PRINT((ndo, "(in
|
请发表评论