//\r
// Copyright (C) Ximian, Inc. http://www.ximian.com\r
//\r
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
\r
using System;\r
using System.Net;\r
{\r
}\r
\r
+#if NET_1_1
public UdpClient(AddressFamily family)\r
{\r
if(family != AddressFamily.InterNetwork && family != AddressFamily.InterNetwork)\r
this.family = family;\r
InitSocket (null);\r
}\r
+#endif
\r
public UdpClient (int port)\r
{\r
\r
InitSocket (localEP);\r
}\r
-\r
+
+#if NET_1_1
+ public UdpClient (int port, AddressFamily family)
+ {
+ if (family != AddressFamily.InterNetwork &&
+ family != AddressFamily.InterNetworkV6) {
+ throw new ArgumentException ("Family must be InterNetwork or InterNetworkV6", "family");
+ }
+
+ if (port < IPEndPoint.MinPort ||
+ port > IPEndPoint.MaxPort) {
+ throw new ArgumentOutOfRangeException ("port");
+ }
+
+ this.family = family;
+
+ IPEndPoint localEP = new IPEndPoint (IPAddress.Any, port);
+ InitSocket (localEP);
+ }
+#endif
+
public UdpClient (string hostname, int port)\r
{\r
if (hostname == null)\r
IPAddress[] addresses = Dns.Resolve (hostname).AddressList;\r
for(int i=0; i<addresses.Length; i++) {\r
try {\r
- Console.WriteLine("Trying: {0}, Family: {1}", addresses[i], addresses[i].AddressFamily);\r
-\r
this.family = addresses[i].AddressFamily;\r
Connect (new IPEndPoint (addresses[i], port));\r
-\r
- Console.WriteLine("Connected: {0}, Family: {1}", addresses[i], family);\r
break;\r
- }\r
- catch(Exception e) {\r
+ } catch(Exception e) {\r
if(i == addresses.Length - 1){\r
if(socket != null) {\r
socket.Close();\r
}\r
}\r
}\r
-\r
}\r
#endregion\r
#region Multicast methods\r
new IPv6MulticastOption (multicastAddr));\r
#endif\r
}\r
-\r
+
+#if NET_1_1
+ public void DropMulticastGroup (IPAddress multicastAddr,
+ int ifindex)
+ {
+ CheckDisposed ();
+
+ /* LAMESPEC: exceptions haven't been specified
+ * for this overload.
+ */
+ if (multicastAddr == null) {
+ throw new ArgumentNullException ("multicastAddr");
+ }
+
+ /* Does this overload only apply to IPv6?
+ * Only the IPv6MulticastOption has an
+ * ifindex-using constructor. The MS docs
+ * don't say.
+ */
+ if (family == AddressFamily.InterNetworkV6) {
+ socket.SetSocketOption (SocketOptionLevel.IPv6, SocketOptionName.DropMembership, new IPv6MulticastOption (multicastAddr, ifindex));
+ }
+ }
+#endif
+
public void JoinMulticastGroup (IPAddress multicastAddr)\r
{\r
CheckDisposed ();\r
new IPv6MulticastOption (multicastAddr));\r
#endif\r
}\r
-\r
+
+#if NET_1_1
+ public void JoinMulticastGroup (int ifindex,
+ IPAddress multicastAddr)
+ {
+ CheckDisposed ();
+
+ /* Does this overload only apply to IPv6?
+ * Only the IPv6MulticastOption has an
+ * ifindex-using constructor. The MS docs
+ * don't say.
+ */
+ if (family == AddressFamily.InterNetworkV6) {
+ socket.SetSocketOption (SocketOptionLevel.IPv6, SocketOptionName.AddMembership, new IPv6MulticastOption (multicastAddr, ifindex));
+ }
+ }
+#endif
+
public void JoinMulticastGroup (IPAddress multicastAddr, int timeToLive)\r
{\r
CheckDisposed ();\r
\r
void Dispose (bool disposing)\r
{\r
- if (disposed) \r
+ if (disposed)\r
return;\r
disposed = true;\r
- if (disposing) {\r
- // release managed resources\r
- } \r
- // release unmanaged resources\r
- Socket s = socket;\r
- socket = null;\r
- if (s != null)\r
- s.Close ();\r
+\r
+ if (disposing){\r
+ if (socket != null)\r
+ socket.Close ();\r
+\r
+ socket = null;\r
+ }\r
}\r
\r
~UdpClient ()\r