Rev 4726 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4726 | Rev 4736 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2009 Lukas Mejdrech |
2 | * Copyright (c) 2009 Lukas Mejdrech |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
13 | * documentation and/or other materials provided with the distribution. |
14 | * - The name of the author may not be used to endorse or promote products |
14 | * - The name of the author may not be used to endorse or promote products |
15 | * derived from this software without specific prior written permission. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | /** @addtogroup net_app |
29 | /** @addtogroup net_app |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | 32 | ||
33 | /** @file |
33 | /** @file |
34 | * Generic application error printing functions implementation. |
34 | * Generic application error printing functions implementation. |
35 | */ |
35 | */ |
36 | 36 | ||
37 | #include <stdio.h> |
37 | #include <stdio.h> |
38 | 38 | ||
39 | #include "../include/icmp_codes.h" |
39 | #include "../include/icmp_codes.h" |
40 | #include "../include/socket_errno.h" |
40 | #include "../include/socket_errno.h" |
41 | 41 | ||
42 | #include "print_error.h" |
42 | #include "print_error.h" |
43 | 43 | ||
44 | void print_error( FILE * output, int error_code, const char * prefix, const char * suffix ){ |
44 | void print_error( FILE * output, int error_code, const char * prefix, const char * suffix ){ |
45 | if( IS_ICMP_ERROR( error_code )){ |
45 | if( IS_ICMP_ERROR( error_code )){ |
46 | icmp_print_error( output, error_code, prefix, suffix ); |
46 | icmp_print_error( output, error_code, prefix, suffix ); |
47 | }else if( IS_SOCKET_ERROR( error_code )){ |
47 | }else if( IS_SOCKET_ERROR( error_code )){ |
48 | socket_print_error( output, error_code, prefix, suffix ); |
48 | socket_print_error( output, error_code, prefix, suffix ); |
49 | } |
49 | } |
50 | } |
50 | } |
51 | 51 | ||
52 | void icmp_print_error( FILE * output, int error_code, const char * prefix, const char * suffix ){ |
52 | void icmp_print_error( FILE * output, int error_code, const char * prefix, const char * suffix ){ |
53 | if( output ){ |
53 | if( output ){ |
54 | if( prefix ){ |
54 | if( prefix ){ |
55 | fprintf( output, "%s", prefix ); |
55 | fprintf( output, "%s", prefix ); |
56 | } |
56 | } |
57 | switch( error_code ){ |
57 | switch( error_code ){ |
58 | case ICMP_DEST_UNREACH: |
58 | case ICMP_DEST_UNREACH: |
59 | fprintf( output, "ICMP Destination Unreachable (%d) error", error_code ); |
59 | fprintf( output, "ICMP Destination Unreachable (%d) error", error_code ); |
60 | break; |
60 | break; |
61 | case ICMP_SOURCE_QUENCH: |
61 | case ICMP_SOURCE_QUENCH: |
62 | fprintf( output, "ICMP Source Quench (%d) error", error_code ); |
62 | fprintf( output, "ICMP Source Quench (%d) error", error_code ); |
63 | break; |
63 | break; |
64 | case ICMP_REDIRECT: |
64 | case ICMP_REDIRECT: |
65 | fprintf( output, "ICMP Redirect (%d) error", error_code ); |
65 | fprintf( output, "ICMP Redirect (%d) error", error_code ); |
66 | break; |
66 | break; |
67 | case ICMP_ALTERNATE_ADDR: |
67 | case ICMP_ALTERNATE_ADDR: |
68 | fprintf( output, "ICMP Alternate Host Address (%d) error", error_code ); |
68 | fprintf( output, "ICMP Alternate Host Address (%d) error", error_code ); |
69 | break; |
69 | break; |
70 | case ICMP_ROUTER_ADV: |
70 | case ICMP_ROUTER_ADV: |
71 | fprintf( output, "ICMP Router Advertisement (%d) error", error_code ); |
71 | fprintf( output, "ICMP Router Advertisement (%d) error", error_code ); |
72 | break; |
72 | break; |
73 | case ICMP_ROUTER_SOL: |
73 | case ICMP_ROUTER_SOL: |
74 | fprintf( output, "ICMP Router Solicitation (%d) error", error_code ); |
74 | fprintf( output, "ICMP Router Solicitation (%d) error", error_code ); |
75 | break; |
75 | break; |
76 | case ICMP_TIME_EXCEEDED: |
76 | case ICMP_TIME_EXCEEDED: |
77 | fprintf( output, "ICMP Time Exceeded (%d) error", error_code ); |
77 | fprintf( output, "ICMP Time Exceeded (%d) error", error_code ); |
78 | break; |
78 | break; |
79 | case ICMP_PARAMETERPROB: |
79 | case ICMP_PARAMETERPROB: |
80 | fprintf( output, "ICMP Paramenter Problem (%d) error", error_code ); |
80 | fprintf( output, "ICMP Paramenter Problem (%d) error", error_code ); |
81 | break; |
81 | break; |
82 | case ICMP_CONVERSION_ERROR: |
82 | case ICMP_CONVERSION_ERROR: |
83 | fprintf( output, "ICMP Datagram Conversion Error (%d) error", error_code ); |
83 | fprintf( output, "ICMP Datagram Conversion Error (%d) error", error_code ); |
84 | break; |
84 | break; |
85 | case ICMP_REDIRECT_MOBILE: |
85 | case ICMP_REDIRECT_MOBILE: |
86 | fprintf( output, "ICMP Mobile Host Redirect (%d) error", error_code ); |
86 | fprintf( output, "ICMP Mobile Host Redirect (%d) error", error_code ); |
87 | break; |
87 | break; |
88 | case ICMP_SKIP: |
88 | case ICMP_SKIP: |
89 | fprintf( output, "ICMP SKIP (%d) error", error_code ); |
89 | fprintf( output, "ICMP SKIP (%d) error", error_code ); |
90 | break; |
90 | break; |
91 | case ICMP_PHOTURIS: |
91 | case ICMP_PHOTURIS: |
92 | fprintf( output, "ICMP Photuris (%d) error", error_code ); |
92 | fprintf( output, "ICMP Photuris (%d) error", error_code ); |
93 | break; |
93 | break; |
94 | default: |
94 | default: |
95 | fprintf( output, "Other (%d) error", error_code ); |
95 | fprintf( output, "Other (%d) error", error_code ); |
96 | } |
96 | } |
97 | if( suffix ){ |
97 | if( suffix ){ |
98 | fprintf( output, "%s", suffix ); |
98 | fprintf( output, "%s", suffix ); |
99 | } |
99 | } |
100 | } |
100 | } |
101 | } |
101 | } |
102 | 102 | ||
103 | void socket_print_error( FILE * output, int error_code, const char * prefix, const char * suffix ){ |
103 | void socket_print_error( FILE * output, int error_code, const char * prefix, const char * suffix ){ |
104 | if( output ){ |
104 | if( output ){ |
105 | if( prefix ){ |
105 | if( prefix ){ |
106 | fprintf( output, "%s", prefix ); |
106 | fprintf( output, "%s", prefix ); |
107 | } |
107 | } |
108 | switch( error_code ){ |
108 | switch( error_code ){ |
109 | case ENOTSOCK: |
109 | case ENOTSOCK: |
110 | fprintf( output, "Not a socket (%d) error", error_code ); |
110 | fprintf( output, "Not a socket (%d) error", error_code ); |
111 | break; |
111 | break; |
112 | case EPROTONOSUPPORT: |
112 | case EPROTONOSUPPORT: |
113 | fprintf( output, "Protocol not supported (%d) error", error_code ); |
113 | fprintf( output, "Protocol not supported (%d) error", error_code ); |
114 | break; |
114 | break; |
115 | case ESOCKTNOSUPPORT: |
115 | case ESOCKTNOSUPPORT: |
116 | fprintf( output, "Socket type not supported (%d) error", error_code ); |
116 | fprintf( output, "Socket type not supported (%d) error", error_code ); |
117 | break; |
117 | break; |
118 | case EPFNOSUPPORT: |
118 | case EPFNOSUPPORT: |
119 | fprintf( output, "Protocol family not supported (%d) error", error_code ); |
119 | fprintf( output, "Protocol family not supported (%d) error", error_code ); |
120 | break; |
120 | break; |
121 | case EAFNOSUPPORT: |
121 | case EAFNOSUPPORT: |
122 | fprintf( output, "Address family not supported (%d) error", error_code ); |
122 | fprintf( output, "Address family not supported (%d) error", error_code ); |
123 | break; |
123 | break; |
124 | case EADDRINUSE: |
124 | case EADDRINUSE: |
125 | fprintf( output, "Address already in use (%d) error", error_code ); |
125 | fprintf( output, "Address already in use (%d) error", error_code ); |
126 | break; |
126 | break; |
127 | case ENOTCONN: |
127 | case ENOTCONN: |
128 | fprintf( output, "Socket not connected (%d) error", error_code ); |
128 | fprintf( output, "Socket not connected (%d) error", error_code ); |
129 | break; |
129 | break; |
130 | case NO_DATA: |
130 | case NO_DATA: |
131 | fprintf( output, "No data (%d) error", error_code ); |
131 | fprintf( output, "No data (%d) error", error_code ); |
132 | break; |
132 | break; |
133 | case EINPROGRESS: |
133 | case EINPROGRESS: |
134 | fprintf( output, "Another operation in progress (%d) error", error_code ); |
134 | fprintf( output, "Another operation in progress (%d) error", error_code ); |
135 | break; |
135 | break; |
- | 136 | case EDESTADDRREQ: |
|
- | 137 | fprintf( output, "Destination address required (%d) error", error_code ); |
|
136 | default: |
138 | default: |
137 | fprintf( output, "Other (%d) error", error_code ); |
139 | fprintf( output, "Other (%d) error", error_code ); |
138 | } |
140 | } |
139 | if( suffix ){ |
141 | if( suffix ){ |
140 | fprintf( output, "%s", suffix ); |
142 | fprintf( output, "%s", suffix ); |
141 | } |
143 | } |
142 | } |
144 | } |
143 | } |
145 | } |
144 | 146 | ||
145 | /** @} |
147 | /** @} |
146 | */ |
148 | */ |
147 | 149 |