xref: /netbsd-src/external/bsd/tcpdump/dist/print-sip.c (revision b8ecfcfef0e343ad71faea7a54fb5fcb42ad4e27)
1 /*
2  * Redistribution and use in source and binary forms, with or without
3  * modification, are permitted provided that: (1) source code
4  * distributions retain the above copyright notice and this paragraph
5  * in its entirety, and (2) distributions including binary code include
6  * the above copyright notice and this paragraph in its entirety in
7  * the documentation or other materials provided with the distribution.
8  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND
9  * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
10  * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
11  * FOR A PARTICULAR PURPOSE.
12  *
13  * Original code by Hannes Gredler (hannes@juniper.net)
14  */
15 
16 #include <sys/cdefs.h>
17 #ifndef lint
18 __RCSID("$NetBSD: print-sip.c,v 1.4 2014/11/20 03:05:03 christos Exp $");
19 #endif
20 
21 #define NETDISSECT_REWORKED
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25 
26 #include <tcpdump-stdinc.h>
27 
28 #include "interface.h"
29 #include "extract.h"
30 
31 void
32 sip_print(netdissect_options *ndo,
33           register const u_char *pptr, register u_int len)
34 {
35     u_int idx;
36 
37     ND_PRINT((ndo, "SIP, length: %u%s", len, ndo->ndo_vflag ? "\n\t" : ""));
38 
39     /* in non-verbose mode just lets print the protocol and length */
40     if (ndo->ndo_vflag < 1)
41         return;
42 
43     for (idx = 0; idx < len; idx++) {
44         ND_TCHECK2(*(pptr+idx), 2);
45         if (EXTRACT_16BITS(pptr+idx) != 0x0d0a) { /* linefeed ? */
46             safeputchar(ndo, *(pptr + idx));
47         } else {
48             ND_PRINT((ndo, "\n\t"));
49             idx+=1;
50         }
51     }
52 
53     /* do we want to see an additionally hexdump ? */
54     if (ndo->ndo_vflag > 1)
55         print_unknown_data(ndo, pptr, "\n\t", len);
56 
57     return;
58 
59 trunc:
60     ND_PRINT((ndo, "[|sip]"));
61 }
62