[swift-users] Canonical way to cast C structs

Quinn "The Eskimo!" eskimo1 at apple.com
Wed Sep 21 03:38:23 CDT 2016


On 21 Sep 2016, at 06:45, Bouke Haarsma via swift-users <swift-users at swift.org> wrote:

> This property is not available on Linux …

Hey, it’s call /BSD/ Sockets for a reason (-:

Honestly, I don’t think there’s a good way to maintain the simplicity of this abstraction without `ss_len`.  Special casing each address format isn’t viable because some addresses are of variable length (I’m looking at you `sockaddr_un`!).

You’re going to have to carry around a `sockaddr_storage` /and/ a `socklen_t`, and if you’re doing that it’d probably be best to build your own abstraction.  When I originally wrote these helpers I was doing so in the context of a `QSocket` class, which had a `QSocket.Address` struct that wrapped `sockaddr_storage`, and that abstraction would have been able to cope with this.

Share and Enjoy
--
Quinn "The Eskimo!"                    <http://www.apple.com/developer/>
Apple Developer Relations, Developer Technical Support, Core OS/Hardware




More information about the swift-users mailing list