File: AixNetworkInterfaceMarshal.cs

package info (click to toggle)
mono 6.14.1%2Bds2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,282,732 kB
  • sloc: cs: 11,182,461; xml: 2,850,281; ansic: 699,123; cpp: 122,919; perl: 58,604; javascript: 30,841; asm: 21,845; makefile: 19,602; sh: 10,973; python: 4,772; pascal: 925; sql: 859; sed: 16; php: 1
file content (166 lines) | stat: -rw-r--r-- 4,873 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
using System.Runtime.InteropServices;

namespace System.Net.NetworkInformation {
	namespace AixStructs {
		//[StructLayout(LayoutKind.Sequential)]
		[StructLayout(LayoutKind.Explicit, Size = 16)]
		internal struct ifconf
		{
			[FieldOffset (0)]
			public int ifc_len; /* size of buffer */
			[FieldOffset (8)]
			public IntPtr ifc_buf; /* buffer address/array of structures returned */
		}

		// approximate the union members after the name with different structs
		[StructLayout (LayoutKind.Explicit, CharSet=CharSet.Ansi, Size=18)]
		internal unsafe struct ifreq
		{
			// it must be a byte array; a char array seems to want to be 2 bytes per element,
			// and a ByVal string doesn't want to seem to marshal properly for being written to
			[FieldOffset (0)]
			public fixed byte ifr_name [16];
			// you must peer into the family and length, then use ptr arith to get the rest
			[FieldOffset (16)]
			public sockaddr ifru_addr;
		}

		[StructLayout (LayoutKind.Explicit, CharSet=CharSet.Ansi, Size=24)]
		internal unsafe struct ifreq_addrin
		{
			[FieldOffset (0)]
			public fixed byte ifr_name [16];
			[FieldOffset (16)]
			public sockaddr_in ifru_addr;
		}

		// For SIOCGIFFLAGS
		[StructLayout (LayoutKind.Explicit, CharSet=CharSet.Ansi, Size=20)]
		internal unsafe struct ifreq_flags
		{
			[FieldOffset (0)]
			public fixed byte ifr_name [16];
			[FieldOffset (16)]
			public uint ifru_flags;
		}

		// For SIOCGIFMTU
		[StructLayout (LayoutKind.Explicit, CharSet=CharSet.Ansi, Size=20)]
		internal unsafe struct ifreq_mtu
		{
			[FieldOffset (0)]
			public fixed byte ifr_name [16];
			[FieldOffset (16)]
			public int ifru_mtu;
		}

		// the rest copied from Mac OS defs
		[StructLayout(LayoutKind.Sequential)]
		internal struct sockaddr
		{
			public byte  sa_len;
			public byte  sa_family;
		}

		[StructLayout(LayoutKind.Sequential)]
		internal struct sockaddr_in
		{
			public byte   sin_len;
			public byte   sin_family;
			public ushort sin_port;
			public uint   sin_addr;
		}

		[StructLayout(LayoutKind.Sequential)]
		internal struct in6_addr
		{
			[MarshalAs (UnmanagedType.ByValArray, SizeConst=16)]
			public byte[] u6_addr8;
		}

		[StructLayout(LayoutKind.Sequential)]
		internal struct sockaddr_in6
		{
			public byte     sin6_len;
			public byte     sin6_family;
			public ushort   sin6_port;
			public uint     sin6_flowinfo;
			public in6_addr sin6_addr;
			public uint     sin6_scope_id;
		}

		[StructLayout(LayoutKind.Sequential)]
		internal struct sockaddr_dl
		{
			public byte   sdl_len;
			public byte   sdl_family;
			public ushort sdl_index;
			public byte   sdl_type;
			public byte   sdl_nlen;
			public byte   sdl_alen;
			public byte   sdl_slen;
			public byte[] sdl_data;
			
			internal void Read (IntPtr ptr)
			{
				sdl_len = Marshal.ReadByte (ptr, 0);
				sdl_family = Marshal.ReadByte (ptr, 1);
				sdl_index = (ushort) Marshal.ReadInt16 (ptr, 2);
				sdl_type = Marshal.ReadByte (ptr, 4);
				sdl_nlen = Marshal.ReadByte (ptr, 5);
				sdl_alen = Marshal.ReadByte (ptr, 6);
				sdl_slen = Marshal.ReadByte (ptr, 7);
				sdl_data = new byte [Math.Max (12, sdl_len - 8)];
				Marshal.Copy (new IntPtr (ptr.ToInt64 () + 8), sdl_data, 0, sdl_data.Length);
			}
		}

	}

	// see: net/if_types.h
	internal enum AixArpHardware {
		ETHER = 0x6,
		ATM = 0x25,
		SLIP = 0x1c,
		PPP = 0x17,
		LOOPBACK = 0x18,
		FDDI = 0xf
	}

	// see: net/if.h
	internal enum AixInterfaceFlags {
		IFF_UP = 0x1,				/* interface is up */
		IFF_BROADCAST = 0x2,		/* broadcast address valid */
		IFF_DEBUG = 0x4,			/* turn on debugging */
		IFF_LOOPBACK = 0x8,			/* is a loopback net */
		IFF_POINTOPOINT = 0x10,		/* interface is point-to-point link */
		IFF_NOTRAILERS = 0x20,		/* avoid use of trailers */
		IFF_RUNNING = 0x40,			/* resources allocated */
		IFF_NOARP = 0x80,			/* no address resolution protocol */
		IFF_PROMISC = 0x100,		/* receive all packets */
		IFF_ALLMULTI = 0x200,		/* receive all multicast packets */
		IFF_OACTIVE = 0x400,		/* transmission in progress */
		IFF_SIMPLEX = 0x800,		/* can't hear own transmissions */
		IFF_LINK0 = 0x100000,			/* per link layer defined bit */
		IFF_LINK1 = 0x200000,			/* per link layer defined bit */
		IFF_LINK2 = 0x400000,			/* per link layer defined bit */
		IFF_MULTICAST = 0x8000000		/* supports multicast */
	}

	// Address families that matter to us
	internal enum AixAddressFamily {
		AF_INET  = 2,
		AF_INET6 = 24,
		AF_LINK  = 18,
	}

	// ioctl commands that matter to us
	internal enum AixIoctlRequest : uint {
		SIOCGSIZIFCONF = 0x4004696a, /* get the buffer size for SIOCGIFCONF */
                SIOCGIFCONF    = 0xc0106945, /* list network interfaces */
                SIOCGIFFLAGS   = 0xc0286911, /* get interface flags */
                SIOCGIFNETMASK = 0xc0286925, /* get netmask for iface */
                SIOCGIFMTU     = 0xc0286956, /* get mtu for iface */
	}
}