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

.NET binding: Socket.Send behavior is unexpected #257

Open
CCRcmcpe opened this issue Sep 7, 2023 · 2 comments
Open

.NET binding: Socket.Send behavior is unexpected #257

CCRcmcpe opened this issue Sep 7, 2023 · 2 comments
Labels

Comments

@CCRcmcpe
Copy link

CCRcmcpe commented Sep 7, 2023

public Int32 Send(Byte[] buffer)
{
return Send(buffer, 0, buffer != null ? buffer.Length : 0, SocketFlags.None);
}
public Int32 Send(Byte[] buffer, int offset, int size, SocketFlags socketFlags)
{
if (_isClosed) {
throw new ObjectDisposedException("Socket has been closed");
}
if (_fd < 0) {
throw new ZeroTier.Sockets.SocketException((int)ZeroTier.Constants.ERR_SOCKET);
}
if (buffer == null) {
throw new ArgumentNullException("buffer");
}
if (size < 0 || size > buffer.Length - offset) {
throw new ArgumentOutOfRangeException("size");
}
if (offset < 0 || offset > buffer.Length) {
throw new ArgumentOutOfRangeException("offset");
}
int flags = 0;
IntPtr bufferPtr = Marshal.UnsafeAddrOfPinnedArrayElement(buffer, 0);
return zts_bsd_send(_fd, bufferPtr + offset, (uint)Buffer.ByteLength(buffer), (int)flags);
}

size parameter is just... ignored. Sure this would not be surprising.

@joseph-henry
Copy link
Contributor

Yes you are correct. I think size should replace (uint)Buffer.ByteLength(buffer). If you want to make a PR I'll merge it, otherwise I can do it.

@chadrockey
Copy link

@joseph-henry This bug still exists, it will send the entire buffer if offered, which really confuses most clients, especially if you have a large storage buffer used.... Can send kB or more.

https://github.com/zerotier/libzt/blob/main/src/bindings/csharp/Socket.cs#L321

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants