source: mainline/uspace/app/netecho/print_error.c@ c6533a7

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since c6533a7 was c6533a7, checked in by Jiri Svoboda <jiri@…>, 13 years ago

Remove most of net-related code from libnet and libc, except parts which are
presumably needed to implement sockets. Socket implementation will be replaced
later. NIC drivers should not include/link libnet.

  • Property mode set to 100644
File size: 3.7 KB
Line 
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 "print_error.h"
38
39#include <stdio.h>
40#include <errno.h>
41
42/** Prints the error description.
43 *
44 * Supports socket error codes.
45 *
46 * @param[in] output The description output stream. May be NULL.
47 * @param[in] error_code The 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 print_error(FILE *output, int error_code, const char *prefix, const char *suffix)
52{
53 if(IS_SOCKET_ERROR(error_code))
54 socket_print_error(output, error_code, prefix, suffix);
55}
56
57/** Prints the specific socket error description.
58 *
59 * @param[in] output The description output stream. May be NULL.
60 * @param[in] error_code The socket error code.
61 * @param[in] prefix The error description prefix. May be NULL.
62 * @param[in] suffix The error description suffix. May be NULL.
63 */
64void socket_print_error(FILE *output, int error_code, const char *prefix, const char *suffix)
65{
66 if (!output)
67 return;
68
69 if (prefix)
70 fprintf(output, "%s", prefix);
71
72 switch (error_code) {
73 case ENOTSOCK:
74 fprintf(output, "Not a socket (%d) error", error_code);
75 break;
76 case EPROTONOSUPPORT:
77 fprintf(output, "Protocol not supported (%d) error", error_code);
78 break;
79 case ESOCKTNOSUPPORT:
80 fprintf(output, "Socket type not supported (%d) error", error_code);
81 break;
82 case EPFNOSUPPORT:
83 fprintf(output, "Protocol family not supported (%d) error", error_code);
84 break;
85 case EAFNOSUPPORT:
86 fprintf(output, "Address family not supported (%d) error", error_code);
87 break;
88 case EADDRINUSE:
89 fprintf(output, "Address already in use (%d) error", error_code);
90 break;
91 case ENOTCONN:
92 fprintf(output, "Socket not connected (%d) error", error_code);
93 break;
94 case NO_DATA:
95 fprintf(output, "No data (%d) error", error_code);
96 break;
97 case EINPROGRESS:
98 fprintf(output, "Another operation in progress (%d) error", error_code);
99 break;
100 case EDESTADDRREQ:
101 fprintf(output, "Destination address required (%d) error", error_code);
102 case EAGAIN:
103 fprintf(output, "Try again (%d) error", error_code);
104 default:
105 fprintf(output, "Other (%d) error", error_code);
106 }
107
108 if (suffix)
109 fprintf(output, "%s", suffix);
110}
111
112/** @}
113 */
114
Note: See TracBrowser for help on using the repository browser.