2
Copyright (C) 2010-2011 Jeroen Frijters
4
This software is provided 'as-is', without any express or implied
5
warranty. In no event will the authors be held liable for any damages
6
arising from the use of this software.
8
Permission is granted to anyone to use this software for any purpose,
9
including commercial applications, and to alter it and redistribute it
10
freely, subject to the following restrictions:
12
1. The origin of this software must not be misrepresented; you must not
13
claim that you wrote the original software. If you use this software
14
in a product, an acknowledgment in the product documentation would be
15
appreciated but is not required.
16
2. Altered source versions must be plainly marked as such, and must not be
17
misrepresented as being the original software.
18
3. This notice may not be removed or altered from any source distribution.
25
package ikvm.internal;
27
import cli.System.Net.EndPoint;
28
import cli.System.Net.IPAddress;
29
import cli.System.Net.IPEndPoint;
30
import cli.System.Net.Sockets.AddressFamily;
31
import cli.System.Net.Sockets.IOControlCode;
32
import cli.System.Net.Sockets.IPv6MulticastOption;
33
import cli.System.Net.Sockets.LingerOption;
34
import cli.System.Net.Sockets.MulticastOption;
35
import cli.System.Net.Sockets.ProtocolType;
36
import cli.System.Net.Sockets.SocketFlags;
37
import cli.System.Net.Sockets.SocketOptionName;
38
import cli.System.Net.Sockets.SocketOptionLevel;
39
import cli.System.Net.Sockets.SocketShutdown;
40
import cli.System.Net.Sockets.SocketType;
44
public final class Winsock
48
// remember the last error code
49
@cli.System.ThreadStaticAttribute.Annotation
50
private static int lastError;
53
public static final int WSA_NOT_ENOUGH_MEMORY = 8;
54
public static final int WSA_OPERATION_ABORTED = 995;
55
public static final int WSAEINTR = 10004;
56
public static final int WSAEACCES = 10013;
57
public static final int WSAEFAULT = 10014;
58
public static final int WSAEINVAL = 10022;
59
public static final int WSAEMFILE = 10024;
60
public static final int WSAEWOULDBLOCK = 10035;
61
public static final int WSAEINPROGRESS = 10036;
62
public static final int WSAEALREADY = 10037;
63
public static final int WSAENOTSOCK = 10038;
64
public static final int WSAEDESTADDRREQ = 10039;
65
public static final int WSAEMSGSIZE = 10040;
66
public static final int WSAEPROTOTYPE = 10041;
67
public static final int WSAENOPROTOOPT = 10042;
68
public static final int WSAEPROTONOSUPPORT = 10043;
69
public static final int WSAESOCKTNOSUPPORT = 10044;
70
public static final int WSAEOPNOTSUPP = 10045;
71
public static final int WSAEPFNOSUPPORT = 10046;
72
public static final int WSAEAFNOSUPPORT = 10047;
73
public static final int WSAEADDRINUSE = 10048;
74
public static final int WSAEADDRNOTAVAIL = 10049;
75
public static final int WSAENETDOWN = 10050;
76
public static final int WSAENETUNREACH = 10051;
77
public static final int WSAENETRESET = 10052;
78
public static final int WSAECONNABORTED = 10053;
79
public static final int WSAECONNRESET = 10054;
80
public static final int WSAENOBUFS = 10055;
81
public static final int WSAEISCONN = 10056;
82
public static final int WSAENOTCONN = 10057;
83
public static final int WSAESHUTDOWN = 10058;
84
public static final int WSAETIMEDOUT = 10060;
85
public static final int WSAECONNREFUSED = 10061;
86
public static final int WSAEHOSTDOWN = 10064;
87
public static final int WSAEHOSTUNREACH = 10065;
88
public static final int WSAEPROCLIM = 10067;
89
public static final int WSASYSNOTREADY = 10091;
90
public static final int WSAVERNOTSUPPORTED = 10092;
91
public static final int WSANOTINITIALISED = 10093;
92
public static final int WSAEDISCON = 10101;
93
public static final int WSATYPE_NOT_FOUND = 10109;
94
public static final int WSAHOST_NOT_FOUND = 11001;
95
public static final int WSATRY_AGAIN = 11002;
96
public static final int WSANO_RECOVERY = 11003;
97
public static final int WSANO_DATA = 11004;
100
public static final int SOCKET_ERROR = -1;
101
public static final cli.System.Net.Sockets.Socket INVALID_SOCKET = null;
103
public static final int AF_INET = AddressFamily.InterNetwork;
104
public static final int AF_INET6 = AddressFamily.InterNetworkV6;
106
public static final int SOCK_STREAM = SocketType.Stream;
107
public static final int SOCK_DGRAM = SocketType.Dgram;
109
public static final int SD_RECEIVE = SocketShutdown.Receive;
110
public static final int SD_SEND = SocketShutdown.Send;
111
public static final int SD_BOTH = SocketShutdown.Both;
113
public static final int SOL_SOCKET = SocketOptionLevel.Socket;
114
public static final int IPPROTO_TCP = SocketOptionLevel.Tcp;
115
public static final int IPPROTO_IP = SocketOptionLevel.IP;
116
public static final int IPPROTO_IPV6 = SocketOptionLevel.IPv6;
118
public static final int TCP_NODELAY = SocketOptionName.NoDelay;
119
public static final int SO_OOBINLINE = SocketOptionName.OutOfBandInline;
120
public static final int SO_LINGER = SocketOptionName.Linger;
121
public static final int SO_SNDBUF = SocketOptionName.SendBuffer;
122
public static final int SO_RCVBUF = SocketOptionName.ReceiveBuffer;
123
public static final int SO_KEEPALIVE = SocketOptionName.KeepAlive;
124
public static final int SO_REUSEADDR = SocketOptionName.ReuseAddress;
125
public static final int SO_BROADCAST = SocketOptionName.Broadcast;
126
public static final int SO_RCVTIMEO = SocketOptionName.ReceiveTimeout;
127
public static final int SO_ERROR = SocketOptionName.Error;
128
public static final int IP_MULTICAST_IF = SocketOptionName.MulticastInterface;
129
public static final int IP_MULTICAST_LOOP = SocketOptionName.MulticastLoopback;
130
public static final int IP_TOS = SocketOptionName.TypeOfService;
131
public static final int IP_MULTICAST_TTL = SocketOptionName.MulticastTimeToLive;
132
public static final int IP_ADD_MEMBERSHIP = SocketOptionName.AddMembership;
133
public static final int IP_DROP_MEMBERSHIP = SocketOptionName.DropMembership;
134
public static final int IPV6_MULTICAST_IF = SocketOptionName.MulticastInterface;
135
public static final int IPV6_MULTICAST_LOOP = SocketOptionName.MulticastLoopback;
136
public static final int IPV6_MULTICAST_HOPS = SocketOptionName.MulticastTimeToLive;
137
public static final int IPV6_ADD_MEMBERSHIP = SocketOptionName.AddMembership;
138
public static final int IPV6_DROP_MEMBERSHIP = SocketOptionName.DropMembership;
139
public static final int IPV6_V6ONLY = 27;
141
public static final int SIO_UDP_CONNRESET = 0x9800000C;
143
public static final int MSG_PEEK = SocketFlags.Peek;
144
public static final int MSG_OOB = SocketFlags.OutOfBand;
146
public static final int FIONREAD = (int)IOControlCode.DataToRead;
147
public static final int FIONBIO = (int)IOControlCode.NonBlockingIO;
149
public static int WSAGetLastError()
154
public static void WSASetLastError(int err)
159
public static int WSASendDisconnect(cli.System.Net.Sockets.Socket socket)
163
lastError = WSAENOTSOCK;
168
if (false) throw new cli.System.Net.Sockets.SocketException();
169
if (false) throw new cli.System.ObjectDisposedException("");
170
socket.Shutdown(SocketShutdown.wrap(SocketShutdown.Send));
173
catch (cli.System.Net.Sockets.SocketException x)
175
lastError = x.get_ErrorCode();
178
catch (cli.System.ObjectDisposedException _)
180
lastError = WSAENOTSOCK;
185
public static int WSAIoctl(cli.System.Net.Sockets.Socket socket, int ioControlCode, boolean optionInValue)
187
byte[] in = new byte[4];
188
in[0] = optionInValue ? (byte)1 : (byte)0;
189
byte[] out = new byte[4];
190
return WSAIoctl(socket, ioControlCode, in, out);
193
public static int WSAIoctl(cli.System.Net.Sockets.Socket socket, int ioControlCode, byte[] optionInValue, byte[] optionOutValue)
197
lastError = WSAENOTSOCK;
202
if (false) throw new cli.System.Net.Sockets.SocketException();
203
if (false) throw new cli.System.ObjectDisposedException("");
204
if (false) throw new cli.System.InvalidOperationException();
205
if (ioControlCode == FIONBIO)
207
// it's illegal to meddle with the blocking mode via IOControl
208
socket.set_Blocking(optionInValue[0] == 0);
210
else if (ioControlCode == FIONREAD)
212
int avail = socket.get_Available();
213
optionOutValue[0] = (byte)(avail >> 0);
214
optionOutValue[1] = (byte)(avail >> 8);
215
optionOutValue[2] = (byte)(avail >> 16);
216
optionOutValue[3] = (byte)(avail >> 24);
220
socket.IOControl(ioControlCode, optionInValue, optionOutValue);
224
catch (cli.System.Net.Sockets.SocketException x)
226
lastError = x.get_ErrorCode();
229
catch (cli.System.ObjectDisposedException _)
231
lastError = WSAENOTSOCK;
234
catch (cli.System.InvalidOperationException _)
236
lastError = WSAEINVAL;
241
public static int ioctlsocket(cli.System.Net.Sockets.Socket s, int cmd, int[] argp)
243
byte[] in = cli.System.BitConverter.GetBytes(argp[0]);
244
byte[] out = new byte[4];
245
int ret = WSAIoctl(s, cmd, in, out);
246
argp[0] = cli.System.BitConverter.ToInt32(out, 0);
250
public static int ioctlsocket(cli.System.Net.Sockets.Socket s, int cmd, int arg)
252
byte[] in = cli.System.BitConverter.GetBytes(arg);
253
return WSAIoctl(s, cmd, in, in);
256
public static cli.System.Net.Sockets.Socket socket(int af, int type, int protocol)
260
if (false) throw new cli.System.Net.Sockets.SocketException();
261
if (false) throw new cli.System.ObjectDisposedException("");
262
return new cli.System.Net.Sockets.Socket(AddressFamily.wrap(af), SocketType.wrap(type), ProtocolType.wrap(protocol));
264
catch (cli.System.Net.Sockets.SocketException x)
266
lastError = x.get_ErrorCode();
267
return INVALID_SOCKET;
269
catch (cli.System.ObjectDisposedException _)
271
lastError = WSAENOTSOCK;
272
return INVALID_SOCKET;
276
public static int closesocket(cli.System.Net.Sockets.Socket socket)
280
lastError = WSAENOTSOCK;
287
public static final class linger
292
LingerOption ToLingerOption()
294
return new LingerOption(l_onoff != 0, l_linger);
298
public static final class ip_mreq
300
public final in_addr imr_multiaddr = new in_addr();
301
public final in_addr imr_interface = new in_addr();
303
MulticastOption ToMulticastOption()
305
return new MulticastOption(imr_multiaddr.ToIPAddress(), imr_interface.ToIPAddress());
309
public static final class in_addr
313
IPAddress ToIPAddress()
315
return new IPAddress(s_addr & 0xFFFFFFFFL);
319
public static final class ipv6_mreq
321
public in6_addr ipv6mr_multiaddr;
322
public int ipv6mr_interface;
324
IPv6MulticastOption ToIPv6MulticastOption()
326
return new IPv6MulticastOption(ipv6mr_multiaddr.addr, ipv6mr_interface & 0xFFFFFFFFL);
330
public static final class in6_addr
334
public byte[] s6_bytes()
336
return addr == null ? new byte[16] : addr.GetAddressBytes();
339
public static in6_addr FromSockAddr(IIPEndPointWrapper ep)
341
in6_addr addr = new in6_addr();
342
addr.addr = ep.get().get_Address();
347
public static int getsockopt(cli.System.Net.Sockets.Socket socket, int level, int optname, Object optval)
351
lastError = WSAENOTSOCK;
356
if (false) throw new cli.System.Net.Sockets.SocketException();
357
if (false) throw new cli.System.ObjectDisposedException("");
358
Object val = socket.GetSocketOption(SocketOptionLevel.wrap(level), SocketOptionName.wrap(optname));
359
if (val instanceof cli.System.Int32)
361
if (optval instanceof in_addr)
363
((in_addr)optval).s_addr = CIL.unbox_int(val);
367
((cli.System.Array)optval).SetValue(val, 0);
370
else if (val instanceof LingerOption)
372
LingerOption lo = (LingerOption)val;
373
linger ling = (linger)optval;
374
ling.l_onoff = lo.get_Enabled() ? 1 : 0;
375
// FXBUG the linger time is treated as a signed short instead of an unsiged short
376
ling.l_linger = lo.get_LingerTime() & 0xFFFF;
380
lastError = WSAEINVAL;
385
catch (cli.System.Net.Sockets.SocketException x)
387
lastError = x.get_ErrorCode();
390
catch (cli.System.ObjectDisposedException _)
392
lastError = WSAENOTSOCK;
397
public static int connect(cli.System.Net.Sockets.Socket socket, IIPEndPointWrapper epw)
401
lastError = WSAENOTSOCK;
406
if (false) throw new cli.System.Net.Sockets.SocketException();
407
if (false) throw new cli.System.ObjectDisposedException("");
408
IPEndPoint ep = epw.get();
411
// it is a disconnect request, we must connect to the Any address
412
if (socket.get_AddressFamily().Value == AddressFamily.InterNetwork)
414
ep = new IPEndPoint(cli.System.Net.IPAddress.Any, 0);
418
ep = new IPEndPoint(cli.System.Net.IPAddress.IPv6Any, 0);
423
ep = v4mapped(socket, ep);
425
if (socket.get_SocketType().Value == SocketType.Dgram)
427
// NOTE we use async connect to work around the issue that the .NET Socket class disallows sync Connect after the socket has received WSAECONNRESET
428
socket.EndConnect(socket.BeginConnect(ep, null, null));
436
catch (cli.System.Net.Sockets.SocketException x)
438
lastError = x.get_ErrorCode();
441
catch (cli.System.ObjectDisposedException _)
443
lastError = WSAENOTSOCK;
448
private static IPEndPoint v4mapped(cli.System.Net.Sockets.Socket socket, IPEndPoint ep)
450
// when binding an IPv6 socket to an IPv4 address, we need to use a mapped v4 address
451
if (socket.get_AddressFamily().Value == AF_INET6 && ep.get_AddressFamily().Value == AF_INET)
453
byte[] v4 = ep.get_Address().GetAddressBytes();
454
if (v4[0] == 0 && v4[1] == 0 && v4[2] == 0 && v4[3] == 0)
456
return new IPEndPoint(IPAddress.IPv6Any, ep.get_Port());
460
byte[] v6 = new byte[16];
467
return new IPEndPoint(new IPAddress(v6), ep.get_Port());
473
public static int bind(cli.System.Net.Sockets.Socket socket, IIPEndPointWrapper ep)
477
lastError = WSAENOTSOCK;
482
if (false) throw new cli.System.Net.Sockets.SocketException();
483
if (false) throw new cli.System.ObjectDisposedException("");
484
socket.Bind(v4mapped(socket, ep.get()));
487
catch (cli.System.Net.Sockets.SocketException x)
489
lastError = x.get_ErrorCode();
492
catch (cli.System.ObjectDisposedException _)
494
lastError = WSAENOTSOCK;
499
public static int listen(cli.System.Net.Sockets.Socket socket, int count)
503
lastError = WSAENOTSOCK;
508
if (false) throw new cli.System.Net.Sockets.SocketException();
509
if (false) throw new cli.System.ObjectDisposedException("");
510
socket.Listen(count);
513
catch (cli.System.Net.Sockets.SocketException x)
515
lastError = x.get_ErrorCode();
518
catch (cli.System.ObjectDisposedException _)
520
lastError = WSAENOTSOCK;
525
public static int shutdown(cli.System.Net.Sockets.Socket socket, int how)
529
lastError = WSAENOTSOCK;
534
if (false) throw new cli.System.Net.Sockets.SocketException();
535
if (false) throw new cli.System.ObjectDisposedException("");
536
socket.Shutdown(SocketShutdown.wrap(how));
539
catch (cli.System.Net.Sockets.SocketException x)
541
lastError = x.get_ErrorCode();
544
catch (cli.System.ObjectDisposedException _)
546
lastError = WSAENOTSOCK;
551
public static final class fd_set
553
cli.System.Collections.ArrayList list = new cli.System.Collections.ArrayList();
556
public static final class timeval
562
public static void FD_ZERO(fd_set set)
567
public static void FD_SET(cli.System.Net.Sockets.Socket socket, fd_set set)
569
set.list.Add(socket);
572
public static boolean FD_ISSET(cli.System.Net.Sockets.Socket socket, fd_set set)
574
return set.list.Contains(socket);
577
private static cli.System.Collections.ArrayList copy(fd_set set)
579
return set == null ? null : (cli.System.Collections.ArrayList)set.list.Clone();
582
public static int select(fd_set readfds, fd_set writefds, fd_set exceptfds, timeval timeout)
585
long current = cli.System.DateTime.get_UtcNow().get_Ticks();
588
// FXBUG documentation says that -1 will block forever, but in fact it returns immediately,
589
// so we simulate timeout with a large expiration
590
expiration = Long.MAX_VALUE;
594
long timeout100nanos = Math.min(Long.MAX_VALUE / 10, timeout.tv_usec) * 10 + Math.min(Long.MAX_VALUE / 10000000, timeout.tv_sec) * 10000000;
595
expiration = current + Math.min(Long.MAX_VALUE - current, timeout100nanos);
599
if (false) throw new cli.System.ArgumentNullException();
600
if (false) throw new cli.System.Net.Sockets.SocketException();
601
if (false) throw new cli.System.ObjectDisposedException("");
604
cli.System.Collections.ArrayList checkRead = copy(readfds);
605
cli.System.Collections.ArrayList checkWrite = copy(writefds);
606
cli.System.Collections.ArrayList checkError = copy(exceptfds);
607
int microSeconds = (int)Math.min(Integer.MAX_VALUE, (expiration - current) / 10);
608
cli.System.Net.Sockets.Socket.Select(checkRead, checkWrite, checkError, microSeconds);
610
if (checkRead != null)
612
count += checkRead.get_Count();
614
if (checkWrite != null)
616
count += checkWrite.get_Count();
618
if (checkError != null)
620
count += checkError.get_Count();
622
current = cli.System.DateTime.get_UtcNow().get_Ticks();
623
if (count != 0 || current >= expiration)
627
readfds.list = checkRead;
629
if (writefds != null)
631
writefds.list = checkWrite;
633
if (exceptfds != null)
635
exceptfds.list = checkError;
641
catch (cli.System.ArgumentNullException _)
643
lastError = WSAEINVAL;
646
catch (cli.System.Net.Sockets.SocketException x)
648
lastError = x.get_ErrorCode();
651
catch (cli.System.ObjectDisposedException _)
653
lastError = WSAENOTSOCK;
658
public static int send(cli.System.Net.Sockets.Socket socket, byte[] buf, int len, int flags)
660
return send(socket, buf, 0, len, flags);
663
public static int send(cli.System.Net.Sockets.Socket socket, byte[] buf, int off, int len, int flags)
667
lastError = WSAENOTSOCK;
672
if (false) throw new cli.System.ArgumentException();
673
if (false) throw new cli.System.Net.Sockets.SocketException();
674
if (false) throw new cli.System.ObjectDisposedException("");
675
return socket.Send(buf, off, len, SocketFlags.wrap(flags));
677
catch (cli.System.ArgumentException _)
679
lastError = WSAEINVAL;
682
catch (cli.System.Net.Sockets.SocketException x)
684
lastError = x.get_ErrorCode();
687
catch (cli.System.ObjectDisposedException _)
689
lastError = WSAENOTSOCK;
694
public static int recv(cli.System.Net.Sockets.Socket socket, byte[] buf, int len, int flags)
696
return recv(socket, buf, 0, len, flags);
699
public static int recv(cli.System.Net.Sockets.Socket socket, byte[] buf, int off, int len, int flags)
703
lastError = WSAENOTSOCK;
708
if (false) throw new cli.System.ArgumentException();
709
if (false) throw new cli.System.Net.Sockets.SocketException();
710
if (false) throw new cli.System.ObjectDisposedException("");
711
return socket.Receive(buf, off, len, SocketFlags.wrap(flags));
713
catch (cli.System.ArgumentException _)
715
lastError = WSAEINVAL;
718
catch (cli.System.Net.Sockets.SocketException x)
720
lastError = x.get_ErrorCode();
723
catch (cli.System.ObjectDisposedException _)
725
lastError = WSAENOTSOCK;
730
public static int sendto(cli.System.Net.Sockets.Socket socket, byte[] buf, int off, int len, int flags, IIPEndPointWrapper to)
734
lastError = WSAENOTSOCK;
739
if (false) throw new cli.System.ArgumentException();
740
if (false) throw new cli.System.Net.Sockets.SocketException();
741
if (false) throw new cli.System.ObjectDisposedException("");
744
return socket.Send(buf, off, len, SocketFlags.wrap(flags));
748
return socket.SendTo(buf, off, len, SocketFlags.wrap(flags), v4mapped(socket, to.get()));
751
catch (cli.System.ArgumentException _)
753
lastError = WSAEINVAL;
756
catch (cli.System.Net.Sockets.SocketException x)
758
// on Linux we get a WSAECONNREFUSED when sending to an unreachable port/destination, so ignore that
759
if (x.get_ErrorCode() == WSAECONNREFUSED)
763
lastError = x.get_ErrorCode();
766
catch (cli.System.ObjectDisposedException _)
768
lastError = WSAENOTSOCK;
773
public static int recvfrom(cli.System.Net.Sockets.Socket socket, byte[] buf, int len, int flags, IIPEndPointWrapper from)
775
return recvfrom(socket, buf, 0, len, flags, from);
778
public static int recvfrom(cli.System.Net.Sockets.Socket socket, byte[] buf, int off, int len, int flags, IIPEndPointWrapper from)
782
lastError = WSAENOTSOCK;
787
if (false) throw new cli.System.ArgumentException();
788
if (false) throw new cli.System.Net.Sockets.SocketException();
789
if (false) throw new cli.System.ObjectDisposedException("");
790
EndPoint[] ep = new EndPoint[] { socket.get_AddressFamily().Value == AF_INET6 ? new IPEndPoint(IPAddress.IPv6Any, 0) : new IPEndPoint(0, 0) };
793
return socket.ReceiveFrom(buf, off, len, SocketFlags.wrap(flags), ep);
799
from.set((IPEndPoint)ep[0]);
803
catch (cli.System.ArgumentException _)
805
lastError = WSAEINVAL;
808
catch (cli.System.Net.Sockets.SocketException x)
810
lastError = x.get_ErrorCode();
813
catch (cli.System.ObjectDisposedException _)
815
lastError = WSAENOTSOCK;
820
public static int setsockopt(cli.System.Net.Sockets.Socket s, int level, int optname, Object optval)
824
lastError = WSAENOTSOCK;
829
if (false) throw new cli.System.ArgumentException();
830
if (false) throw new cli.System.Net.Sockets.SocketException();
831
if (false) throw new cli.System.ObjectDisposedException("");
832
if (optval instanceof Boolean)
834
s.SetSocketOption(SocketOptionLevel.wrap(level), SocketOptionName.wrap(optname), ((Boolean)optval).booleanValue());
836
else if (optval instanceof Integer)
838
s.SetSocketOption(SocketOptionLevel.wrap(level), SocketOptionName.wrap(optname), ((Integer)optval).intValue());
840
else if (optval instanceof linger)
842
s.set_LingerState(((linger)optval).ToLingerOption());
844
else if (optval instanceof ip_mreq)
846
s.SetSocketOption(SocketOptionLevel.wrap(level), SocketOptionName.wrap(optname), ((ip_mreq)optval).ToMulticastOption());
848
else if (optval instanceof ipv6_mreq)
850
s.SetSocketOption(SocketOptionLevel.wrap(level), SocketOptionName.wrap(optname), ((ipv6_mreq)optval).ToIPv6MulticastOption());
852
else if (optval instanceof in_addr)
854
s.SetSocketOption(SocketOptionLevel.wrap(level), SocketOptionName.wrap(optname), ((in_addr)optval).s_addr);
858
lastError = WSAEINVAL;
863
catch (cli.System.ArgumentException _)
865
lastError = WSAEINVAL;
868
catch (cli.System.Net.Sockets.SocketException x)
870
lastError = x.get_ErrorCode();
873
catch (cli.System.ObjectDisposedException _)
875
lastError = WSAENOTSOCK;
880
public static cli.System.Net.Sockets.Socket accept(cli.System.Net.Sockets.Socket s, IIPEndPointWrapper ep)
884
lastError = WSAENOTSOCK;
885
return INVALID_SOCKET;
889
if (false) throw new cli.System.InvalidOperationException();
890
if (false) throw new cli.System.Net.Sockets.SocketException();
891
if (false) throw new cli.System.ObjectDisposedException("");
892
cli.System.Net.Sockets.Socket remote = s.Accept();
895
ep.set((IPEndPoint)remote.get_RemoteEndPoint());
899
catch (cli.System.ObjectDisposedException _)
901
lastError = WSAENOTSOCK;
902
return INVALID_SOCKET;
904
catch (cli.System.InvalidOperationException _)
906
lastError = WSAEINVAL;
907
return INVALID_SOCKET;
909
catch (cli.System.Net.Sockets.SocketException x)
911
lastError = x.get_ErrorCode();
912
return INVALID_SOCKET;
916
public interface IIPEndPointWrapper
918
void set(IPEndPoint value);
922
public static int getsockname(cli.System.Net.Sockets.Socket s, IIPEndPointWrapper name)
926
lastError = WSAENOTSOCK;
931
if (false) throw new cli.System.Net.Sockets.SocketException();
932
if (false) throw new cli.System.ObjectDisposedException("");
933
IPEndPoint ep = (IPEndPoint)s.get_LocalEndPoint();
936
lastError = WSAEINVAL;
942
catch (ClassCastException _)
944
lastError = WSAEOPNOTSUPP;
947
catch (cli.System.ObjectDisposedException _)
949
lastError = WSAENOTSOCK;
952
catch (cli.System.Net.Sockets.SocketException x)
954
lastError = x.get_ErrorCode();
959
public static int ntohl(int address)
961
return Integer.reverseBytes(address);
964
public static int htonl(int address)
966
return Integer.reverseBytes(address);
969
public static int ntohs(int port)
971
return Short.reverseBytes((short)port) & 0xFFFF;
974
public static int htons(int port)
976
return Short.reverseBytes((short)port) & 0xFFFF;