1 /*
2 NETWIB
3 Network library
4 Copyright(c) 1999-2010 Laurent Constantin
5 -----
6
7 Main server : http://www.laurentconstantin.com/
8 Backup server : http://laurentconstantin.free.fr/
9 [my current email address is on the web servers]
10
11 -----
12 This file is part of Netwib.
13
14 Netwib is free software: you can redistribute it and/or modify
15 it under the terms of the GNU General Public License version 3
16 as published by the Free Software Foundation.
17
18 Netwib is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details (http://www.gnu.org/).
22
23 ------------------------------------------------------------------------
24 */
25
26 #include <netwib/inc/maininc.h>
27
28 /*-------------------------------------------------------------*/
netwib_udphdr_show(netwib_constudphdr * pudphdr,netwib_encodetype encodetype,netwib_buf * pbuf)29 netwib_err netwib_udphdr_show(netwib_constudphdr *pudphdr,
30 netwib_encodetype encodetype,
31 netwib_buf *pbuf)
32 {
33 netwib_buf buf;
34
35 switch(encodetype) {
36 case NETWIB_ENCODETYPE_SYNTH :
37 netwib_er(netwib_buf_append_fmt(pbuf, "udp%{port}->%{port}",
38 pudphdr->src, pudphdr->dst));
39 break;
40 case NETWIB_ENCODETYPE_ARRAY :
41 netwib_er(netwib_show_array_head("UDP", pbuf));
42 netwib_er(netwib_show_array_line_begin(pbuf));
43 netwib_er(netwib_show_array_text16("source port", pbuf));
44 netwib_er(netwib_show_array_text16("destination port", pbuf));
45 netwib_er(netwib_show_array_line_end(pbuf));
46 netwib_er(netwib_show_array_line_begin(pbuf));
47 netwib_er(netwib_show_array_num16((netwib_uint16)pudphdr->src,
48 NETWIB_SHOW_ARRAY_NUMTYPE_HEXADEC,
49 pbuf));
50 netwib_er(netwib_show_array_num16((netwib_uint16)pudphdr->dst,
51 NETWIB_SHOW_ARRAY_NUMTYPE_HEXADEC,
52 pbuf));
53 netwib_er(netwib_show_array_line_end(pbuf));
54 netwib_er(netwib_show_array_line_begin(pbuf));
55 netwib_er(netwib_show_array_text16("length", pbuf));
56 netwib_er(netwib_show_array_text16("checksum", pbuf));
57 netwib_er(netwib_show_array_line_end(pbuf));
58 netwib_er(netwib_show_array_line_begin(pbuf));
59 netwib_er(netwib_show_array_num16(pudphdr->len,
60 NETWIB_SHOW_ARRAY_NUMTYPE_HEXADEC,
61 pbuf));
62 netwib_er(netwib_show_array_num16(pudphdr->check,
63 NETWIB_SHOW_ARRAY_NUMTYPE_HEXADEC,
64 pbuf));
65 netwib_er(netwib_show_array_line_end(pbuf));
66 break;
67 default :
68 netwib_er(netwib_buf_init_mallocdefault(&buf));
69 netwib_er(netwib_pkt_append_udphdr(pudphdr, &buf));
70 netwib_er(netwib_buf_encode(&buf, encodetype, pbuf));
71 netwib_er(netwib_buf_close(&buf));
72 break;
73 }
74
75 return(NETWIB_ERR_OK);
76 }
77