Convert a Null-terminated Unicode string to IPv4 address and prefix length. This function outputs a value of type IPv4_ADDRESS and may output a value of type UINT8 by interpreting the contents of the Unicode string specified by String. The format of the input Unicode string String is as follows: D.D.D.D[/P] D and P are decimal digit characters in the range [0-9
| 1365 | |
| 1366 | **/ |
| 1367 | RETURN_STATUS |
| 1368 | EFIAPI |
| 1369 | StrToIpv4Address ( |
| 1370 | IN CONST CHAR16 *String, |
| 1371 | OUT CHAR16 **EndPointer, OPTIONAL |
| 1372 | OUT IPv4_ADDRESS *Address, |
| 1373 | OUT UINT8 *PrefixLength OPTIONAL |
| 1374 | ) |
| 1375 | { |
| 1376 | RETURN_STATUS Status; |
| 1377 | UINTN AddressIndex; |
| 1378 | UINTN Uintn; |
| 1379 | IPv4_ADDRESS LocalAddress; |
| 1380 | UINT8 LocalPrefixLength; |
| 1381 | CHAR16 *Pointer; |
| 1382 | |
| 1383 | LocalPrefixLength = MAX_UINT8; |
| 1384 | |
| 1385 | ASSERT (((UINTN) String & BIT0) == 0); |
| 1386 | |
| 1387 | // |
| 1388 | // 1. None of String or Guid shall be a null pointer. |
| 1389 | // |
| 1390 | SAFE_STRING_CONSTRAINT_CHECK ((String != NULL), RETURN_INVALID_PARAMETER); |
| 1391 | SAFE_STRING_CONSTRAINT_CHECK ((Address != NULL), RETURN_INVALID_PARAMETER); |
| 1392 | |
| 1393 | for (Pointer = (CHAR16 *) String, AddressIndex = 0; AddressIndex < ARRAY_SIZE (Address->Addr) + 1;) { |
| 1394 | if (!InternalIsDecimalDigitCharacter (*Pointer)) { |
| 1395 | // |
| 1396 | // D or P contains invalid characters. |
| 1397 | // |
| 1398 | break; |
| 1399 | } |
| 1400 | |
| 1401 | // |
| 1402 | // Get D or P. |
| 1403 | // |
| 1404 | Status = StrDecimalToUintnS ((CONST CHAR16 *) Pointer, &Pointer, &Uintn); |
| 1405 | if (RETURN_ERROR (Status)) { |
| 1406 | return RETURN_UNSUPPORTED; |
| 1407 | } |
| 1408 | if (AddressIndex == ARRAY_SIZE (Address->Addr)) { |
| 1409 | // |
| 1410 | // It's P. |
| 1411 | // |
| 1412 | if (Uintn > 32) { |
| 1413 | return RETURN_UNSUPPORTED; |
| 1414 | } |
| 1415 | LocalPrefixLength = (UINT8) Uintn; |
| 1416 | } else { |
| 1417 | // |
| 1418 | // It's D. |
| 1419 | // |
| 1420 | if (Uintn > MAX_UINT8) { |
| 1421 | return RETURN_UNSUPPORTED; |
| 1422 | } |
| 1423 | LocalAddress.Addr[AddressIndex] = (UINT8) Uintn; |
| 1424 | AddressIndex++; |
no test coverage detected