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