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

Binding failed while starting the server #50

Open
srijanraj opened this issue Apr 10, 2018 · 2 comments
Open

Binding failed while starting the server #50

srijanraj opened this issue Apr 10, 2018 · 2 comments

Comments

@srijanraj
Copy link

var address = sockaddr_in6()
#if !os(Linux)
address.sin6_len = UInt8(MemoryLayout<sockaddr_in6>.stride)
#endif
address.sin6_family = sa_family_t(AF_INET6)
address.sin6_port = UInt16(port).bigEndian //This basically I think Cause error
address.sin6_flowinfo = 0
address.sin6_addr = try ipAddressToStruct(address: interface)
address.sin6_scope_id = 0
let size = socklen_t(MemoryLayout<sockaddr_in6>.size)
// bind the address and port on socket
guard withUnsafePointer(to: &address, { pointer in
return pointer.withMemoryRebound(to: sockaddr.self, capacity: Int(size)) { pointer in
return SystemLibrary.bind(fileDescriptor, pointer, size) >= 0
}
}) else {
throw OSError.lastIOError()
}

This part of the code is throwing the error. Error number 1 and error description "Operation Not Permitted". I am new to swift and trying to implement mock server on the ongoing project. Can someone have answer for this?

@fangpenlin
Copy link
Contributor

@srijanraj What's the port number you are binding to? As far as I know, if you are binding to port numbers which are below 1024 or a certain number, say you're binding port 80, it will usually require root permission to do so. I guess that's why you are seeing Operation Not Permitted error. If it's the case, I would suggest to use port numbers like 8080 or any number you like that's higher than 1024

@Krystek20
Copy link

@fangpenlin

I set port 8880 and I got the same issue, when I create severer from main app target it's okay, but when I try start server from uitests target for macOS app (for iOS it works) then I got same issue:

Embassy.OSError.ioError(number: 1, message: "Operation not permitted")

Additionally my entitlements are set:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>com.apple.security.app-sandbox</key>
	<true/>
	<key>com.apple.security.network.client</key>
	<true/>
	<key>com.apple.security.network.server</key>
	<true/>
</dict>
</plist>

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

3 participants