1 
2 /*-------------------------------------------------------------*/
3 /***************************************************************
4  * An array permits to show a packet. Generally, one line      *
5  * corresponds to 32bits/4bytes, as seen in RFCs               *
6  ***************************************************************/
7 /*
8 For example :
9 ._______________________________________________________________.
10 |0|1|1|0|0|1|1|0|0|1|1|0|0|1|1|0|0|1|1|0|0|1|1|0|0|1|1|0|0|1|1|0|
11 |_3_|_3_|_3_|_3_|_3_|_3_|_3_|_3_|_3_|_3_|_3_|_3_|_3_|_3_|_3_|_3_|
12 |0xF=15_|__0xF__|__15___|0xF=15_|__0xF__|__15___|0xF=15_|__0xF__|
13 |_0x80=128='c'__|_0x80=128='c'__|_0x80=128='c'__|_0x80=128='c'__|
14 | data: 0123456789012345678901234567890123456789012345678901234 |
15 |       0123456789012345678901234567890123456789012345678901234 |
16 |_______________________________________________________________|
17 
18 Ethernet________________________________________________________.
19 | 00:00:01:02:03:04->00:00:05:06:97:08 type:0x0800              |
20 |_______________________________________________________________|
21 IP______________________________________________________________.
22 |version|  ihl  |      tos      |            totlen             |
23 |___4___|___5___|____0x00=0_____|___________0x0054=84___________|
24 |              id               |r|D|M|       offsetfrag        |
25 |___________0x0008=8____________|0|0|0|________0x0000=0_________|
26 |      ttl      |   protocol    |           checksum            |
27 |___0xFF=255____|____0x01=1_____|____________0x2551_____________|
28 |                            source                             |
29 |_________________________192.168.1.1___________________________|
30 |                          destination                          |
31 |_________________________192.168.1.2___________________________|
32 ICMP4_echo reply________________________________________________.
33 |     type      |     code      |           checksum            |
34 |____0x00=0_____|____0x00=0_____|_________0xC6A9=50857__________|
35 
36 */
37 
38 /*-------------------------------------------------------------*/
39 /* "._________________." or "Title_____________." */
40 netwib_err netwib_show_array_head(netwib_conststring title,
41                                   netwib_buf *pbuf);
42 /* "|_________________|" */
43 netwib_err netwib_show_array_tail(netwib_buf *pbuf);
44 
45 /*-------------------------------------------------------------*/
46 /* "|" */
47 netwib_err netwib_show_array_line_begin(netwib_buf *pbuf);
48 /* "\n" */
49 netwib_err netwib_show_array_line_end(netwib_buf *pbuf);
50 
51 /*-------------------------------------------------------------*/
52 /* centered text surrounded by spaces and ending with "|" */
53 netwib_err netwib_show_array_text(netwib_uint32 size,
54                                   netwib_conststring txt,
55                                   netwib_buf *pbuf);
56 /* num32 is special : line_begin and line_end are internally called */
57 #define netwib_show_array_text32(text,pbuf) netwib_show_array_text(32,text,pbuf)
58 #define netwib_show_array_text16(text,pbuf) netwib_show_array_text(16,text,pbuf)
59 #define netwib_show_array_text8(text,pbuf) netwib_show_array_text(8,text,pbuf)
60 #define netwib_show_array_text4(text,pbuf) netwib_show_array_text(4,text,pbuf)
61 #define netwib_show_array_text1(text,pbuf) netwib_show_array_text(1,text,pbuf)
62 
63 /*-------------------------------------------------------------*/
64 /* centered number surrounded by "_" and ending with "|" */
65 typedef enum {
66   NETWIB_SHOW_ARRAY_NUMTYPE_BIN = 1,
67   NETWIB_SHOW_ARRAY_NUMTYPE_DEC,
68   NETWIB_SHOW_ARRAY_NUMTYPE_HEXA,
69   NETWIB_SHOW_ARRAY_NUMTYPE_CHAR,
70   NETWIB_SHOW_ARRAY_NUMTYPE_DECCHAR,
71   NETWIB_SHOW_ARRAY_NUMTYPE_HEXADEC,
72   NETWIB_SHOW_ARRAY_NUMTYPE_HEXACHAR,
73   NETWIB_SHOW_ARRAY_NUMTYPE_HEXADECCHAR
74 } netwib_show_array_numtype;
75 netwib_err netwib_show_array_num(netwib_uint32 size,
76                                  netwib_uint32 ui,
77                                  netwib_show_array_numtype type,
78                                  netwib_buf *pbuf);
79 /* num32 is special : line_begin and line_end are internally called */
80 #define netwib_show_array_num32(ui,type,pbuf) netwib_show_array_num(32,ui,type,pbuf)
81 #define netwib_show_array_num16(ui,type,pbuf) netwib_show_array_num(16,ui,type,pbuf)
82 #define netwib_show_array_num8(ui,type,pbuf) netwib_show_array_num(8,ui,type,pbuf)
83 #define netwib_show_array_num4(ui,type,pbuf) netwib_show_array_num(4,ui,type,pbuf)
84 #define netwib_show_array_num1(ui,pbuf) netwib_show_array_num(1,ui,NETWIB_SHOW_ARRAY_NUMTYPE_DEC,pbuf)
85 
86 /*-------------------------------------------------------------*/
87 typedef enum {
88   NETWIB_SHOW_ARRAY_ALIGN_LEFT,
89   NETWIB_SHOW_ARRAY_ALIGN_CENTER,
90   NETWIB_SHOW_ARRAY_ALIGN_RIGHT
91 } netwib_show_array_align;
92 /* if size==32, line_begin and line_end are internally called */
93 netwib_err netwib_show_array_fmt(netwib_uint32 size,
94                                  netwib_show_array_align align,
95                                  netwib_char fillchar, /* ie ' ' or '_' */
96                                  netwib_buf *pbuf,
97                                  netwib_conststring fmt,
98                                  ...);
99 /* size==32, align==NETWIB_SHOW_ARRAY_ALIGN_LEFT and fillchar==' ' */
100 netwib_err netwib_show_array_fmt32(netwib_buf *pbuf,
101                                    netwib_conststring fmt,
102                                    ...);
103 
104 /*-------------------------------------------------------------*/
105 /*
106  data wrapped to fit in the array. For example :
107     |title: 0123456789012345678901234567890123456789012 |
108     |       3456789012345678901234567801234567890123456 |
109     |_______567890123456789012345678____________________|
110 */
111 netwib_err netwib_show_array_data(netwib_conststring title,
112                                   netwib_constbuf *pdata,
113                                   netwib_encodetype encodetype,
114                                   netwib_char fillchar, /* ie ' ' or '_' */
115                                   netwib_buf *pbuf);
116