1
2
3
4
5 package oshi.jna.platform.mac;
6
7 import com.sun.jna.Native;
8 import com.sun.jna.Structure;
9 import com.sun.jna.Structure.FieldOrder;
10 import com.sun.jna.Union;
11
12 import oshi.jna.platform.unix.CLibrary;
13 import oshi.util.Util;
14
15
16
17
18
19 public interface SystemB extends com.sun.jna.platform.mac.SystemB, CLibrary {
20
21 SystemB INSTANCE = Native.load("System", SystemB.class);
22
23 int PROC_PIDLISTFDS = 1;
24 int PROX_FDTYPE_SOCKET = 2;
25 int PROC_PIDFDSOCKETINFO = 3;
26 int TSI_T_NTIMERS = 4;
27 int SOCKINFO_IN = 1;
28 int SOCKINFO_TCP = 2;
29
30 int UTX_USERSIZE = 256;
31 int UTX_LINESIZE = 32;
32 int UTX_IDSIZE = 4;
33 int UTX_HOSTSIZE = 256;
34
35 int AF_INET = 2;
36 int AF_INET6 = 30;
37
38
39
40
41 @FieldOrder({ "ut_user", "ut_id", "ut_line", "ut_pid", "ut_type", "ut_tv", "ut_host", "ut_pad" })
42 class MacUtmpx extends Structure {
43 public byte[] ut_user = new byte[UTX_USERSIZE];
44 public byte[] ut_id = new byte[UTX_IDSIZE];
45 public byte[] ut_line = new byte[UTX_LINESIZE];
46 public int ut_pid;
47 public short ut_type;
48 public Timeval ut_tv;
49 public byte[] ut_host = new byte[UTX_HOSTSIZE];
50 public byte[] ut_pad = new byte[16];
51 }
52
53
54
55
56 @FieldOrder({ "proc_fd", "proc_fdtype" })
57 class ProcFdInfo extends Structure {
58 public int proc_fd;
59 public int proc_fdtype;
60 }
61
62
63
64
65 @FieldOrder({ "insi_fport", "insi_lport", "insi_gencnt", "insi_flags", "insi_flow", "insi_vflag", "insi_ip_ttl",
66 "rfu_1", "insi_faddr", "insi_laddr", "insi_v4", "insi_v6" })
67 class InSockInfo extends Structure {
68 public int insi_fport;
69 public int insi_lport;
70 public long insi_gencnt;
71 public int insi_flags;
72 public int insi_flow;
73
74 public byte insi_vflag;
75 public byte insi_ip_ttl;
76 public int rfu_1;
77
78 public int[] insi_faddr = new int[4];
79 public int[] insi_laddr = new int[4];
80 public byte insi_v4;
81 public byte[] insi_v6 = new byte[9];
82 }
83
84
85
86
87 @FieldOrder({ "tcpsi_ini", "tcpsi_state", "tcpsi_timer", "tcpsi_mss", "tcpsi_flags", "rfu_1", "tcpsi_tp" })
88 class TcpSockInfo extends Structure {
89 public InSockInfo tcpsi_ini;
90 public int tcpsi_state;
91 public int[] tcpsi_timer = new int[TSI_T_NTIMERS];
92 public int tcpsi_mss;
93 public int tcpsi_flags;
94 public int rfu_1;
95 public long tcpsi_tp;
96 }
97
98
99
100
101 @FieldOrder({ "soi_stat", "soi_so", "soi_pcb", "soi_type", "soi_protocol", "soi_family", "soi_options",
102 "soi_linger", "soi_state", "soi_qlen", "soi_incqlen", "soi_qlimit", "soi_timeo", "soi_error", "soi_oobmark",
103 "soi_rcv", "soi_snd", "soi_kind", "rfu_1", "soi_proto" })
104 class SocketInfo extends Structure {
105 public long[] soi_stat = new long[17];
106 public long soi_so;
107 public long soi_pcb;
108 public int soi_type;
109 public int soi_protocol;
110 public int soi_family;
111 public short soi_options;
112 public short soi_linger;
113 public short soi_state;
114 public short soi_qlen;
115 public short soi_incqlen;
116 public short soi_qlimit;
117 public short soi_timeo;
118 public short soi_error;
119 public int soi_oobmark;
120 public int[] soi_rcv = new int[6];
121 public int[] soi_snd = new int[6];
122 public int soi_kind;
123 public int rfu_1;
124 public Pri soi_proto;
125 }
126
127
128
129
130 @FieldOrder({ "fi_openflags", "fi_status", "fi_offset", "fi_type", "fi_guardflags" })
131 class ProcFileInfo extends Structure {
132 public int fi_openflags;
133 public int fi_status;
134 public long fi_offset;
135 public int fi_type;
136 public int fi_guardflags;
137 }
138
139
140
141
142 @FieldOrder({ "pfi", "psi" })
143 class SocketFdInfo extends Structure implements AutoCloseable {
144 public ProcFileInfo pfi;
145 public SocketInfo psi;
146
147 @Override
148 public void close() {
149 Util.freeMemory(getPointer());
150 }
151 }
152
153
154
155
156 class Pri extends Union {
157 public InSockInfo pri_in;
158 public TcpSockInfo pri_tcp;
159
160 public byte[] max_size = new byte[524];
161 }
162
163
164
165
166
167
168
169
170
171 MacUtmpx getutxent();
172
173 int proc_pidfdinfo(int pid, int fd, int flavor, Structure buffer, int buffersize);
174 }