Changeset a8e5051 in mainline for uspace/app/netecho/print_error.c


Ignore:
Timestamp:
2010-11-03T19:51:15Z (13 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
3d459fc
Parents:
d0d1f4f
Message:

Gently cleanup netecho.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/netecho/print_error.c

    rd0d1f4f ra8e5051  
    2828
    2929/** @addtogroup net_app
    30  *  @{
     30 * @{
    3131 */
    3232
    3333/** @file
    34  *  Generic application error printing functions implementation.
     34 * Generic application error printing functions implementation.
    3535 */
     36
     37#include "print_error.h"
    3638
    3739#include <stdio.h>
     
    4042#include <net/icmp_codes.h>
    4143
    42 #include "print_error.h"
     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);
     98        }
    4399
    44 void 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);
    48                 }
    49                 switch(error_code){
    50                         case ICMP_DEST_UNREACH:
    51                                 fprintf(output, "ICMP Destination Unreachable (%d) error", error_code);
    52                                 break;
    53                         case ICMP_SOURCE_QUENCH:
    54                                 fprintf(output, "ICMP Source Quench (%d) error", error_code);
    55                                 break;
    56                         case ICMP_REDIRECT:
    57                                 fprintf(output, "ICMP Redirect (%d) error", error_code);
    58                                 break;
    59                         case ICMP_ALTERNATE_ADDR:
    60                                 fprintf(output, "ICMP Alternate Host Address (%d) error", error_code);
    61                                 break;
    62                         case ICMP_ROUTER_ADV:
    63                                 fprintf(output, "ICMP Router Advertisement (%d) error", error_code);
    64                                 break;
    65                         case ICMP_ROUTER_SOL:
    66                                 fprintf(output, "ICMP Router Solicitation (%d) error", error_code);
    67                                 break;
    68                         case ICMP_TIME_EXCEEDED:
    69                                 fprintf(output, "ICMP Time Exceeded (%d) error", error_code);
    70                                 break;
    71                         case ICMP_PARAMETERPROB:
    72                                 fprintf(output, "ICMP Paramenter Problem (%d) error", error_code);
    73                                 break;
    74                         case ICMP_CONVERSION_ERROR:
    75                                 fprintf(output, "ICMP Datagram Conversion Error (%d) error", error_code);
    76                                 break;
    77                         case ICMP_REDIRECT_MOBILE:
    78                                 fprintf(output, "ICMP Mobile Host Redirect (%d) error", error_code);
    79                                 break;
    80                         case ICMP_SKIP:
    81                                 fprintf(output, "ICMP SKIP (%d) error", error_code);
    82                                 break;
    83                         case ICMP_PHOTURIS:
    84                                 fprintf(output, "ICMP Photuris (%d) error", error_code);
    85                                 break;
    86                         default:
    87                                 fprintf(output, "Other (%d) error", error_code);
    88                 }
    89                 if(suffix){
    90                         fprintf(output, "%s", suffix);
    91                 }
    92         }
     100        if (suffix)
     101                fprintf(output, "%s", suffix);
    93102}
    94103
    95 void print_error(FILE * output, int error_code, const char * prefix, const char * suffix){
    96         if(IS_ICMP_ERROR(error_code)){
     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))
    97116                icmp_print_error(output, error_code, prefix, suffix);
    98         }else if(IS_SOCKET_ERROR(error_code)){
     117        else if(IS_SOCKET_ERROR(error_code))
    99118                socket_print_error(output, error_code, prefix, suffix);
    100         }
    101119}
    102120
    103 void 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);
    107                 }
    108                 switch(error_code){
    109                         case ENOTSOCK:
    110                                 fprintf(output, "Not a socket (%d) error", error_code);
    111                                 break;
    112                         case EPROTONOSUPPORT:
    113                                 fprintf(output, "Protocol not supported (%d) error", error_code);
    114                                 break;
    115                         case ESOCKTNOSUPPORT:
    116                                 fprintf(output, "Socket type not supported (%d) error", error_code);
    117                                 break;
    118                         case EPFNOSUPPORT:
    119                                 fprintf(output, "Protocol family not supported (%d) error", error_code);
    120                                 break;
    121                         case EAFNOSUPPORT:
    122                                 fprintf(output, "Address family not supported (%d) error", error_code);
    123                                 break;
    124                         case EADDRINUSE:
    125                                 fprintf(output, "Address already in use (%d) error", error_code);
    126                                 break;
    127                         case ENOTCONN:
    128                                 fprintf(output, "Socket not connected (%d) error", error_code);
    129                                 break;
    130                         case NO_DATA:
    131                                 fprintf(output, "No data (%d) error", error_code);
    132                                 break;
    133                         case EINPROGRESS:
    134                                 fprintf(output, "Another operation in progress (%d) error", error_code);
    135                                 break;
    136                         case EDESTADDRREQ:
    137                                 fprintf(output, "Destination address required (%d) error", error_code);
    138                         case TRY_AGAIN:
    139                                 fprintf(output, "Try again (%d) error", error_code);
    140                         default:
    141                                 fprintf(output, "Other (%d) error", error_code);
    142                 }
    143                 if(suffix){
    144                         fprintf(output, "%s", suffix);
    145                 }
     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);
    146170        }
     171
     172        if (suffix)
     173                fprintf(output, "%s", suffix);
    147174}
    148175
    149176/** @}
    150177 */
     178
Note: See TracChangeset for help on using the changeset viewer.