Changes in uspace/lib/c/generic/inet/addr.c [a62ceaf:683e584] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/inet/addr.c
ra62ceaf r683e584 290 290 291 291 static int inet_addr_parse_v4(const char *str, inet_addr_t *raddr, 292 int *prefix , char **endptr)292 int *prefix) 293 293 { 294 294 uint32_t a = 0; … … 306 306 i++; 307 307 308 if (*cur == '\0') 309 break; 310 308 311 if (*cur != '.') 309 break;312 return EINVAL; 310 313 311 314 if (i < 4) … … 314 317 315 318 if (prefix != NULL) { 316 if (*cur != '/')317 return EINVAL;318 cur++;319 320 319 *prefix = strtoul(cur, &cur, 10); 321 320 if (*prefix > 32) … … 323 322 } 324 323 325 if (i != 4) 326 return EINVAL; 327 328 if (endptr == NULL && *cur != '\0') 324 if (i != 4 || (*cur != '\0')) 329 325 return EINVAL; 330 326 … … 332 328 raddr->addr = a; 333 329 334 if (endptr != NULL)335 *endptr = cur;336 337 330 return EOK; 338 331 } 339 332 340 static int inet_addr_parse_v6(const char *str, inet_addr_t *raddr, int *prefix, 341 char **endptr) 333 static int inet_addr_parse_v6(const char *str, inet_addr_t *raddr, int *prefix) 342 334 { 343 335 uint8_t data[16]; 344 int explicit_groups;345 336 346 337 memset(data, 0, 16); … … 356 347 wildcard_pos = 0; 357 348 wildcard_size = 16; 349 350 /* Handle the unspecified address */ 351 if (*cur == '\0') 352 goto success; 358 353 } 359 354 360 355 while (i < 16) { 361 356 uint16_t bioctet; 362 const char *gend; 363 int rc = str_uint16_t(cur, &gend, 16, false, &bioctet); 357 int rc = str_uint16_t(cur, &cur, 16, false, &bioctet); 364 358 if (rc != EOK) 365 break;359 return rc; 366 360 367 361 data[i] = (bioctet >> 8) & 0xff; … … 377 371 i += 2; 378 372 379 if (*gend != ':') { 380 cur = gend; 373 if (*cur != ':') 381 374 break; 382 }383 375 384 376 if (i < 16) { 377 cur++; 378 385 379 /* Handle wildcard */ 386 if ( gend[1]== ':') {380 if (*cur == ':') { 387 381 if (wildcard_pos != (size_t) -1) 388 382 return EINVAL; … … 390 384 wildcard_pos = i; 391 385 wildcard_size = 16 - i; 392 cur = gend + 2; 386 cur++; 387 388 if (*cur == '\0' || *cur == '/') 389 break; 393 390 } 394 391 } 395 392 } 396 397 /* Number of explicitly specified groups */398 explicit_groups = i;399 393 400 394 if (prefix != NULL) { … … 408 402 } 409 403 410 if ( endptr == NULL &&*cur != '\0')404 if (*cur != '\0') 411 405 return EINVAL; 412 406 … … 420 414 data[j] = 0; 421 415 } 422 } else { 423 /* Verify that all groups have been specified */ 424 if (explicit_groups != 16) 425 return EINVAL; 426 } 427 416 } 417 418 success: 428 419 raddr->version = ip_v6; 429 420 memcpy(raddr->addr6, data, 16); 430 if (endptr != NULL)431 *endptr = (char *)cur;432 421 return EOK; 433 422 } 434 423 435 424 /** Parse node address. 436 *437 * Will fail if @a text contains extra characters at the and and @a endptr438 * is @c NULL.439 425 * 440 426 * @param text Network address in common notation. 441 427 * @param addr Place to store node address. 442 * @param endptr Place to store pointer to next character oc @c NULL443 428 * 444 429 * @return EOK on success, EINVAL if input is not in valid format. 445 430 * 446 431 */ 447 int inet_addr_parse(const char *text, inet_addr_t *addr , char **endptr)432 int inet_addr_parse(const char *text, inet_addr_t *addr) 448 433 { 449 434 int rc; 450 435 451 rc = inet_addr_parse_v4(text, addr, NULL , endptr);436 rc = inet_addr_parse_v4(text, addr, NULL); 452 437 if (rc == EOK) 453 438 return EOK; 454 439 455 rc = inet_addr_parse_v6(text, addr, NULL , endptr);440 rc = inet_addr_parse_v6(text, addr, NULL); 456 441 if (rc == EOK) 457 442 return EOK; … … 462 447 /** Parse network address. 463 448 * 464 * Will fail if @a text contains extra characters at the and and @a endptr465 * is @c NULL.466 *467 449 * @param text Network address in common notation. 468 450 * @param naddr Place to store network address. 469 * @param endptr Place to store pointer to next character oc @c NULL470 451 * 471 452 * @return EOK on success, EINVAL if input is not in valid format. 472 453 * 473 454 */ 474 int inet_naddr_parse(const char *text, inet_naddr_t *naddr , char **endptr)455 int inet_naddr_parse(const char *text, inet_naddr_t *naddr) 475 456 { 476 457 int rc; … … 478 459 int prefix; 479 460 480 rc = inet_addr_parse_v4(text, &addr, &prefix , endptr);461 rc = inet_addr_parse_v4(text, &addr, &prefix); 481 462 if (rc == EOK) { 482 463 inet_addr_naddr(&addr, prefix, naddr); … … 484 465 } 485 466 486 rc = inet_addr_parse_v6(text, &addr, &prefix , endptr);467 rc = inet_addr_parse_v6(text, &addr, &prefix); 487 468 if (rc == EOK) { 488 469 inet_addr_naddr(&addr, prefix, naddr);
Note:
See TracChangeset
for help on using the changeset viewer.