source: mainline/uspace/srv/net/app/print_error.c@ aadf01e

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since aadf01e was aadf01e, checked in by Lukas Mejdrech <lukasmejdrech@…>, 15 years ago

Coding style (no functional change)

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