On 2015-05-28 11:10 PM, Vladimir Panteleev wrote:
On Friday, 29 May 2015 at 00:08:10 UTC, Andre Kostur wrote:
I'm looking for one of two things:

1) If I have a sockaddr_in, how do I get it into an InternetAddress?

First of all, you may not actually need an InternetAddress. Modern code
working with addresses should be address-agnostic, so it should take an
Address instead. Ideally, you should avoid doing anything
address-family-specific - then, it will work with any address family,
incl. any introduced in the future.

Generally speaking, sure. But I live down at the protocol layers of networking where I do need to be aware of whether I'm using IPv4 or IPv6.

You could:

- Create an UnknownAddressReference which uses a pointer to your
sockaddr_in.

- Create an InternetAddress, then copy the address over its "name"
property.

Seems inconvenient to construct then copy over an object when I have the data ready at the time of construction.

2) If it is agreed that there should be a shorter way, I'm willing to
write the code, but would need a little guidance as to where would be
the appropriate place to put the code (New overload to parseAddress?
New constructor for InternetAddress?)

A new constructor for InternetAddress won't hurt.

Done (for both InternetAddress and Internet6Address), pull request is in progress.

Thanks for the input!  (And to Adam too...)

Reply via email to