Skip to content

x/sys/unix: add Send on Linux #47288

@dandare100

Description

@dandare100

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions