N3606: parsing invalid address-string

121 views
Skip to first unread message

Oliver Kowalke

unread,
Sep 9, 2013, 2:49:52 AM9/9/13
to netwo...@isocpp.org
The proposal suggestes that from_string(const string& str) returns an address_v4 value corresponding to the string str or address_v4() otherwise.
address_v4() is equivalent to address_v4::any() which is a valid ip-address.
In cases where you get string with garbage (from UI, config-files etc.) you should get the information that the address-string was not valid.

address_v4 addr1 = address_v4::from_string("0.0.0.0");
address_v4 addr2 = address_v4::from_string("abc");
address_v4 addr3 = address_v4::from_string("712.0.0.1");

All three addresses are equal - but addr2 is garbage and addr3 contains an typo - you can not detect this with the address_v4::from_string().
The developer is forced to write its own parsing function in order to filter such invalid address-string out.

address_v6 addr4 = address_v6::from_string(" 2001::1277::");
addr4 seams to be valid at the first look but it's not. double colon is only allowed once in an IPv6 address.
the developer would be forced to write its own parsing function.

I suggest that from_string() should not map to 'any'-address ('0.0.0.0', '::') if the passed address-string is not valid.
instead it should return an 'invalid address' (for instance default ctor represents not-a-valid-address).

Christopher Kohlhoff

unread,
Sep 9, 2013, 3:04:55 AM9/9/13
to netwo...@isocpp.org


On Mon, Sep 9, 2013, at 04:49 PM, Oliver Kowalke wrote:
> The proposal suggestes that from_string(const string& str) returns an
> address_v4 value corresponding to the string str or address_v4()
> otherwise.
> address_v4() is equivalent to address_v4::any() which is a valid
> ip-address.

Where there are two overloads of the form:

static address from_string(const string& str);
static address from_string(const string& str, error_code& ec);

The first form is supposed to throw a system_error exception. Looks like
that detail got left out of the document.

Cheers,
Chris

Oliver Kowalke

unread,
Sep 9, 2013, 3:20:31 AM9/9/13
to netwo...@isocpp.org, chris_k...@fastmail.fm
Am Montag, 9. September 2013 09:04:55 UTC+2 schrieb Christopher Kohlhoff:
Where there are two overloads of the form:

  static address from_string(const string& str);
  static address from_string(const string& str, error_code& ec);

The first form is supposed to throw a system_error exception. Looks like
that detail got left out of the document.

very good - I was referring to this version of N3606: http://isocpp.org/files/papers/n3603.html#classes.__ip__address_v6__static_members

Oliver

Christopher Kohlhoff

unread,
Sep 9, 2013, 3:25:33 AM9/9/13
to netwo...@isocpp.org
Actually what I intended (but forgot to add) was a general statement
covering all operations, similar to what can be found from line 51
onwards on this page:

<https://github.com/chriskohlhoff/asio-tr2/blob/master/doc/requirements/synchronous_operations.qbk>

Cheers,
Chris
Reply all
Reply to author
Forward
0 new messages