00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00037 #include "print_error.h"
00038
00039 #include <stdio.h>
00040 #include <errno.h>
00041
00042 #include <net/icmp_codes.h>
00043
00051 void icmp_print_error(FILE *output, int error_code, const char *prefix, const char *suffix)
00052 {
00053 if (!output)
00054 return;
00055
00056 if (prefix)
00057 fprintf(output, "%s", prefix);
00058
00059 switch (error_code) {
00060 case ICMP_DEST_UNREACH:
00061 fprintf(output, "ICMP Destination Unreachable (%d) error", error_code);
00062 break;
00063 case ICMP_SOURCE_QUENCH:
00064 fprintf(output, "ICMP Source Quench (%d) error", error_code);
00065 break;
00066 case ICMP_REDIRECT:
00067 fprintf(output, "ICMP Redirect (%d) error", error_code);
00068 break;
00069 case ICMP_ALTERNATE_ADDR:
00070 fprintf(output, "ICMP Alternate Host Address (%d) error", error_code);
00071 break;
00072 case ICMP_ROUTER_ADV:
00073 fprintf(output, "ICMP Router Advertisement (%d) error", error_code);
00074 break;
00075 case ICMP_ROUTER_SOL:
00076 fprintf(output, "ICMP Router Solicitation (%d) error", error_code);
00077 break;
00078 case ICMP_TIME_EXCEEDED:
00079 fprintf(output, "ICMP Time Exceeded (%d) error", error_code);
00080 break;
00081 case ICMP_PARAMETERPROB:
00082 fprintf(output, "ICMP Paramenter Problem (%d) error", error_code);
00083 break;
00084 case ICMP_CONVERSION_ERROR:
00085 fprintf(output, "ICMP Datagram Conversion Error (%d) error", error_code);
00086 break;
00087 case ICMP_REDIRECT_MOBILE:
00088 fprintf(output, "ICMP Mobile Host Redirect (%d) error", error_code);
00089 break;
00090 case ICMP_SKIP:
00091 fprintf(output, "ICMP SKIP (%d) error", error_code);
00092 break;
00093 case ICMP_PHOTURIS:
00094 fprintf(output, "ICMP Photuris (%d) error", error_code);
00095 break;
00096 default:
00097 fprintf(output, "Other (%d) error", error_code);
00098 }
00099
00100 if (suffix)
00101 fprintf(output, "%s", suffix);
00102 }
00103
00113 void print_error(FILE *output, int error_code, const char *prefix, const char *suffix)
00114 {
00115 if (IS_ICMP_ERROR(error_code))
00116 icmp_print_error(output, error_code, prefix, suffix);
00117 else if(IS_SOCKET_ERROR(error_code))
00118 socket_print_error(output, error_code, prefix, suffix);
00119 }
00120
00128 void socket_print_error(FILE *output, int error_code, const char *prefix, const char *suffix)
00129 {
00130 if (!output)
00131 return;
00132
00133 if (prefix)
00134 fprintf(output, "%s", prefix);
00135
00136 switch (error_code) {
00137 case ENOTSOCK:
00138 fprintf(output, "Not a socket (%d) error", error_code);
00139 break;
00140 case EPROTONOSUPPORT:
00141 fprintf(output, "Protocol not supported (%d) error", error_code);
00142 break;
00143 case ESOCKTNOSUPPORT:
00144 fprintf(output, "Socket type not supported (%d) error", error_code);
00145 break;
00146 case EPFNOSUPPORT:
00147 fprintf(output, "Protocol family not supported (%d) error", error_code);
00148 break;
00149 case EAFNOSUPPORT:
00150 fprintf(output, "Address family not supported (%d) error", error_code);
00151 break;
00152 case EADDRINUSE:
00153 fprintf(output, "Address already in use (%d) error", error_code);
00154 break;
00155 case ENOTCONN:
00156 fprintf(output, "Socket not connected (%d) error", error_code);
00157 break;
00158 case NO_DATA:
00159 fprintf(output, "No data (%d) error", error_code);
00160 break;
00161 case EINPROGRESS:
00162 fprintf(output, "Another operation in progress (%d) error", error_code);
00163 break;
00164 case EDESTADDRREQ:
00165 fprintf(output, "Destination address required (%d) error", error_code);
00166 case EAGAIN:
00167 fprintf(output, "Try again (%d) error", error_code);
00168 default:
00169 fprintf(output, "Other (%d) error", error_code);
00170 }
00171
00172 if (suffix)
00173 fprintf(output, "%s", suffix);
00174 }
00175