X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/e2982e7f6f0b624a773ec5a58885ee80fab46d34..cda9bf8c5f842fc7110fbbf2234bcc898f78c0bd:/print-olsr.c diff --git a/print-olsr.c b/print-olsr.c index 449fc917..8e3adbbb 100644 --- a/print-olsr.c +++ b/print-olsr.c @@ -22,10 +22,10 @@ /* specification: RFC 3626 */ #ifdef HAVE_CONFIG_H -#include "config.h" +#include #endif -#include +#include "netdissect-stdinc.h" #include "netdissect.h" #include "addrtoname.h" @@ -213,8 +213,9 @@ static uint32_t deserialize_gw_speed(uint8_t value) { speed = (value >> 3) + 1; exp = value & 7; - while (exp-- > 0) { + while (exp != 0) { speed *= 10; + exp--; } return speed; } @@ -239,19 +240,20 @@ olsr_print_lq_neighbor4(netdissect_options *ndo, while (hello_len >= sizeof(struct olsr_lq_neighbor4)) { lq_neighbor = (const struct olsr_lq_neighbor4 *)msg_data; - if (!ND_TTEST_SIZE(lq_neighbor)) - return (-1); + ND_TCHECK_SIZE(lq_neighbor); ND_PRINT("\n\t neighbor %s, link-quality %.2f%%" ", neighbor-link-quality %.2f%%", ipaddr_string(ndo, lq_neighbor->neighbor), - ((double)EXTRACT_U_1(lq_neighbor->link_quality)/2.55), - ((double)EXTRACT_U_1(lq_neighbor->neighbor_link_quality)/2.55)); + ((double) GET_U_1(lq_neighbor->link_quality)/2.55), + ((double) GET_U_1(lq_neighbor->neighbor_link_quality)/2.55)); msg_data += sizeof(struct olsr_lq_neighbor4); hello_len -= sizeof(struct olsr_lq_neighbor4); } return (0); +trunc: + return -1; } static int @@ -263,19 +265,20 @@ olsr_print_lq_neighbor6(netdissect_options *ndo, while (hello_len >= sizeof(struct olsr_lq_neighbor6)) { lq_neighbor = (const struct olsr_lq_neighbor6 *)msg_data; - if (!ND_TTEST_SIZE(lq_neighbor)) - return (-1); + ND_TCHECK_SIZE(lq_neighbor); ND_PRINT("\n\t neighbor %s, link-quality %.2f%%" ", neighbor-link-quality %.2f%%", ip6addr_string(ndo, lq_neighbor->neighbor), - ((double)EXTRACT_U_1(lq_neighbor->link_quality)/2.55), - ((double)EXTRACT_U_1(lq_neighbor->neighbor_link_quality)/2.55)); + ((double) GET_U_1(lq_neighbor->link_quality)/2.55), + ((double) GET_U_1(lq_neighbor->neighbor_link_quality)/2.55)); msg_data += sizeof(struct olsr_lq_neighbor6); hello_len -= sizeof(struct olsr_lq_neighbor6); } return (0); +trunc: + return -1; } /* @@ -290,19 +293,20 @@ olsr_print_neighbor(netdissect_options *ndo, ND_PRINT("\n\t neighbor\n\t\t"); neighbor = 1; - while (hello_len >= sizeof(struct in_addr)) { + while (hello_len >= sizeof(nd_ipv4)) { - if (!ND_TTEST_LEN(msg_data, sizeof(struct in_addr))) - return (-1); + ND_TCHECK_LEN(msg_data, sizeof(nd_ipv4)); /* print 4 neighbors per line */ ND_PRINT("%s%s", ipaddr_string(ndo, msg_data), neighbor % 4 == 0 ? "\n\t\t" : " "); - msg_data += sizeof(struct in_addr); - hello_len -= sizeof(struct in_addr); + msg_data += sizeof(nd_ipv4); + hello_len -= sizeof(nd_ipv4); } return (0); +trunc: + return -1; } @@ -326,6 +330,7 @@ olsr_print(netdissect_options *ndo, uint8_t link_type, neighbor_type; const u_char *tptr, *msg_data; + ndo->ndo_protocol = "olsr"; tptr = pptr; if (length < sizeof(struct olsr_common)) { @@ -335,11 +340,11 @@ olsr_print(netdissect_options *ndo, ND_TCHECK_LEN(tptr, sizeof(struct olsr_common)); ptr.common = (const struct olsr_common *)tptr; - length = min(length, EXTRACT_BE_U_2(ptr.common->packet_len)); + length = min(length, GET_BE_U_2(ptr.common->packet_len)); ND_PRINT("OLSRv%i, seq 0x%04x, length %u", (is_ipv6 == 0) ? 4 : 6, - EXTRACT_BE_U_2(ptr.common->packet_seq), + GET_BE_U_2(ptr.common->packet_seq), length); tptr += sizeof(struct olsr_common); @@ -363,8 +368,8 @@ olsr_print(netdissect_options *ndo, { ND_TCHECK_LEN(tptr, sizeof(struct olsr_msg6)); msgptr.v6 = (const struct olsr_msg6 *) tptr; - msg_type = EXTRACT_U_1(msgptr.v6->msg_type); - msg_len = EXTRACT_BE_U_2(msgptr.v6->msg_len); + msg_type = GET_U_1(msgptr.v6->msg_type); + msg_len = GET_BE_U_2(msgptr.v6->msg_len); if ((msg_len >= sizeof (struct olsr_msg6)) && (msg_len <= length)) msg_len_valid = 1; @@ -378,10 +383,10 @@ olsr_print(netdissect_options *ndo, "\n\t vtime %.3fs, msg-seq 0x%04x, length %u%s", tok2str(olsr_msg_values, "Unknown", msg_type), msg_type, ip6addr_string(ndo, msgptr.v6->originator), - EXTRACT_U_1(msgptr.v6->ttl), - EXTRACT_U_1(msgptr.v6->hopcount), - ME_TO_DOUBLE(EXTRACT_U_1(msgptr.v6->vtime)), - EXTRACT_BE_U_2(msgptr.v6->msg_seq), + GET_U_1(msgptr.v6->ttl), + GET_U_1(msgptr.v6->hopcount), + ME_TO_DOUBLE(GET_U_1(msgptr.v6->vtime)), + GET_BE_U_2(msgptr.v6->msg_seq), msg_len, (msg_len_valid == 0) ? " (invalid)" : ""); if (!msg_len_valid) { return; @@ -394,8 +399,8 @@ olsr_print(netdissect_options *ndo, { ND_TCHECK_LEN(tptr, sizeof(struct olsr_msg4)); msgptr.v4 = (const struct olsr_msg4 *) tptr; - msg_type = EXTRACT_U_1(msgptr.v4->msg_type); - msg_len = EXTRACT_BE_U_2(msgptr.v4->msg_len); + msg_type = GET_U_1(msgptr.v4->msg_type); + msg_len = GET_BE_U_2(msgptr.v4->msg_len); if ((msg_len >= sizeof (struct olsr_msg4)) && (msg_len <= length)) msg_len_valid = 1; @@ -409,10 +414,10 @@ olsr_print(netdissect_options *ndo, "\n\t vtime %.3fs, msg-seq 0x%04x, length %u%s", tok2str(olsr_msg_values, "Unknown", msg_type), msg_type, ipaddr_string(ndo, msgptr.v4->originator), - EXTRACT_U_1(msgptr.v4->ttl), - EXTRACT_U_1(msgptr.v4->hopcount), - ME_TO_DOUBLE(EXTRACT_U_1(msgptr.v4->vtime)), - EXTRACT_BE_U_2(msgptr.v4->msg_seq), + GET_U_1(msgptr.v4->ttl), + GET_U_1(msgptr.v4->hopcount), + ME_TO_DOUBLE(GET_U_1(msgptr.v4->vtime)), + GET_BE_U_2(msgptr.v4->msg_seq), msg_len, (msg_len_valid == 0) ? " (invalid)" : ""); if (!msg_len_valid) { return; @@ -431,8 +436,8 @@ olsr_print(netdissect_options *ndo, ptr.hello = (const struct olsr_hello *)msg_data; ND_PRINT("\n\t hello-time %.3fs, MPR willingness %u", - ME_TO_DOUBLE(EXTRACT_U_1(ptr.hello->htime)), - EXTRACT_U_1(ptr.hello->will)); + ME_TO_DOUBLE(GET_U_1(ptr.hello->htime)), + GET_U_1(ptr.hello->will)); msg_data += sizeof(struct olsr_hello); msg_tlen -= sizeof(struct olsr_hello); @@ -446,9 +451,9 @@ olsr_print(netdissect_options *ndo, ptr.hello_link = (const struct olsr_hello_link *)msg_data; - hello_len = EXTRACT_BE_U_2(ptr.hello_link->len); - link_type = OLSR_EXTRACT_LINK_TYPE(EXTRACT_U_1(ptr.hello_link->link_code)); - neighbor_type = OLSR_EXTRACT_NEIGHBOR_TYPE(EXTRACT_U_1(ptr.hello_link->link_code)); + hello_len = GET_BE_U_2(ptr.hello_link->len); + link_type = OLSR_EXTRACT_LINK_TYPE(GET_U_1(ptr.hello_link->link_code)); + neighbor_type = OLSR_EXTRACT_NEIGHBOR_TYPE(GET_U_1(ptr.hello_link->link_code)); if ((hello_len <= msg_tlen) && (hello_len >= sizeof(struct olsr_hello_link))) @@ -494,7 +499,7 @@ olsr_print(netdissect_options *ndo, ptr.tc = (const struct olsr_tc *)msg_data; ND_PRINT("\n\t advertised neighbor seq 0x%04x", - EXTRACT_BE_U_2(ptr.tc->ans_seq)); + GET_BE_U_2(ptr.tc->ans_seq)); msg_data += sizeof(struct olsr_tc); msg_tlen -= sizeof(struct olsr_tc); @@ -514,10 +519,10 @@ olsr_print(netdissect_options *ndo, case OLSR_MID_MSG: { - size_t addr_size = sizeof(struct in_addr); + size_t addr_size = sizeof(nd_ipv4); if (is_ipv6) - addr_size = sizeof(struct in6_addr); + addr_size = sizeof(nd_ipv6); while (msg_tlen >= addr_size) { ND_TCHECK_LEN(msg_data, addr_size); @@ -604,7 +609,7 @@ olsr_print(netdissect_options *ndo, ND_PRINT("%s%s/%u", col == 0 ? "\n\t " : ", ", ipaddr_string(ndo, ptr.hna->network), - mask2plen(EXTRACT_BE_U_4(ptr.hna->mask))); + mask2plen(GET_BE_U_4(ptr.hna->mask))); } msg_data += sizeof(struct olsr_hna4); @@ -626,7 +631,7 @@ olsr_print(netdissect_options *ndo, goto trunc; ND_TCHECK_4(msg_data); - name_entries = EXTRACT_BE_U_2(msg_data + 2); + name_entries = GET_BE_U_2(msg_data + 2); addr_size = 4; if (is_ipv6) addr_size = 16; @@ -637,7 +642,7 @@ olsr_print(netdissect_options *ndo, name_entries_valid = 1; ND_PRINT("\n\t Version %u, Entries %u%s", - EXTRACT_BE_U_2(msg_data), + GET_BE_U_2(msg_data), name_entries, (name_entries_valid == 0) ? " (invalid)" : ""); if (name_entries_valid == 0) @@ -653,8 +658,8 @@ olsr_print(netdissect_options *ndo, break; ND_TCHECK_4(msg_data); - name_entry_type = EXTRACT_BE_U_2(msg_data); - name_entry_len = EXTRACT_BE_U_2(msg_data + 2); + name_entry_type = GET_BE_U_2(msg_data); + name_entry_len = GET_BE_U_2(msg_data + 2); msg_data += 4; msg_tlen -= 4; @@ -686,7 +691,7 @@ olsr_print(netdissect_options *ndo, else ND_PRINT(", address %s, name \"", ipaddr_string(ndo, msg_data)); - (void)fn_printn(ndo, msg_data + addr_size, name_entry_len, NULL); + (void)nd_printn(ndo, msg_data + addr_size, name_entry_len, NULL); ND_PRINT("\""); msg_data += addr_size + name_entry_len + name_entry_padding; @@ -710,12 +715,5 @@ olsr_print(netdissect_options *ndo, return; trunc: - ND_PRINT("[|olsr]"); + nd_print_trunc(ndo); } - -/* - * Local Variables: - * c-style: whitesmith - * c-basic-offset: 4 - * End: - */