* and Realtek Echo Protocol (RRCP-REP) packets.
*/
-#ifndef lint
-static const char rcsid[] _U_ =
- "@(#) $Header: /tcpdump/master/tcpdump/print-rrcp.c,v 1.2 2008-04-11 17:21:34 gianluca Exp $";
-#endif
-
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
-#include <tcpdump-stdinc.h>
-
-#include <stdio.h>
-#include <string.h>
+#include <netdissect-stdinc.h>
#include "netdissect.h"
#include "addrtoname.h"
#include "extract.h"
#include "ether.h"
-#ifndef ETH_ALEN
-#define ETH_ALEN 6
-#endif
-
#define RRCP_OPCODE_MASK 0x7F /* 0x00 = hello, 0x01 = get, 0x02 = set */
#define RRCP_ISREPLY 0x80 /* 0 = request to switch, 0x80 = reply from switch */
#define RRCP_CHIP_ID_OFFSET 12 /* 2 bytes */
#define RRCP_VENDOR_ID_OFFSET 14 /* 4 bytes */
+static const struct tok proto_values[] = {
+ { 1, "RRCP" },
+ { 2, "RRCP-REP" },
+ { 0, NULL }
+};
+
+static const struct tok opcode_values[] = {
+ { 0, "hello" },
+ { 1, "get" },
+ { 2, "set" },
+ { 0, NULL }
+};
+
/*
* Print RRCP requests
*/
u_int length _U_)
{
const u_char *rrcp;
- u_int8_t rrcp_proto;
- u_int8_t rrcp_opcode;
+ uint8_t rrcp_proto;
+ uint8_t rrcp_opcode;
register const struct ether_header *ep;
- char proto_str[16];
- char opcode_str[32];
ep = (const struct ether_header *)cp;
rrcp = cp + ETHER_HDRLEN;
ND_TCHECK(*(rrcp + RRCP_PROTO_OFFSET));
rrcp_proto = *(rrcp + RRCP_PROTO_OFFSET);
- if (rrcp_proto==1){
- strcpy(proto_str,"RRCP");
- }else if ( rrcp_proto==2 ){
- strcpy(proto_str,"RRCP-REP");
- }else{
- sprintf(proto_str,"RRCP-0x%02d",rrcp_proto);
- }
ND_TCHECK(*(rrcp + RRCP_OPCODE_ISREPLY_OFFSET));
rrcp_opcode = (*(rrcp + RRCP_OPCODE_ISREPLY_OFFSET)) & RRCP_OPCODE_MASK;
- if (rrcp_opcode==0){
- strcpy(opcode_str,"hello");
- }else if ( rrcp_opcode==1 ){
- strcpy(opcode_str,"get");
- }else if ( rrcp_opcode==2 ){
- strcpy(opcode_str,"set");
- }else{
- sprintf(opcode_str,"unknown opcode (0x%02d)",rrcp_opcode);
- }
ND_PRINT((ndo, "%s > %s, %s %s",
- etheraddr_string(ESRC(ep)),
- etheraddr_string(EDST(ep)),
- proto_str,
+ etheraddr_string(ndo, ESRC(ep)),
+ etheraddr_string(ndo, EDST(ep)),
+ tok2str(proto_values,"RRCP-0x%02x",rrcp_proto),
((*(rrcp + RRCP_OPCODE_ISREPLY_OFFSET)) & RRCP_ISREPLY) ? "reply" : "query"));
if (rrcp_proto==1){
- ND_PRINT((ndo, ": %s", opcode_str));
+ ND_PRINT((ndo, ": %s",
+ tok2str(opcode_values,"unknown opcode (0x%02x)",rrcp_opcode)));
}
if (rrcp_opcode==1 || rrcp_opcode==2){
ND_TCHECK2(*(rrcp + RRCP_REG_ADDR_OFFSET), 6);
ND_PRINT((ndo, " addr=0x%04x, data=0x%08x",
- EXTRACT_16BITS(rrcp + RRCP_REG_ADDR_OFFSET),
- EXTRACT_32BITS(rrcp + RRCP_REG_DATA_OFFSET)));
+ EXTRACT_LE_16BITS(rrcp + RRCP_REG_ADDR_OFFSET),
+ EXTRACT_LE_32BITS(rrcp + RRCP_REG_DATA_OFFSET)));
}
if (rrcp_proto==1){
ND_TCHECK2(*(rrcp + RRCP_AUTHKEY_OFFSET), 2);
ND_PRINT((ndo, " downlink_port=%d, uplink_port=%d, uplink_mac=%s, vendor_id=%08x ,chip_id=%04x ",
*(rrcp + RRCP_DOWNLINK_PORT_OFFSET),
*(rrcp + RRCP_UPLINK_PORT_OFFSET),
- etheraddr_string(rrcp + RRCP_UPLINK_MAC_OFFSET),
+ etheraddr_string(ndo, rrcp + RRCP_UPLINK_MAC_OFFSET),
EXTRACT_32BITS(rrcp + RRCP_VENDOR_ID_OFFSET),
EXTRACT_16BITS(rrcp + RRCP_CHIP_ID_OFFSET)));
}else if (rrcp_opcode==1 || rrcp_opcode==2 || rrcp_proto==2){
EXTRACT_32BITS(rrcp + RRCP_COOKIE2_OFFSET),
EXTRACT_32BITS(rrcp + RRCP_COOKIE1_OFFSET)));
}
- if (!ndo->ndo_vflag)
- return;
return;
trunc: