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
x/sys/unix: add Send on Linux #47288
Comments
per owners: @ianlancetaylor @bradfitz @tklauser |
Note that this issue is about the x/sys/unix package. I don't see a problem with adding |
Right, sorry for the confusion. I'll edit my comment. |
I understand and agree. Send will work perfectly and no need to change SendTo |
I just want to check in with some observations and request some advice before submitting to gerrit please : It seems like "send" is not included because the implementation of makeZSysnumFile() in mkall.go only parses asm/unistd.h for linux. This does not have "send", it only has
which seems strange(the fact that it has "sendto" and others that are already covered by this go package) The only place I can find a reference to "send(2)" is in linux/net.h, which has
So in summary what I am asking is : asm/unistd.h does not contain the send syscall I wish to add but it seems net.h contains all of the send calls. What is the recommended way forward ? |
Write a |
You are correct, thank you.
|
Change https://golang.org/cl/336569 mentions this issue: |
go version go1.16.5 linux/amd64
GOARCH="amd64"
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
Hello
https://man7.org/linux/man-pages/man2/sendto.2.html refers.
I cannot find a syscall func in the sys/unix package for
ssize_t send(int sockfd, const void *buf, size_t len, int flags);
The good news is that there is one for
ssize_t sendto(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen);
It looks like the sendto syscall in linux allows the sockaddr to be NULL and its accompanying length to be 0 for connections in a connected state. (because the destination is known)
The above documentation mentions that the following call
send(sockfd, buf, len, flags);
is equivalent to
sendto(sockfd, buf, len, flags, NULL, 0);
The current implementation of
func Sendto(fd int, p []byte, flags int, to Sockaddr) (err error)
in
syscall_unix.go
has code that relies on "to Sockaddr" not being nil and a "nil pointer dereference" occurs if a nil is passed.
There could be cases where "to Sockaddr" can be nil to achieve a "send"
Would it be worthwhile modifying this function to allow for a nil "to" (leaving the current non nil behaviour intact) and letting the call reach the kernel (like the equivalent example above) ?
I have done a quick test and it works as predicted.
The text was updated successfully, but these errors were encountered: