-
Notifications
You must be signed in to change notification settings - Fork 16
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
Getting the remote socket address #18
Comments
Hey! Sorry for late response. I think you would that similar to getting port: Socket.swift/Sources/Socket.swift Lines 196 to 208 in 36911c1
Instead of It will have some sort of structure that needs to be converted to string. You can use c functions which to do that. Here is and examples: I am assuming you need the ip address from the accepted socket. If you still can't get it work, I can help you further. |
Thanks, here's what I ended up with: var address = sockaddr_in()
var len = socklen_t(MemoryLayout.size(ofValue: address))
let ptr = UnsafeMutableRawPointer(&address).assumingMemoryBound(to: sockaddr.self)
try ing { getpeername(client.fileDescriptor, ptr, &len) }
var buffer: [CChar] = .init(repeating: 0, count: 100)
let remoteHost: String = buffer.withUnsafeMutableBufferPointer { pointer in
guard let cString = inet_ntop(AF_INET, &address.sin_addr, pointer.baseAddress, 100) else { return "unknown" }
return String(cString: cString)
} Would a |
That's great! If you are up to something serious, I would suggest looking into apple/swift-nio |
Thanks for this great package. I'm using this on Linux.
What's the best way to get the remote socket address after the
accept
returns?The text was updated successfully, but these errors were encountered: