xref: /netbsd-src/external/bsd/tcpdump/dist/print-calm-fast.c (revision ccd9df534e375a4366c5b55f23782053c7a98d82)
1 /*
2  * Copyright (c) 2013 The TCPDUMP project
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that: (1) source code
6  * distributions retain the above copyright notice and this paragraph
7  * in its entirety, and (2) distributions including binary code include
8  * the above copyright notice and this paragraph in its entirety in
9  * the documentation or other materials provided with the distribution.
10  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND
11  * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
12  * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
13  * FOR A PARTICULAR PURPOSE.
14  *
15  * Original code by Ola Martin Lykkja (ola.lykkja@q-free.com)
16  */
17 
18 #include <sys/cdefs.h>
19 #ifndef lint
20 __RCSID("$NetBSD: print-calm-fast.c,v 1.4 2023/08/17 20:19:40 christos Exp $");
21 #endif
22 
23 /* \summary: Communication access for land mobiles (CALM) printer */
24 
25 #ifdef HAVE_CONFIG_H
26 #include <config.h>
27 #endif
28 
29 #include "netdissect-stdinc.h"
30 
31 #define ND_LONGJMP_FROM_TCHECK
32 #include "netdissect.h"
33 #include "extract.h"
34 #include "addrtoname.h"
35 
36 /*
37    ISO 29281:2009
38    Intelligent Transport Systems . Communications access for land mobiles (CALM)
39    CALM non-IP networking
40 */
41 
42 /*
43  * This is the top level routine of the printer.  'bp' points
44  * to the calm header of the packet.
45  */
46 void
47 calm_fast_print(netdissect_options *ndo, const u_char *bp, u_int length, const struct lladdr_info *src)
48 {
49 	ndo->ndo_protocol = "calm_fast";
50 
51 	ND_PRINT("CALM FAST");
52 	if (src != NULL)
53 		ND_PRINT(" src:%s", (src->addr_string)(ndo, src->addr));
54 	ND_PRINT("; ");
55 
56 	if (length < 2) {
57 		ND_PRINT(" (length %u < 2)", length);
58 		goto invalid;
59 	}
60 
61 	ND_PRINT("SrcNwref:%u; ", GET_U_1(bp));
62 	length -= 1;
63 	bp += 1;
64 
65 	ND_PRINT("DstNwref:%u; ", GET_U_1(bp));
66 	length -= 1;
67 	bp += 1;
68 
69 	if (ndo->ndo_vflag)
70 		ND_DEFAULTPRINT(bp, length);
71 	return;
72 
73 invalid:
74 	nd_print_invalid(ndo);
75 	ND_TCHECK_LEN(bp, length);
76 }
77