View | Details | Raw Unified | Return to bug 2033
Collapse All | Expand All

(-)a/mcs/class/System/System.Net.NetworkInformation/IPInterfaceProperties.cs (-20 / +20 lines)
Lines 58-73 Link Here
58
	{
58
	{
59
		protected IPv4InterfaceProperties ipv4iface_properties;
59
		protected IPv4InterfaceProperties ipv4iface_properties;
60
		protected UnixNetworkInterface iface;
60
		protected UnixNetworkInterface iface;
61
		List <IPAddress> addresses;
61
		List <InterfaceIPDetails> interfaceDetailsList;
62
		IPAddressCollection dns_servers;
62
		IPAddressCollection dns_servers;
63
		IPAddressCollection gateways;
63
		IPAddressCollection gateways;
64
		string dns_suffix;
64
		string dns_suffix;
65
		DateTime last_parse;
65
		DateTime last_parse;
66
		
66
		
67
		public UnixIPInterfaceProperties (UnixNetworkInterface iface, List <IPAddress> addresses)
67
		public UnixIPInterfaceProperties (UnixNetworkInterface iface, List <InterfaceIPDetails> interfaceDetailsList)
68
		{
68
		{
69
			this.iface = iface;
69
			this.iface = iface;
70
			this.addresses = addresses;
70
			this.interfaceDetailsList = interfaceDetailsList;
71
		}
71
		}
72
72
73
		public override IPv6InterfaceProperties GetIPv6Properties ()
73
		public override IPv6InterfaceProperties GetIPv6Properties ()
Lines 154-162 Link Here
154
			get {
154
			get {
155
				List<IPAddress> anycastAddresses = new List<IPAddress> ();
155
				List<IPAddress> anycastAddresses = new List<IPAddress> ();
156
				/* XXX:
156
				/* XXX:
157
				foreach (IPAddress address in addresses) {
157
				foreach (IPAddress ipInterface in interfaceDetailsList) {
158
					if (is_anycast_address (address)) {
158
					if (is_anycast_address (ipInterface.address)) {
159
						anycastAddresses.Add (address);
159
						anycastAddresses.Add (ipInterface.address);
160
					}
160
					}
161
				}
161
				}
162
				*/
162
				*/
Lines 217-226 Link Here
217
		public override MulticastIPAddressInformationCollection MulticastAddresses {
217
		public override MulticastIPAddressInformationCollection MulticastAddresses {
218
			get {
218
			get {
219
				List<IPAddress> multicastAddresses = new List<IPAddress> ();
219
				List<IPAddress> multicastAddresses = new List<IPAddress> ();
220
				foreach (IPAddress address in addresses) {
220
				foreach (InterfaceIPDetails ipInterface in interfaceDetailsList) {
221
					byte[] addressBytes = address.GetAddressBytes ();
221
					byte[] addressBytes = ipInterface.address.GetAddressBytes ();
222
					if (addressBytes[0] >= 224 && addressBytes[0] <= 239) {
222
					if (addressBytes[0] >= 224 && addressBytes[0] <= 239) {
223
						multicastAddresses.Add (address);
223
						multicastAddresses.Add (ipInterface.address);
224
					}
224
					}
225
				}
225
				}
226
				return MulticastIPAddressInformationImplCollection.LinuxFromList (multicastAddresses);
226
				return MulticastIPAddressInformationImplCollection.LinuxFromList (multicastAddresses);
Lines 229-248 Link Here
229
229
230
		public override UnicastIPAddressInformationCollection UnicastAddresses {
230
		public override UnicastIPAddressInformationCollection UnicastAddresses {
231
			get {
231
			get {
232
				List<IPAddress> unicastAddresses = new List<IPAddress> ();
232
				var unicastAddresses = new List<InterfaceIPDetails> ();
233
				foreach (IPAddress address in addresses) {
233
				foreach (InterfaceIPDetails ipInterface in interfaceDetailsList) {
234
					switch (address.AddressFamily) {
234
					switch (ipInterface.address.AddressFamily) {
235
						case AddressFamily.InterNetwork:
235
						case AddressFamily.InterNetwork:
236
							byte top = address.GetAddressBytes () [0];
236
							byte top = ipInterface.address.GetAddressBytes () [0];
237
							if (top >= 224 && top <= 239)
237
							if (top >= 224 && top <= 239)
238
								continue;
238
								continue;
239
							unicastAddresses.Add (address);
239
							unicastAddresses.Add (ipInterface);
240
							break;
240
							break;
241
241
242
						case AddressFamily.InterNetworkV6:
242
						case AddressFamily.InterNetworkV6:
243
							if (address.IsIPv6Multicast)
243
							if (ipInterface.address.IsIPv6Multicast)
244
								continue;
244
								continue;
245
							unicastAddresses.Add (address);
245
							unicastAddresses.Add (ipInterface);
246
							break;
246
							break;
247
					}
247
					}
248
				}
248
				}
Lines 261-268 Link Here
261
261
262
	class LinuxIPInterfaceProperties : UnixIPInterfaceProperties
262
	class LinuxIPInterfaceProperties : UnixIPInterfaceProperties
263
	{
263
	{
264
		public LinuxIPInterfaceProperties (LinuxNetworkInterface iface, List <IPAddress> addresses)
264
		public LinuxIPInterfaceProperties (LinuxNetworkInterface iface, List <InterfaceIPDetails> interfaceDetailsList)
265
			: base (iface, addresses)
265
			: base (iface, interfaceDetailsList)
266
		{
266
		{
267
		}
267
		}
268
268
Lines 277-284 Link Here
277
277
278
	class MacOsIPInterfaceProperties : UnixIPInterfaceProperties
278
	class MacOsIPInterfaceProperties : UnixIPInterfaceProperties
279
	{
279
	{
280
		public MacOsIPInterfaceProperties (MacOsNetworkInterface iface, List <IPAddress> addresses)
280
		public MacOsIPInterfaceProperties (MacOsNetworkInterface iface, List <InterfaceIPDetails> interfaceDetailsList)
281
			: base (iface, addresses)
281
			: base (iface, interfaceDetailsList)
282
		{
282
		{
283
		}
283
		}
284
284
(-)a/mcs/class/System/System.Net.NetworkInformation/NetworkInterface.cs (-13 / +28 lines)
Lines 114-121 Link Here
114
		public abstract bool SupportsMulticast { get; }
114
		public abstract bool SupportsMulticast { get; }
115
	}
115
	}
116
116
117
	// Interfaces IPAddress and other details.
118
	internal class InterfaceIPDetails
119
	{
120
		// The IPAddress
121
		internal IPAddress address { get; set; }
122
		// Interfaces netmask (can be IPAddress.None)
123
		internal IPAddress netmask { get; set; }
124
	}
125
	
117
	abstract class UnixNetworkInterface : NetworkInterface
126
	abstract class UnixNetworkInterface : NetworkInterface
118
	{
127
	{		
119
		[DllImport("libc")]
128
		[DllImport("libc")]
120
		static extern int if_nametoindex(string ifname);
129
		static extern int if_nametoindex(string ifname);
121
130
Lines 124-137 Link Here
124
		
133
		
125
		string               name;
134
		string               name;
126
		//int                  index;
135
		//int                  index;
127
		protected List <IPAddress> addresses;
136
		protected List <InterfaceIPDetails> interfaceDetailsList;
128
		byte[]               macAddress;
137
		byte[]               macAddress;
129
		NetworkInterfaceType type;
138
		NetworkInterfaceType type;
130
		
139
		
131
		internal UnixNetworkInterface (string name)
140
		internal UnixNetworkInterface (string name)
132
		{
141
		{
133
			this.name = name;
142
			this.name = name;
134
			addresses = new List<IPAddress> ();
143
			interfaceDetailsList = new List<InterfaceIPDetails> ();
135
		}
144
		}
136
145
137
		public static int IfNameToIndex (string ifname)
146
		public static int IfNameToIndex (string ifname)
Lines 139-147 Link Here
139
			return if_nametoindex(ifname);
148
			return if_nametoindex(ifname);
140
		}
149
		}
141
		
150
		
142
		internal void AddAddress (IPAddress address)
151
		internal void AddAddress (IPAddress address, IPAddress netmask)
143
		{
152
		{
144
			addresses.Add (address);
153
			interfaceDetailsList.Add (new InterfaceIPDetails { address = address , netmask = netmask });
145
		}
154
		}
146
155
147
		internal void SetLinkLayerInfo (int index, byte[] macAddress, NetworkInterfaceType type)
156
		internal void SetLinkLayerInfo (int index, byte[] macAddress, NetworkInterfaceType type)
Lines 164-173 Link Here
164
			bool wantIPv4 = networkInterfaceComponent == NetworkInterfaceComponent.IPv4;
173
			bool wantIPv4 = networkInterfaceComponent == NetworkInterfaceComponent.IPv4;
165
			bool wantIPv6 = wantIPv4 ? false : networkInterfaceComponent == NetworkInterfaceComponent.IPv6;
174
			bool wantIPv6 = wantIPv4 ? false : networkInterfaceComponent == NetworkInterfaceComponent.IPv6;
166
				
175
				
167
			foreach (IPAddress address in addresses) {
176
			foreach (InterfaceIPDetails ipInterface in interfaceDetailsList) {
168
				if (wantIPv4 && address.AddressFamily == AddressFamily.InterNetwork)
177
				if (wantIPv4 && ipInterface.address.AddressFamily == AddressFamily.InterNetwork)
169
					return true;
178
					return true;
170
				else if (wantIPv6 && address.AddressFamily == AddressFamily.InterNetworkV6)
179
				else if (wantIPv6 && ipInterface.address.AddressFamily == AddressFamily.InterNetworkV6)
171
					return true;
180
					return true;
172
			}
181
			}
173
			
182
			
Lines 242-247 Link Here
242
				while (next != IntPtr.Zero) {
251
				while (next != IntPtr.Zero) {
243
					ifaddrs   addr = (ifaddrs) Marshal.PtrToStructure (next, typeof (ifaddrs));
252
					ifaddrs   addr = (ifaddrs) Marshal.PtrToStructure (next, typeof (ifaddrs));
244
					IPAddress address = IPAddress.None;
253
					IPAddress address = IPAddress.None;
254
					IPAddress netmask = IPAddress.None;
245
					string    name = addr.ifa_name;
255
					string    name = addr.ifa_name;
246
					int       index = -1;
256
					int       index = -1;
247
					byte[]    macAddress = null;
257
					byte[]    macAddress = null;
Lines 249-260 Link Here
249
259
250
					if (addr.ifa_addr != IntPtr.Zero) {
260
					if (addr.ifa_addr != IntPtr.Zero) {
251
						sockaddr_in sockaddr = (sockaddr_in) Marshal.PtrToStructure (addr.ifa_addr, typeof (sockaddr_in));
261
						sockaddr_in sockaddr = (sockaddr_in) Marshal.PtrToStructure (addr.ifa_addr, typeof (sockaddr_in));
252
262
						
253
						if (sockaddr.sin_family == AF_INET6) {
263
						if (sockaddr.sin_family == AF_INET6) {
254
							sockaddr_in6 sockaddr6 = (sockaddr_in6) Marshal.PtrToStructure (addr.ifa_addr, typeof (sockaddr_in6));
264
							sockaddr_in6 sockaddr6 = (sockaddr_in6) Marshal.PtrToStructure (addr.ifa_addr, typeof (sockaddr_in6));
255
							address = new IPAddress (sockaddr6.sin6_addr.u6_addr8, sockaddr6.sin6_scope_id);
265
							address = new IPAddress (sockaddr6.sin6_addr.u6_addr8, sockaddr6.sin6_scope_id);
256
						} else if (sockaddr.sin_family == AF_INET) {
266
						} else if (sockaddr.sin_family == AF_INET) {
257
							address = new IPAddress (sockaddr.sin_addr);
267
							address = new IPAddress (sockaddr.sin_addr);
268
							if (addr.ifa_netmask != IntPtr.Zero)
269
							{
270
								sockaddr_in netmaskaddr = (sockaddr_in) Marshal.PtrToStructure (addr.ifa_netmask, typeof (sockaddr_in));
271
								netmask = new IPAddress (netmaskaddr.sin_addr);
272
							}
258
						} else if (sockaddr.sin_family == AF_PACKET) {
273
						} else if (sockaddr.sin_family == AF_PACKET) {
259
							sockaddr_ll sockaddrll = (sockaddr_ll) Marshal.PtrToStructure (addr.ifa_addr, typeof (sockaddr_ll));
274
							sockaddr_ll sockaddrll = (sockaddr_ll) Marshal.PtrToStructure (addr.ifa_addr, typeof (sockaddr_ll));
260
							if (((int)sockaddrll.sll_halen) > sockaddrll.sll_addr.Length){
275
							if (((int)sockaddrll.sll_halen) > sockaddrll.sll_addr.Length){
Lines 322-328 Link Here
322
					}
337
					}
323
338
324
					if (!address.Equals (IPAddress.None))
339
					if (!address.Equals (IPAddress.None))
325
						iface.AddAddress (address);
340
						iface.AddAddress (address, netmask);
326
341
327
					if (macAddress != null || type == NetworkInterfaceType.Loopback) {
342
					if (macAddress != null || type == NetworkInterfaceType.Loopback) {
328
						if (type == NetworkInterfaceType.Ethernet) {
343
						if (type == NetworkInterfaceType.Ethernet) {
Lines 359-365 Link Here
359
		public override IPInterfaceProperties GetIPProperties ()
374
		public override IPInterfaceProperties GetIPProperties ()
360
		{
375
		{
361
			if (ipproperties == null)
376
			if (ipproperties == null)
362
				ipproperties = new LinuxIPInterfaceProperties (this, addresses);
377
				ipproperties = new LinuxIPInterfaceProperties (this, interfaceDetailsList);
363
			return ipproperties;
378
			return ipproperties;
364
		}
379
		}
365
380
Lines 512-518 Link Here
512
					}
527
					}
513
528
514
					if (!address.Equals (IPAddress.None))
529
					if (!address.Equals (IPAddress.None))
515
						iface.AddAddress (address);
530
						iface.AddAddress (address, IPAddress.None);
516
531
517
					if (macAddress != null || type == NetworkInterfaceType.Loopback)
532
					if (macAddress != null || type == NetworkInterfaceType.Loopback)
518
						iface.SetLinkLayerInfo (index, macAddress, type);
533
						iface.SetLinkLayerInfo (index, macAddress, type);
Lines 540-546 Link Here
540
		public override IPInterfaceProperties GetIPProperties ()
555
		public override IPInterfaceProperties GetIPProperties ()
541
		{
556
		{
542
			if (ipproperties == null)
557
			if (ipproperties == null)
543
				ipproperties = new MacOsIPInterfaceProperties (this, addresses);
558
				ipproperties = new MacOsIPInterfaceProperties (this, interfaceDetailsList);
544
			return ipproperties;
559
			return ipproperties;
545
		}
560
		}
546
561
(-)a/mcs/class/System/System.Net.NetworkInformation/UnicastIPAddressInformation.cs (-2 / +4 lines)
Lines 123-132 Link Here
123
	class LinuxUnicastIPAddressInformation : UnicastIPAddressInformation
123
	class LinuxUnicastIPAddressInformation : UnicastIPAddressInformation
124
	{
124
	{
125
		IPAddress address;
125
		IPAddress address;
126
		IPAddress netmask;
126
127
127
		public LinuxUnicastIPAddressInformation (IPAddress address)
128
		public LinuxUnicastIPAddressInformation (IPAddress address, IPAddress netmask)
128
		{
129
		{
129
			this.address = address;
130
			this.address = address;
131
			this.netmask = netmask;
130
		}
132
		}
131
133
132
		public override IPAddress Address {
134
		public override IPAddress Address {
Lines 164-170 Link Here
164
		}
166
		}
165
167
166
		public override IPAddress IPv4Mask {
168
		public override IPAddress IPv4Mask {
167
			get { throw new NotImplementedException (); }
169
			get { return netmask; }
168
		}
170
		}
169
171
170
		public override PrefixOrigin PrefixOrigin {
172
		public override PrefixOrigin PrefixOrigin {
(-)a/mcs/class/System/System.Net.NetworkInformation/UnicastIPAddressInformationCollection.cs (-3 / +3 lines)
Lines 124-134 Link Here
124
			return c;
124
			return c;
125
		}
125
		}
126
126
127
		public static UnicastIPAddressInformationCollection LinuxFromList (List<IPAddress> addresses)
127
		public static UnicastIPAddressInformationCollection LinuxFromList (List<InterfaceIPDetails> interfaceDetailsList)
128
		{
128
		{
129
			UnicastIPAddressInformationImplCollection c = new UnicastIPAddressInformationImplCollection (false);
129
			UnicastIPAddressInformationImplCollection c = new UnicastIPAddressInformationImplCollection (false);
130
			foreach (IPAddress address in addresses) {
130
			foreach (InterfaceIPDetails ipInterface in interfaceDetailsList) {
131
				c.Add (new LinuxUnicastIPAddressInformation (address));
131
				c.Add (new LinuxUnicastIPAddressInformation (ipInterface.address, ipInterface.netmask));
132
			}
132
			}
133
			c.is_readonly = true;
133
			c.is_readonly = true;
134
			return c;
134
			return c;

Return to bug 2033