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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 60ab6c3 was 3be62bc, checked in by Lukas Mejdrech <lukasmejdrech@…>, 15 years ago
  • net app command line argument checks, * code reorganization
  • 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 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);
[21580dd]48 }
[aadf01e]49 switch(error_code){
[21580dd]50 case ICMP_DEST_UNREACH:
[aadf01e]51 fprintf(output, "ICMP Destination Unreachable (%d) error", error_code);
[21580dd]52 break;
53 case ICMP_SOURCE_QUENCH:
[aadf01e]54 fprintf(output, "ICMP Source Quench (%d) error", error_code);
[21580dd]55 break;
56 case ICMP_REDIRECT:
[aadf01e]57 fprintf(output, "ICMP Redirect (%d) error", error_code);
[21580dd]58 break;
59 case ICMP_ALTERNATE_ADDR:
[aadf01e]60 fprintf(output, "ICMP Alternate Host Address (%d) error", error_code);
[21580dd]61 break;
62 case ICMP_ROUTER_ADV:
[aadf01e]63 fprintf(output, "ICMP Router Advertisement (%d) error", error_code);
[21580dd]64 break;
65 case ICMP_ROUTER_SOL:
[aadf01e]66 fprintf(output, "ICMP Router Solicitation (%d) error", error_code);
[21580dd]67 break;
68 case ICMP_TIME_EXCEEDED:
[aadf01e]69 fprintf(output, "ICMP Time Exceeded (%d) error", error_code);
[21580dd]70 break;
71 case ICMP_PARAMETERPROB:
[aadf01e]72 fprintf(output, "ICMP Paramenter Problem (%d) error", error_code);
[21580dd]73 break;
74 case ICMP_CONVERSION_ERROR:
[aadf01e]75 fprintf(output, "ICMP Datagram Conversion Error (%d) error", error_code);
[21580dd]76 break;
77 case ICMP_REDIRECT_MOBILE:
[aadf01e]78 fprintf(output, "ICMP Mobile Host Redirect (%d) error", error_code);
[21580dd]79 break;
80 case ICMP_SKIP:
[aadf01e]81 fprintf(output, "ICMP SKIP (%d) error", error_code);
[21580dd]82 break;
83 case ICMP_PHOTURIS:
[aadf01e]84 fprintf(output, "ICMP Photuris (%d) error", error_code);
[21580dd]85 break;
86 default:
[aadf01e]87 fprintf(output, "Other (%d) error", error_code);
[21580dd]88 }
[aadf01e]89 if(suffix){
90 fprintf(output, "%s", suffix);
[21580dd]91 }
92 }
93}
94
[3be62bc]95void 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
[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.