Changeset 5d0f1bc in mainline
- Timestamp:
- 2010-11-07T12:41:29Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 987930f
- Parents:
- 774e9ecd
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/netecho/netecho.c
r774e9ecd r5d0f1bc 41 41 #include <task.h> 42 42 #include <arg_parse.h> 43 #include <err.h>44 43 45 44 #include <net/in.h> … … 91 90 int main(int argc, char *argv[]) 92 91 { 93 ERROR_DECLARE;94 95 92 size_t size = 1024; 96 93 int verbose = 0; … … 117 114 size_t reply_length; 118 115 int value; 116 int rc; 119 117 120 118 // parse the command line arguments … … 123 121 switch (argv[index][1]) { 124 122 case 'b': 125 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &backlog, 0)); 123 rc = arg_parse_int(argc, argv, &index, &backlog, 0); 124 if (rc != EOK) 125 return rc; 126 126 break; 127 127 case 'c': 128 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &count, 0)); 128 rc = arg_parse_int(argc, argv, &index, &count, 0); 129 if (rc != EOK) 130 return rc; 129 131 break; 130 132 case 'f': 131 ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &family, 0, socket_parse_protocol_family)); 133 rc = arg_parse_name_int(argc, argv, &index, &family, 0, socket_parse_protocol_family); 134 if (rc != EOK) 135 return rc; 132 136 break; 133 137 case 'h': … … 136 140 break; 137 141 case 'p': 138 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 0)); 142 rc = arg_parse_int(argc, argv, &index, &value, 0); 143 if (rc != EOK) 144 return rc; 139 145 port = (uint16_t) value; 140 146 break; 141 147 case 'r': 142 ERROR_PROPAGATE(arg_parse_string(argc, argv, &index, &reply, 0)); 148 rc = arg_parse_string(argc, argv, &index, &reply, 0); 149 if (rc != EOK) 150 return rc; 143 151 break; 144 152 case 's': 145 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 0)); 153 rc = arg_parse_int(argc, argv, &index, &value, 0); 154 if (rc != EOK) 155 return rc; 146 156 size = (value >= 0) ? (size_t) value : 0; 147 157 break; 148 158 case 't': 149 ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &value, 0, socket_parse_socket_type)); 159 rc = arg_parse_name_int(argc, argv, &index, &value, 0, socket_parse_socket_type); 160 if (rc != EOK) 161 return rc; 150 162 type = (sock_type_t) value; 151 163 break; … … 156 168 case '-': 157 169 if (str_lcmp(argv[index] + 2, "backlog=", 6) == 0) { 158 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &backlog, 8)); 170 rc = arg_parse_int(argc, argv, &index, &backlog, 8); 171 if (rc != EOK) 172 return rc; 159 173 } else if (str_lcmp(argv[index] + 2, "count=", 6) == 0) { 160 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &count, 8));174 rc = arg_parse_int(argc, argv, &index, &count, 8); 161 175 } 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)); 176 rc = arg_parse_name_int(argc, argv, &index, &family, 9, socket_parse_protocol_family); 177 if (rc != EOK) 178 return rc; 163 179 } else if (str_lcmp(argv[index] + 2, "help", 5) == 0) { 164 180 echo_print_help(); 165 181 return EOK; 166 182 } else if (str_lcmp(argv[index] + 2, "port=", 5) == 0) { 167 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 7)); 183 rc = arg_parse_int(argc, argv, &index, &value, 7); 184 if (rc != EOK) 185 return rc; 168 186 port = (uint16_t) value; 169 187 } else if (str_lcmp(argv[index] + 2, "reply=", 6) == 0) { 170 ERROR_PROPAGATE(arg_parse_string(argc, argv, &index, &reply, 8)); 188 rc = arg_parse_string(argc, argv, &index, &reply, 8); 189 if (rc != EOK) 190 return rc; 171 191 } else if (str_lcmp(argv[index] + 2, "size=", 5) == 0) { 172 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 7)); 192 rc = arg_parse_int(argc, argv, &index, &value, 7); 193 if (rc != EOK) 194 return rc; 173 195 size = (value >= 0) ? (size_t) value : 0; 174 196 } 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)); 197 rc = arg_parse_name_int(argc, argv, &index, &value, 7, socket_parse_socket_type); 198 if (rc != EOK) 199 return rc; 176 200 type = (sock_type_t) value; 177 201 } else if (str_lcmp(argv[index] + 2, "verbose", 8) == 0) { … … 240 264 } 241 265 // set the backlog 242 if (ERROR_OCCURRED(listen(listening_id, backlog))) { 243 socket_print_error(stderr, ERROR_CODE, "Socket listen: ", "\n"); 244 return ERROR_CODE; 266 rc = listen(listening_id, backlog); 267 if (rc != EOK) { 268 socket_print_error(stderr, rc, "Socket listen: ", "\n"); 269 return rc; 245 270 } 246 271 } 247 272 248 273 // bind the listenning socket 249 if (ERROR_OCCURRED(bind(listening_id, address, addrlen))) { 250 socket_print_error(stderr, ERROR_CODE, "Socket bind: ", "\n"); 251 return ERROR_CODE; 274 rc = bind(listening_id, address, addrlen); 275 if (rc != EOK) { 276 socket_print_error(stderr, rc, "Socket bind: ", "\n"); 277 return rc; 252 278 } 253 279 … … 301 327 // parse the source address 302 328 if (address_start) { 303 if (ERROR_OCCURRED(inet_ntop(address->sa_family, address_start, address_string, sizeof(address_string)))) { 304 fprintf(stderr, "Received address error %d\n", ERROR_CODE); 329 rc = inet_ntop(address->sa_family, address_start, address_string, sizeof(address_string)); 330 if (rc != EOK) { 331 fprintf(stderr, "Received address error %d\n", rc); 305 332 } else { 306 333 data[length] = '\0'; … … 311 338 312 339 // answer the request either with the static reply or the original data 313 if (ERROR_OCCURRED(sendto(socket_id, reply ? reply : data, reply ? reply_length : length, 0, address, addrlen))) 314 socket_print_error(stderr, ERROR_CODE, "Socket send: ", "\n"); 340 rc = sendto(socket_id, reply ? reply : data, reply ? reply_length : length, 0, address, addrlen); 341 if (rc != EOK) 342 socket_print_error(stderr, rc, "Socket send: ", "\n"); 315 343 } 316 344 317 345 // close the accepted stream socket 318 346 if (type == SOCK_STREAM) { 319 if (ERROR_OCCURRED(closesocket(socket_id))) 320 socket_print_error(stderr, ERROR_CODE, "Close socket: ", "\n"); 347 rc = closesocket(socket_id); 348 if (rc != EOK) 349 socket_print_error(stderr, rc, "Close socket: ", "\n"); 321 350 } 322 351 … … 335 364 336 365 // close the listenning socket 337 if (ERROR_OCCURRED(closesocket(listening_id))) { 338 socket_print_error(stderr, ERROR_CODE, "Close socket: ", "\n"); 339 return ERROR_CODE; 366 rc = closesocket(listening_id); 367 if (rc != EOK) { 368 socket_print_error(stderr, rc, "Close socket: ", "\n"); 369 return rc; 340 370 } 341 371
Note:
See TracChangeset
for help on using the changeset viewer.