Merge pull request #409 from Alkarex/patch-1
[mono.git] / mcs / class / System / System.Net.NetworkInformation / MacOsNetworkInterfaceMarshal.cs
1 using System;
2 using System.Runtime.InteropServices;
3
4 namespace System.Net.NetworkInformation {
5         namespace MacOsStructs {
6                 internal struct ifaddrs
7                 {
8                         public IntPtr  ifa_next;
9                         public string  ifa_name;
10                         public uint    ifa_flags;
11                         public IntPtr  ifa_addr;
12                         public IntPtr  ifa_netmask;
13                         public IntPtr  ifa_dstaddr;
14                         public IntPtr  ifa_data;
15                 }
16
17                 internal struct sockaddr
18                 {
19                         public byte  sa_len;
20                         public byte  sa_family;
21                 }
22
23                 internal struct sockaddr_in
24                 {
25                         public byte   sin_len;
26                         public byte   sin_family;
27                         public ushort sin_port;
28                         public uint   sin_addr;
29                 }
30
31                 internal struct in6_addr
32                 {
33                         [MarshalAs (UnmanagedType.ByValArray, SizeConst=16)]
34                         public byte[] u6_addr8;
35                 }
36
37                 internal struct sockaddr_in6
38                 {
39                         public byte     sin6_len;
40                         public byte     sin6_family;
41                         public ushort   sin6_port;
42                         public uint     sin6_flowinfo;
43                         public in6_addr sin6_addr;
44                         public uint     sin6_scope_id;
45                 }
46
47                 internal struct sockaddr_dl
48                 {
49                         public byte   sdl_len;
50                         public byte   sdl_family;
51                         public ushort sdl_index;
52                         public byte   sdl_type;
53                         public byte   sdl_nlen;
54                         public byte   sdl_alen;
55                         public byte   sdl_slen;
56                         public byte[] sdl_data;
57                         
58                         internal void Read (IntPtr ptr)
59                         {
60                                 sdl_len = Marshal.ReadByte (ptr, 0);
61                                 sdl_family = Marshal.ReadByte (ptr, 1);
62                                 sdl_index = (ushort) Marshal.ReadInt16 (ptr, 2);
63                                 sdl_type = Marshal.ReadByte (ptr, 4);
64                                 sdl_nlen = Marshal.ReadByte (ptr, 5);
65                                 sdl_alen = Marshal.ReadByte (ptr, 6);
66                                 sdl_slen = Marshal.ReadByte (ptr, 7);
67                                 sdl_data = new byte [Math.Max (12, sdl_len - 8)];
68                                 Marshal.Copy (new IntPtr (ptr.ToInt64 () + 8), sdl_data, 0, sdl_data.Length);
69                         }
70                 }
71
72         }
73
74         internal enum MacOsArpHardware {
75                 ETHER = 0x6,
76                 ATM = 0x25,
77                 SLIP = 0x1c,
78                 PPP = 0x17,
79                 LOOPBACK = 0x18,
80                 FDDI = 0xf
81         }
82 }