Add TryStrToHostAddr and TryStrToHostAddr6 to Sockets unit
Original Reporter info from Mantis: nduffy @solas_agus_dolas
-
Reporter name: Noel Duffy
Original Reporter info from Mantis: nduffy @solas_agus_dolas
- Reporter name: Noel Duffy
Description:
This bug report tracks the proposal to add two new functions to the sockets unit.
function TryStrToHostAddr(IP: String; var ip4: in_addr): Boolean;
function TryStrToHostAddr6(IP: String; var ip6: in6_addr): Boolean;
Instead of returning all-zero results to indicate error conditions, these functions return boolean True or False to the caller. The parsed address is stored in the var parameter.
The motivation for this change is the observation that RFCs for IPv4 and IPv6 regard all-zero addresses as valid, albeit non-routable addresses. Parsing them with libc function inet_pton returns 1, indicating success. Therefore, all zero addresses shouldn't be used as sentinels.
Existing methods StrToHostAddr and StrToHostAddr6 will call the appropriate Try* function, but will discard the boolean and return the address returned by the Try* function. This way, existing code that relies on these functions will still compile and run as before.
Steps to reproduce:
N/A. This isn't a bug.
Additional information:
This change is related to the refactoring of StrToHostAddr6, which is tracked in bug #37013 (closed).
Mantis conversion info:
- Mantis ID: 37060
- Version: 3.0.4
- Fixed in version: 3.3.1
- Fixed in revision: 45376 (#f432bd93)
- Target version: 4.0.0