]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Use tok2strbuf() rather than doing it by hand (with potentially-unsafe
authorGuy Harris <[email protected]>
Sun, 11 Oct 2009 19:49:05 +0000 (12:49 -0700)
committerGuy Harris <[email protected]>
Sun, 11 Oct 2009 19:49:05 +0000 (12:49 -0700)
routines).  Thanks and a tip of the Hatlo hat to OpenBSD's linker for
warning about that.

print-rrcp.c

index 96a49617aa69157fca31507304180fa6b956c1db..961fb87309c6f6350c5c11557cd2285a927b45f1 100644 (file)
@@ -64,6 +64,19 @@ static const char rcsid[] _U_ =
 #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
  */
@@ -84,31 +97,16 @@ rrcp_print(netdissect_options *ndo,
 
        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,
+               tok2strbuf(proto_values,"RRCP-0x%02d",rrcp_proto,proto_str,sizeof(proto_str)),
                ((*(rrcp + RRCP_OPCODE_ISREPLY_OFFSET)) & RRCP_ISREPLY) ? "reply" : "query"));
        if (rrcp_proto==1){
-           ND_PRINT((ndo, ": %s", opcode_str));
+           ND_PRINT((ndo, ": %s",
+                    tok2strbuf(opcode_values,"unknown opcode (0x%02d)",rrcp_opcode,opcode_str,sizeof(opcode_str))));
        }
        if (rrcp_opcode==1 || rrcp_opcode==2){
            ND_TCHECK2(*(rrcp + RRCP_REG_ADDR_OFFSET), 6);