Network code not compiling on Ubuntu - "'sockaddr' has no member 'sa_len'"

I took excellent samople from:

it does compile under macOS (I am writing a package) but on Linux (Ubuntu) I got:

error: value of type 'sockaddr' has no member 'sa_len'

I suppose different underlying C sockert libs?
any clue?

indeed, compared to BSD, Linux traditionally doesn't have sa_len in sockaddr structure.
but with swift we have a superpower to add one:

#if LINUX // put a proper check here
extension sockaddr {
    var sa_len: Int {
        switch Int32(sa_family) {
        case AF_INET: return MemoryLayout<sockaddr_in>.size
        case AF_INET6: return MemoryLayout<sockaddr_in6>.size
        default: return MemoryLayout<sockaddr_storage>.size // something else
Terms of Service

Privacy Policy

Cookie Policy