-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Description
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.