Changeset a8e5051 in mainline
- Timestamp:
- 2010-11-03T19:51:15Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 3d459fc
- Parents:
- d0d1f4f
- Location:
- uspace/app/netecho
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/netecho/netecho.c
rd0d1f4f ra8e5051 28 28 29 29 /** @addtogroup netecho 30 * 30 * @{ 31 31 */ 32 32 33 33 /** @file 34 * 35 * 34 * Network echo application. 35 * Answers received packets. 36 36 */ 37 37 … … 51 51 #include "print_error.h" 52 52 53 /** Network echo module name. 54 */ 53 /** Network echo module name. */ 55 54 #define NAME "Network Echo" 56 55 57 /** Prints the application help. 58 */ 59 void echo_print_help(void); 60 61 /** Module entry point. 62 * Reads command line parameters and starts listenning. 63 * @param[in] argc The number of command line parameters. 64 * @param[in] argv The command line parameters. 65 * @returns EOK on success. 66 */ 67 int main(int argc, char * argv[]); 68 69 void echo_print_help(void){ 56 static void echo_print_help(void) 57 { 70 58 printf( 71 59 "Network Echo aplication\n" \ … … 101 89 } 102 90 103 int main(int argc, char * argv[]){ 91 int main(int argc, char *argv[]) 92 { 104 93 ERROR_DECLARE; 105 94 106 size_t size 107 int verbose 108 char * reply= NULL;109 sock_type_t type 110 int count 111 int family 112 uint16_t port 113 int backlog 114 115 socklen_t max_length 95 size_t size = 1024; 96 int verbose = 0; 97 char *reply = NULL; 98 sock_type_t type = SOCK_DGRAM; 99 int count = -1; 100 int family = PF_INET; 101 uint16_t port = 7; 102 int backlog = 3; 103 104 socklen_t max_length = sizeof(struct sockaddr_in6); 116 105 uint8_t address_data[max_length]; 117 struct sockaddr * address= (struct sockaddr *) address_data;118 struct sockaddr_in * address_in= (struct sockaddr_in *) address;119 struct sockaddr_in6 * address_in6= (struct sockaddr_in6 *) address;106 struct sockaddr *address = (struct sockaddr *) address_data; 107 struct sockaddr_in *address_in = (struct sockaddr_in *) address; 108 struct sockaddr_in6 *address_in6 = (struct sockaddr_in6 *) address; 120 109 socklen_t addrlen; 121 110 char address_string[INET6_ADDRSTRLEN]; 122 uint8_t * 111 uint8_t *address_start; 123 112 int socket_id; 124 113 int listening_id; 125 char * 114 char *data; 126 115 size_t length; 127 116 int index; … … 130 119 131 120 // parse the command line arguments 132 for(index = 1; index < argc; ++ index){ 133 if(argv[index][0] == '-'){ 134 switch(argv[index][1]){ 135 case 'b': 136 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &backlog, 0)); 137 break; 138 case 'c': 139 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &count, 0)); 140 break; 141 case 'f': 142 ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &family, 0, socket_parse_protocol_family)); 143 break; 144 case 'h': 121 for (index = 1; index < argc; ++ index) { 122 if (argv[index][0] == '-') { 123 switch (argv[index][1]) { 124 case 'b': 125 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &backlog, 0)); 126 break; 127 case 'c': 128 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &count, 0)); 129 break; 130 case 'f': 131 ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &family, 0, socket_parse_protocol_family)); 132 break; 133 case 'h': 134 echo_print_help(); 135 return EOK; 136 break; 137 case 'p': 138 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 0)); 139 port = (uint16_t) value; 140 break; 141 case 'r': 142 ERROR_PROPAGATE(arg_parse_string(argc, argv, &index, &reply, 0)); 143 break; 144 case 's': 145 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 0)); 146 size = (value >= 0) ? (size_t) value : 0; 147 break; 148 case 't': 149 ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &value, 0, socket_parse_socket_type)); 150 type = (sock_type_t) value; 151 break; 152 case 'v': 153 verbose = 1; 154 break; 155 // long options with the double minus sign ('-') 156 case '-': 157 if (str_lcmp(argv[index] + 2, "backlog=", 6) == 0) { 158 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &backlog, 8)); 159 } else if (str_lcmp(argv[index] + 2, "count=", 6) == 0) { 160 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &count, 8)); 161 } else if (str_lcmp(argv[index] + 2, "family=", 7) == 0) { 162 ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &family, 9, socket_parse_protocol_family)); 163 } else if (str_lcmp(argv[index] + 2, "help", 5) == 0) { 145 164 echo_print_help(); 146 165 return EOK; 147 break; 148 case 'p': 149 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 0)); 166 } else if (str_lcmp(argv[index] + 2, "port=", 5) == 0) { 167 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 7)); 150 168 port = (uint16_t) value; 151 break; 152 case 'r': 153 ERROR_PROPAGATE(arg_parse_string(argc, argv, &index, &reply, 0)); 154 break; 155 case 's': 156 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 0)); 169 } else if (str_lcmp(argv[index] + 2, "reply=", 6) == 0) { 170 ERROR_PROPAGATE(arg_parse_string(argc, argv, &index, &reply, 8)); 171 } else if (str_lcmp(argv[index] + 2, "size=", 5) == 0) { 172 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 7)); 157 173 size = (value >= 0) ? (size_t) value : 0; 158 break; 159 case 't': 160 ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &value, 0, socket_parse_socket_type)); 174 } else if (str_lcmp(argv[index] + 2, "type=", 5) == 0) { 175 ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &value, 7, socket_parse_socket_type)); 161 176 type = (sock_type_t) value; 162 break; 163 case 'v': 177 } else if (str_lcmp(argv[index] + 2, "verbose", 8) == 0) { 164 178 verbose = 1; 165 break; 166 // long options with the double minus sign ('-') 167 case '-': 168 if(str_lcmp(argv[index] + 2, "backlog=", 6) == 0){ 169 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &backlog, 8)); 170 }else if(str_lcmp(argv[index] + 2, "count=", 6) == 0){ 171 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &count, 8)); 172 }else if(str_lcmp(argv[index] + 2, "family=", 7) == 0){ 173 ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &family, 9, socket_parse_protocol_family)); 174 }else if(str_lcmp(argv[index] + 2, "help", 5) == 0){ 175 echo_print_help(); 176 return EOK; 177 }else if(str_lcmp(argv[index] + 2, "port=", 5) == 0){ 178 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 7)); 179 port = (uint16_t) value; 180 }else if(str_lcmp(argv[index] + 2, "reply=", 6) == 0){ 181 ERROR_PROPAGATE(arg_parse_string(argc, argv, &index, &reply, 8)); 182 }else if(str_lcmp(argv[index] + 2, "size=", 5) == 0){ 183 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 7)); 184 size = (value >= 0) ? (size_t) value : 0; 185 }else if(str_lcmp(argv[index] + 2, "type=", 5) == 0){ 186 ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &value, 7, socket_parse_socket_type)); 187 type = (sock_type_t) value; 188 }else if(str_lcmp(argv[index] + 2, "verbose", 8) == 0){ 189 verbose = 1; 190 }else{ 191 echo_print_help(); 192 return EINVAL; 193 } 194 break; 195 default: 179 } else { 196 180 echo_print_help(); 197 181 return EINVAL; 182 } 183 break; 184 default: 185 echo_print_help(); 186 return EINVAL; 198 187 } 199 } else{188 } else { 200 189 echo_print_help(); 201 190 return EINVAL; … … 204 193 205 194 // check the buffer size 206 if (size <= 0){195 if (size <= 0) { 207 196 fprintf(stderr, "Receive size too small (%d). Using 1024 bytes instead.\n", size); 208 197 size = 1024; … … 210 199 // size plus the terminating null (\0) 211 200 data = (char *) malloc(size + 1); 212 if (! data){201 if (!data) { 213 202 fprintf(stderr, "Failed to allocate receive buffer.\n"); 214 203 return ENOMEM; … … 220 209 // prepare the address buffer 221 210 bzero(address_data, max_length); 222 switch (family){223 224 225 226 227 228 229 230 231 232 233 234 235 211 switch (family) { 212 case PF_INET: 213 address_in->sin_family = AF_INET; 214 address_in->sin_port = htons(port); 215 addrlen = sizeof(struct sockaddr_in); 216 break; 217 case PF_INET6: 218 address_in6->sin6_family = AF_INET6; 219 address_in6->sin6_port = htons(port); 220 addrlen = sizeof(struct sockaddr_in6); 221 break; 222 default: 223 fprintf(stderr, "Protocol family is not supported\n"); 224 return EAFNOSUPPORT; 236 225 } 237 226 238 227 // get a listening socket 239 228 listening_id = socket(family, type, 0); 240 if (listening_id < 0){229 if (listening_id < 0) { 241 230 socket_print_error(stderr, listening_id, "Socket create: ", "\n"); 242 231 return listening_id; … … 244 233 245 234 // if the stream socket is used 246 if (type == SOCK_STREAM){235 if (type == SOCK_STREAM) { 247 236 // check the backlog 248 if (backlog <= 0){237 if (backlog <= 0) { 249 238 fprintf(stderr, "Accepted sockets queue size too small (%d). Using 3 instead.\n", size); 250 239 backlog = 3; 251 240 } 252 241 // set the backlog 253 if (ERROR_OCCURRED(listen(listening_id, backlog))){242 if (ERROR_OCCURRED(listen(listening_id, backlog))) { 254 243 socket_print_error(stderr, ERROR_CODE, "Socket listen: ", "\n"); 255 244 return ERROR_CODE; … … 258 247 259 248 // bind the listenning socket 260 if (ERROR_OCCURRED(bind(listening_id, address, addrlen))){249 if (ERROR_OCCURRED(bind(listening_id, address, addrlen))) { 261 250 socket_print_error(stderr, ERROR_CODE, "Socket bind: ", "\n"); 262 251 return ERROR_CODE; 263 252 } 264 253 265 if (verbose){254 if (verbose) 266 255 printf("Socket %d listenning at %d\n", listening_id, port); 267 }268 256 269 257 socket_id = listening_id; … … 271 259 // do count times 272 260 // or indefinitely if set to a negative value 273 while (count){261 while (count) { 274 262 275 263 addrlen = max_length; 276 if (type == SOCK_STREAM){264 if (type == SOCK_STREAM) { 277 265 // acceept a socket if the stream socket is used 278 266 socket_id = accept(listening_id, address, &addrlen); 279 if (socket_id <= 0){267 if (socket_id <= 0) { 280 268 socket_print_error(stderr, socket_id, "Socket accept: ", "\n"); 281 } else{282 if (verbose){269 } else { 270 if (verbose) 283 271 printf("Socket %d accepted\n", socket_id); 284 }285 272 } 286 273 } 287 274 288 275 // if the datagram socket is used or the stream socked was accepted 289 if (socket_id > 0){276 if (socket_id > 0) { 290 277 291 278 // receive an echo request 292 279 value = recvfrom(socket_id, data, size, 0, address, &addrlen); 293 if (value < 0){280 if (value < 0) { 294 281 socket_print_error(stderr, value, "Socket receive: ", "\n"); 295 } else{282 } else { 296 283 length = (size_t) value; 297 if (verbose){284 if (verbose) { 298 285 // print the header 299 286 300 287 // get the source port and prepare the address buffer 301 288 address_start = NULL; 302 switch (address->sa_family){303 304 305 306 307 308 309 310 311 312 289 switch (address->sa_family) { 290 case AF_INET: 291 port = ntohs(address_in->sin_port); 292 address_start = (uint8_t *) &address_in->sin_addr.s_addr; 293 break; 294 case AF_INET6: 295 port = ntohs(address_in6->sin6_port); 296 address_start = (uint8_t *) &address_in6->sin6_addr.s6_addr; 297 break; 298 default: 299 fprintf(stderr, "Address family %d (0x%X) is not supported.\n", address->sa_family); 313 300 } 314 301 // parse the source address 315 if (address_start){316 if (ERROR_OCCURRED(inet_ntop(address->sa_family, address_start, address_string, sizeof(address_string)))){302 if (address_start) { 303 if (ERROR_OCCURRED(inet_ntop(address->sa_family, address_start, address_string, sizeof(address_string)))) { 317 304 fprintf(stderr, "Received address error %d\n", ERROR_CODE); 318 } else{305 } else { 319 306 data[length] = '\0'; 320 307 printf("Socket %d received %d bytes from %s:%d\n%s\n", socket_id, length, address_string, port, data); … … 324 311 325 312 // answer the request either with the static reply or the original data 326 if (ERROR_OCCURRED(sendto(socket_id, reply ? reply : data, reply ? reply_length : length, 0, address, addrlen))){313 if (ERROR_OCCURRED(sendto(socket_id, reply ? reply : data, reply ? reply_length : length, 0, address, addrlen))) 327 314 socket_print_error(stderr, ERROR_CODE, "Socket send: ", "\n"); 328 }329 330 315 } 331 316 332 317 // close the accepted stream socket 333 if (type == SOCK_STREAM){334 if (ERROR_OCCURRED(closesocket(socket_id))){318 if (type == SOCK_STREAM) { 319 if (ERROR_OCCURRED(closesocket(socket_id))) 335 320 socket_print_error(stderr, ERROR_CODE, "Close socket: ", "\n"); 336 }337 321 } 338 322 … … 340 324 341 325 // decrease the count if positive 342 if (count > 0){343 -- count;344 if (verbose){326 if (count > 0) { 327 count--; 328 if (verbose) 345 329 printf("Waiting for next %d packet(s)\n", count); 346 } 347 } 348 } 349 350 if(verbose){ 330 } 331 } 332 333 if (verbose) 351 334 printf("Closing the socket\n"); 352 }353 335 354 336 // close the listenning socket 355 if (ERROR_OCCURRED(closesocket(listening_id))){337 if (ERROR_OCCURRED(closesocket(listening_id))) { 356 338 socket_print_error(stderr, ERROR_CODE, "Close socket: ", "\n"); 357 339 return ERROR_CODE; 358 340 } 359 341 360 if (verbose){342 if (verbose) 361 343 printf("Exiting\n"); 362 }363 344 364 345 return EOK; -
uspace/app/netecho/print_error.c
rd0d1f4f ra8e5051 28 28 29 29 /** @addtogroup net_app 30 * 30 * @{ 31 31 */ 32 32 33 33 /** @file 34 * 34 * Generic application error printing functions implementation. 35 35 */ 36 37 #include "print_error.h" 36 38 37 39 #include <stdio.h> … … 40 42 #include <net/icmp_codes.h> 41 43 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 */ 51 void 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 } 43 99 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); 93 102 } 94 103 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 */ 113 void print_error(FILE *output, int error_code, const char *prefix, const char *suffix) 114 { 115 if (IS_ICMP_ERROR(error_code)) 97 116 icmp_print_error(output, error_code, prefix, suffix); 98 }else if(IS_SOCKET_ERROR(error_code)){117 else if(IS_SOCKET_ERROR(error_code)) 99 118 socket_print_error(output, error_code, prefix, suffix); 100 }101 119 } 102 120 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 */ 128 void 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); 146 170 } 171 172 if (suffix) 173 fprintf(output, "%s", suffix); 147 174 } 148 175 149 176 /** @} 150 177 */ 178 -
uspace/app/netecho/print_error.h
rd0d1f4f ra8e5051 28 28 29 29 /** @addtogroup net_app 30 * 30 * @{ 31 31 */ 32 32 33 33 /** @file 34 * 34 * Generic application error printing functions. 35 35 */ 36 36 37 #ifndef __NET_APP_PRINT__ 38 #define __NET_APP_PRINT__ 37 #ifndef NET_APP_PRINT_ 38 #define NET_APP_PRINT_ 39 40 #include <stdio.h> 39 41 40 42 /** Returns whether the error code may be an ICMP error code. 41 * @param[in] error_code The error code. 42 * @returns A value indicating whether the error code may be an ICMP error code. 43 * 44 * @param[in] error_code The error code. 45 * @returns A value indicating whether the error code may be an ICMP error code. 43 46 */ 44 #define IS_ICMP_ERROR(error_code) 47 #define IS_ICMP_ERROR(error_code) ((error_code) > 0) 45 48 46 49 /** Returns whether the error code may be socket error code. 47 * @param[in] error_code The error code. 48 * @returns A value indicating whether the error code may be a socket error code. 50 * 51 * @param[in] error_code The error code. 52 * @returns A value indicating whether the error code may be a socket error code. 49 53 */ 50 54 #define IS_SOCKET_ERROR(error_code) ((error_code) < 0) 51 55 52 /** Prints the specific ICMP error description. 53 * @param[in] output The description output stream. May be NULL. 54 * @param[in] error_code The ICMP error code. 55 * @param[in] prefix The error description prefix. May be NULL. 56 * @param[in] suffix The error description suffix. May be NULL. 57 */ 58 extern void icmp_print_error(FILE * output, int error_code, const char * prefix, const char * suffix); 59 60 /** Prints the error description. 61 * Supports ICMP and socket error codes. 62 * @param[in] output The description output stream. May be NULL. 63 * @param[in] error_code The error code. 64 * @param[in] prefix The error description prefix. May be NULL. 65 * @param[in] suffix The error description suffix. May be NULL. 66 */ 67 extern void print_error(FILE * output, int error_code, const char * prefix, const char * suffix); 68 69 /** Prints the specific socket error description. 70 * @param[in] output The description output stream. May be NULL. 71 * @param[in] error_code The socket error code. 72 * @param[in] prefix The error description prefix. May be NULL. 73 * @param[in] suffix The error description suffix. May be NULL. 74 */ 75 extern void socket_print_error(FILE * output, int error_code, const char * prefix, const char * suffix); 56 extern void icmp_print_error(FILE *, int, const char *, const char *); 57 extern void print_error(FILE *, int, const char *, const char *); 58 extern void socket_print_error(FILE *, int, const char *, const char *); 76 59 77 60 #endif
Note:
See TracChangeset
for help on using the changeset viewer.