source: mainline/uspace/app/netecho/print_error.c@ 7ae3d6f

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 7ae3d6f was a8e5051, checked in by Jakub Jermar <jakub@…>, 15 years ago

Gently cleanup netecho.

  • Property mode set to 100644
File size: 5.6 KB
RevLine 
[21580dd]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
[a8e5051]30 * @{
[21580dd]31 */
32
33/** @file
[a8e5051]34 * Generic application error printing functions implementation.
[21580dd]35 */
36
[a8e5051]37#include "print_error.h"
38
[21580dd]39#include <stdio.h>
[e98b1d5]40#include <errno.h>
[21580dd]41
[753bca3]42#include <net/icmp_codes.h>
[21580dd]43
[a8e5051]44/** Prints the specific ICMP error description.
45 *
46 * @param[in] output The description output stream. May be NULL.
47 * @param[in] error_code The ICMP error code.
48 * @param[in] prefix The error description prefix. May be NULL.
49 * @param[in] suffix The error description suffix. May be NULL.
50 */
51void icmp_print_error(FILE *output, int error_code, const char *prefix, const char *suffix)
52{
53 if (!output)
54 return;
55
56 if (prefix)
57 fprintf(output, "%s", prefix);
58
59 switch (error_code) {
60 case ICMP_DEST_UNREACH:
61 fprintf(output, "ICMP Destination Unreachable (%d) error", error_code);
62 break;
63 case ICMP_SOURCE_QUENCH:
64 fprintf(output, "ICMP Source Quench (%d) error", error_code);
65 break;
66 case ICMP_REDIRECT:
67 fprintf(output, "ICMP Redirect (%d) error", error_code);
68 break;
69 case ICMP_ALTERNATE_ADDR:
70 fprintf(output, "ICMP Alternate Host Address (%d) error", error_code);
71 break;
72 case ICMP_ROUTER_ADV:
73 fprintf(output, "ICMP Router Advertisement (%d) error", error_code);
74 break;
75 case ICMP_ROUTER_SOL:
76 fprintf(output, "ICMP Router Solicitation (%d) error", error_code);
77 break;
78 case ICMP_TIME_EXCEEDED:
79 fprintf(output, "ICMP Time Exceeded (%d) error", error_code);
80 break;
81 case ICMP_PARAMETERPROB:
82 fprintf(output, "ICMP Paramenter Problem (%d) error", error_code);
83 break;
84 case ICMP_CONVERSION_ERROR:
85 fprintf(output, "ICMP Datagram Conversion Error (%d) error", error_code);
86 break;
87 case ICMP_REDIRECT_MOBILE:
88 fprintf(output, "ICMP Mobile Host Redirect (%d) error", error_code);
89 break;
90 case ICMP_SKIP:
91 fprintf(output, "ICMP SKIP (%d) error", error_code);
92 break;
93 case ICMP_PHOTURIS:
94 fprintf(output, "ICMP Photuris (%d) error", error_code);
95 break;
96 default:
97 fprintf(output, "Other (%d) error", error_code);
[21580dd]98 }
[a8e5051]99
100 if (suffix)
101 fprintf(output, "%s", suffix);
[21580dd]102}
103
[a8e5051]104/** Prints the error description.
105 *
106 * Supports ICMP and socket error codes.
107 *
108 * @param[in] output The description output stream. May be NULL.
109 * @param[in] error_code The error code.
110 * @param[in] prefix The error description prefix. May be NULL.
111 * @param[in] suffix The error description suffix. May be NULL.
112 */
113void print_error(FILE *output, int error_code, const char *prefix, const char *suffix)
114{
115 if (IS_ICMP_ERROR(error_code))
[3be62bc]116 icmp_print_error(output, error_code, prefix, suffix);
[a8e5051]117 else if(IS_SOCKET_ERROR(error_code))
[3be62bc]118 socket_print_error(output, error_code, prefix, suffix);
119}
120
[a8e5051]121/** Prints the specific socket error description.
122 *
123 * @param[in] output The description output stream. May be NULL.
124 * @param[in] error_code The socket error code.
125 * @param[in] prefix The error description prefix. May be NULL.
126 * @param[in] suffix The error description suffix. May be NULL.
127 */
128void socket_print_error(FILE *output, int error_code, const char *prefix, const char *suffix)
129{
130 if (!output)
131 return;
132
133 if (prefix)
134 fprintf(output, "%s", prefix);
135
136 switch (error_code) {
137 case ENOTSOCK:
138 fprintf(output, "Not a socket (%d) error", error_code);
139 break;
140 case EPROTONOSUPPORT:
141 fprintf(output, "Protocol not supported (%d) error", error_code);
142 break;
143 case ESOCKTNOSUPPORT:
144 fprintf(output, "Socket type not supported (%d) error", error_code);
145 break;
146 case EPFNOSUPPORT:
147 fprintf(output, "Protocol family not supported (%d) error", error_code);
148 break;
149 case EAFNOSUPPORT:
150 fprintf(output, "Address family not supported (%d) error", error_code);
151 break;
152 case EADDRINUSE:
153 fprintf(output, "Address already in use (%d) error", error_code);
154 break;
155 case ENOTCONN:
156 fprintf(output, "Socket not connected (%d) error", error_code);
157 break;
158 case NO_DATA:
159 fprintf(output, "No data (%d) error", error_code);
160 break;
161 case EINPROGRESS:
162 fprintf(output, "Another operation in progress (%d) error", error_code);
163 break;
164 case EDESTADDRREQ:
165 fprintf(output, "Destination address required (%d) error", error_code);
166 case TRY_AGAIN:
167 fprintf(output, "Try again (%d) error", error_code);
168 default:
169 fprintf(output, "Other (%d) error", error_code);
[21580dd]170 }
[a8e5051]171
172 if (suffix)
173 fprintf(output, "%s", suffix);
[21580dd]174}
175
176/** @}
177 */
[a8e5051]178
Note: See TracBrowser for help on using the repository browser.