Hey guys,
Why is this error.Unexpected rather than error.AccessDenied?
I’m attempting to create a raw socket using std.posix. When running my program without sudo I’m getting an unknown error. Running with sudo returns no error. Im a noob so if someone could enlighten me that would be cool
.
Function call:
const socket: std.posix.socket_t = try std.posix.socket(std.posix.AF.INET, std.posix.SOCK.RAW, std.posix.IPPROTO.ICMP)
Im running zig 0.14.0 on popOS.
Hey, and welcome to the forum! The error you see is not a Zig issue per se. It’s due to raw sockets requiring special permissions on your OS.
You can use setcap
to set this capability on the executable as explained here
5 Likes
Welcome to ziggit @jibarra 
Zig handles all the error number cases listed in macos and linux manual page for man 2 socket
, including EACCES
defined as errno 13, meaning “Permission denied”.
But the linux man page also says:
Other errors may be generated by the underlying protocol modules.
The manual page man 7 packet
lists some more error numbers that the zig source code of socket
currently does not handle. For example EPERM
is defined as errno 1, meaning “Operation not permitted”, with the following description in the manual page:
User has insufficient privileges to carry out this operation.
What is the error number displayed after the message unexpected errno:
?
2 Likes
You’re totally right I am getting errno 1. This exactly answered my question, Thanks!