Subversion Repositories HelenOS

Rev

Rev 4720 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  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.  
  44. void 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 );
  49.     }
  50. }
  51.  
  52. void 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 );
  56.         }
  57.         switch( error_code ){
  58.             case ICMP_DEST_UNREACH:
  59.                 fprintf( output, "ICMP Destination Unreachable (%d) error", error_code );
  60.                 break;
  61.             case ICMP_SOURCE_QUENCH:
  62.                 fprintf( output, "ICMP Source Quench (%d) error", error_code );
  63.                 break;
  64.             case ICMP_REDIRECT:
  65.                 fprintf( output, "ICMP Redirect (%d) error", error_code );
  66.                 break;
  67.             case ICMP_ALTERNATE_ADDR:
  68.                 fprintf( output, "ICMP Alternate Host Address (%d) error", error_code );
  69.                 break;
  70.             case ICMP_ROUTER_ADV:
  71.                 fprintf( output, "ICMP Router Advertisement (%d) error", error_code );
  72.                 break;
  73.             case ICMP_ROUTER_SOL:
  74.                 fprintf( output, "ICMP Router Solicitation (%d) error", error_code );
  75.                 break;
  76.             case ICMP_TIME_EXCEEDED:
  77.                 fprintf( output, "ICMP Time Exceeded (%d) error", error_code );
  78.                 break;
  79.             case ICMP_PARAMETERPROB:
  80.                 fprintf( output, "ICMP Paramenter Problem (%d) error", error_code );
  81.                 break;
  82.             case ICMP_CONVERSION_ERROR:
  83.                 fprintf( output, "ICMP Datagram Conversion Error (%d) error", error_code );
  84.                 break;
  85.             case ICMP_REDIRECT_MOBILE:
  86.                 fprintf( output, "ICMP Mobile Host Redirect (%d) error", error_code );
  87.                 break;
  88.             case ICMP_SKIP:
  89.                 fprintf( output, "ICMP SKIP (%d) error", error_code );
  90.                 break;
  91.             case ICMP_PHOTURIS:
  92.                 fprintf( output, "ICMP Photuris (%d) error", error_code );
  93.                 break;
  94.             default:
  95.                 fprintf( output, "Other (%d) error", error_code );
  96.         }
  97.         if( suffix ){
  98.             fprintf( output, "%s", suffix );
  99.         }
  100.     }
  101. }
  102.  
  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.             default:
  137.                 fprintf( output, "Other (%d) error", error_code );
  138.         }
  139.         if( suffix ){
  140.             fprintf( output, "%s", suffix );
  141.         }
  142.     }
  143. }
  144.  
  145. /** @}
  146.  */
  147.