Does anybody know why:
boost::system::error_code ec;
boost::asio::ip::address const addr =
boost::asio::ip::address::from_string("10.10.10", ec);
does not return error, since 10.10.10 is invalid address ?
Instead of this 10.10.10 is modified to 10.10.0.10 in addr and no exception is thrown ?
boost::asio::ip::address::from_string()
relies on inet_pton()
internally which accepts things like 10.10.10 as valid addresses. The string "10.10" is used for the two top octets. The remaining "10" is interpreted as 16-bit number and splitted across the last two octets. Altogether this gets correctly interpreted into 10.10.0.10 .
Besides, your call boost::asio::ip::address::from_string("10.10.10", ec);
does not throw since it uses boost::system::error_code
.
Boost provide two type of variant for(Atlest which I uses) all function
boost::system::error_code
.boost::system::error_code
as argument accordingly.Have look at https://wandbox.org/permlink/0wXerng3CYzhAOtT
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.