public byte[] EndReceive(IAsyncResult asyncResult, ref IPEndPoint remoteEP)
{
CheckDisposed();
if (asyncResult == null)
{
throw new ArgumentNullException("asyncResult is a null reference");
}
EndPoint ep;
if (family == AddressFamily.InterNetwork)
{
ep = new IPEndPoint(IPAddress.Any, 0);
}
else
{
ep = new IPEndPoint(IPAddress.IPv6Any, 0);
}
int bytes = socket.EndReceiveFrom(asyncResult,
ref ep);
remoteEP = (IPEndPoint)ep;
/* Need to copy into a new array here, because
* otherwise the returned array length is not
* 'bytes'
*/
byte[] buf = new byte[bytes];
Array.Copy(recvbuffer, buf, bytes);
return (buf);
}