Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Will this work around fix the undefined htonl which causes the different port bug? #5

Closed
curveddesign opened this issue Aug 3, 2014 · 2 comments

Comments

@curveddesign
Copy link

    let isLittleEndian = Int(OSHostByteOrder()) == OSLittleEndian

    let htons  = isLittleEndian ? _OSSwapInt16 : { $0 }
    let htonl  = isLittleEndian ? _OSSwapInt32 : { $0 }
    let htonll = isLittleEndian ? _OSSwapInt64 : { $0 }
    let ntohs  = isLittleEndian ? _OSSwapInt16 : { $0 }
    let ntohl  = isLittleEndian ? _OSSwapInt32 : { $0 }
    let ntohll = isLittleEndian ? _OSSwapInt64 : { $0 }
@curveddesign
Copy link
Author

I know nothing about sockets but I think I fixed the port problem!

I changed this...

    // Can't find htonl(...) function in Swift runtime so port value will be diffrent.
    var addr = sockaddr_in(sin_len: __uint8_t(sizeof(sockaddr_in)), sin_family: sa_family_t(AF_INET),
    sin_port: port, sin_addr: in_addr(s_addr: inet_addr("0.0.0.0")), sin_zero: (0, 0, 0, 0, 0, 0, 0, 0))

To this... ( I added htons, defined above, to the sin_port )

    // Can't find htonl(...) function in Swift runtime so port value will be diffrent.
    var addr = sockaddr_in(sin_len: __uint8_t(sizeof(sockaddr_in)), sin_family: sa_family_t(AF_INET),
    sin_port: htons(port), sin_addr: in_addr(s_addr: inet_addr("0.0.0.0")), sin_zero: (0, 0, 0, 0, 0, 0, 0, 0))

@damian-kolakowski
Copy link
Member

Super !

I pushed your fix: 30acc44

Best

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants