node-netlink 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/message.d.ts +3 -3
- package/dist/lib/message.js +3 -3
- package/dist/lib/structures.d.ts +17 -14
- package/dist/lib/structures.js +15 -7
- package/package.json +1 -1
package/dist/lib/message.d.ts
CHANGED
|
@@ -19,14 +19,14 @@ declare const nlmsgAlign: ({ length }: {
|
|
|
19
19
|
declare const parseMessages: ({ data, structures }: {
|
|
20
20
|
data: Uint8Array;
|
|
21
21
|
structures: TNetlinkStructures;
|
|
22
|
-
}) =>
|
|
22
|
+
}) => TNetlinkMessage[];
|
|
23
23
|
/**
|
|
24
24
|
* Formats a netlink message, nlmsg_len is calculated from the payload.
|
|
25
25
|
*/
|
|
26
26
|
declare const formatMessage: ({ message, structures }: {
|
|
27
27
|
message: TNetlinkMessage;
|
|
28
28
|
structures: TNetlinkStructures;
|
|
29
|
-
}) =>
|
|
29
|
+
}) => Uint8Array;
|
|
30
30
|
/**
|
|
31
31
|
* Whether the message terminates a request: NLMSG_ERROR (including acknowledgements) or NLMSG_DONE.
|
|
32
32
|
*/
|
|
@@ -40,6 +40,6 @@ declare const isTerminatingMessage: ({ message }: {
|
|
|
40
40
|
declare const errnoOfMessage: ({ message, structures }: {
|
|
41
41
|
message: TNetlinkMessage;
|
|
42
42
|
structures: TNetlinkStructures;
|
|
43
|
-
}) => number;
|
|
43
|
+
}) => number | undefined;
|
|
44
44
|
export { nlmsgAlign, parseMessages, formatMessage, errnoOfMessage, isTerminatingMessage, };
|
|
45
45
|
export type { TNetlinkHeader, TNetlinkMessage, };
|
package/dist/lib/message.js
CHANGED
|
@@ -46,7 +46,7 @@ const parseOneMessage = ({ data, structures }/*: { data: Uint8Array, structures:
|
|
|
46
46
|
* Splits a received datagram into its netlink messages.
|
|
47
47
|
* Throws if the datagram is malformed.
|
|
48
48
|
*/
|
|
49
|
-
const parseMessages = ({ data, structures }/*: { data: Uint8Array, structures: TNetlinkStructures }*/) => {
|
|
49
|
+
const parseMessages = ({ data, structures }/*: { data: Uint8Array, structures: TNetlinkStructures }*/)/*: TNetlinkMessage[]*/ => {
|
|
50
50
|
let messages/*: TNetlinkMessage[]*/ = [];
|
|
51
51
|
let remaining = data;
|
|
52
52
|
|
|
@@ -62,7 +62,7 @@ const parseMessages = ({ data, structures }/*: { data: Uint8Array, structures: T
|
|
|
62
62
|
/**
|
|
63
63
|
* Formats a netlink message, nlmsg_len is calculated from the payload.
|
|
64
64
|
*/
|
|
65
|
-
const formatMessage = ({ message, structures }/*: { message: TNetlinkMessage, structures: TNetlinkStructures }*/) => {
|
|
65
|
+
const formatMessage = ({ message, structures }/*: { message: TNetlinkMessage, structures: TNetlinkStructures }*/)/*: Uint8Array*/ => {
|
|
66
66
|
const { header, payload } = message;
|
|
67
67
|
|
|
68
68
|
const headerAsBuffer = structures.nlmsghdr.format({
|
|
@@ -95,7 +95,7 @@ const readInt32 = ({ payload, structures }/*: { payload: Uint8Array, structures:
|
|
|
95
95
|
* Extracts the errno of an NLMSG_ERROR or NLMSG_DONE message.
|
|
96
96
|
* Returns `undefined` for an acknowledgement (error 0) and for other message types.
|
|
97
97
|
*/
|
|
98
|
-
const errnoOfMessage = ({ message, structures }/*: { message: TNetlinkMessage, structures: TNetlinkStructures }*/) => {
|
|
98
|
+
const errnoOfMessage = ({ message, structures }/*: { message: TNetlinkMessage, structures: TNetlinkStructures }*/)/*: number | undefined*/ => {
|
|
99
99
|
if (!isTerminatingMessage({ message })) {
|
|
100
100
|
return undefined;
|
|
101
101
|
}
|
package/dist/lib/structures.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type TAbi } from "ya-struct";
|
|
1
|
+
import { define, type TAbi } from "ya-struct";
|
|
2
2
|
declare const sockaddrNlDefinition: {
|
|
3
3
|
readonly type: "struct";
|
|
4
4
|
readonly packed: false;
|
|
@@ -142,21 +142,24 @@ declare const nlmsgerrDefinition: {
|
|
|
142
142
|
};
|
|
143
143
|
}];
|
|
144
144
|
};
|
|
145
|
-
declare const
|
|
146
|
-
|
|
147
|
-
|
|
145
|
+
declare const sockaddrNl: ReturnType<typeof define<typeof sockaddrNlDefinition>>;
|
|
146
|
+
declare const nlmsghdr: ReturnType<typeof define<typeof nlmsghdrDefinition>>;
|
|
147
|
+
declare const nlmsgerr: ReturnType<typeof define<typeof nlmsgerrDefinition>>;
|
|
148
|
+
type TParserOf<T extends {
|
|
149
|
+
parser: (args: {
|
|
150
|
+
abi: TAbi;
|
|
151
|
+
}) => object;
|
|
152
|
+
}> = ReturnType<T["parser"]>;
|
|
153
|
+
type TNetlinkStructures = {
|
|
148
154
|
abi: TAbi;
|
|
149
|
-
sockaddrNl:
|
|
150
|
-
nlmsghdr:
|
|
151
|
-
nlmsgerr:
|
|
155
|
+
sockaddrNl: TParserOf<typeof sockaddrNl>;
|
|
156
|
+
nlmsghdr: TParserOf<typeof nlmsghdr>;
|
|
157
|
+
nlmsgerr: TParserOf<typeof nlmsgerr>;
|
|
152
158
|
};
|
|
153
|
-
|
|
154
|
-
declare const hostStructures: {
|
|
159
|
+
declare const createNetlinkStructuresFor: ({ abi }: {
|
|
155
160
|
abi: TAbi;
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
nlmsgerr: any;
|
|
159
|
-
};
|
|
161
|
+
}) => TNetlinkStructures;
|
|
162
|
+
declare const hostStructures: TNetlinkStructures;
|
|
160
163
|
/**
|
|
161
164
|
* Formats a struct sockaddr_nl, e.g. to bind() a netlink socket.
|
|
162
165
|
*/
|
|
@@ -166,6 +169,6 @@ declare const formatNetlinkAddress: ({ address, structures }: {
|
|
|
166
169
|
nl_groups: bigint;
|
|
167
170
|
};
|
|
168
171
|
structures?: TNetlinkStructures;
|
|
169
|
-
}) =>
|
|
172
|
+
}) => Uint8Array;
|
|
170
173
|
export { sockaddrNlDefinition, nlmsghdrDefinition, nlmsgerrDefinition, createNetlinkStructuresFor, hostStructures, formatNetlinkAddress, };
|
|
171
174
|
export type { TNetlinkStructures, };
|
package/dist/lib/structures.js
CHANGED
|
@@ -40,11 +40,21 @@ const nlmsgerrDefinition = {
|
|
|
40
40
|
],
|
|
41
41
|
} /*as const*/;
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
const
|
|
45
|
-
const
|
|
43
|
+
// spelled out, as the declaration files are generated per file and could not infer these types
|
|
44
|
+
const sockaddrNl/*: ReturnType<typeof define<typeof sockaddrNlDefinition>>*/ = define({ definition: sockaddrNlDefinition });
|
|
45
|
+
const nlmsghdr/*: ReturnType<typeof define<typeof nlmsghdrDefinition>>*/ = define({ definition: nlmsghdrDefinition });
|
|
46
|
+
const nlmsgerr/*: ReturnType<typeof define<typeof nlmsgerrDefinition>>*/ = define({ definition: nlmsgerrDefinition });
|
|
46
47
|
|
|
47
|
-
|
|
48
|
+
/*type TParserOf<T extends { parser: (args: { abi: TAbi }) => object }> = ReturnType<T["parser"]>;*/
|
|
49
|
+
|
|
50
|
+
/*type TNetlinkStructures = {
|
|
51
|
+
abi: TAbi;
|
|
52
|
+
sockaddrNl: TParserOf<typeof sockaddrNl>;
|
|
53
|
+
nlmsghdr: TParserOf<typeof nlmsghdr>;
|
|
54
|
+
nlmsgerr: TParserOf<typeof nlmsgerr>;
|
|
55
|
+
};*/
|
|
56
|
+
|
|
57
|
+
const createNetlinkStructuresFor = ({ abi }/*: { abi: TAbi }*/)/*: TNetlinkStructures*/ => {
|
|
48
58
|
return {
|
|
49
59
|
abi,
|
|
50
60
|
sockaddrNl: sockaddrNl.parser({ abi }),
|
|
@@ -53,8 +63,6 @@ const createNetlinkStructuresFor = ({ abi }/*: { abi: TAbi }*/) => {
|
|
|
53
63
|
};
|
|
54
64
|
};
|
|
55
65
|
|
|
56
|
-
/*type TNetlinkStructures = ReturnType<typeof createNetlinkStructuresFor>;*/
|
|
57
|
-
|
|
58
66
|
const hostStructures = createNetlinkStructuresFor({ abi: hostAbi });
|
|
59
67
|
|
|
60
68
|
/**
|
|
@@ -63,7 +71,7 @@ const hostStructures = createNetlinkStructuresFor({ abi: hostAbi });
|
|
|
63
71
|
const formatNetlinkAddress = ({ address, structures = hostStructures }/*: {
|
|
64
72
|
address: { nl_pid: bigint, nl_groups: bigint },
|
|
65
73
|
structures?: TNetlinkStructures,
|
|
66
|
-
}*/) => {
|
|
74
|
+
}*/)/*: Uint8Array*/ => {
|
|
67
75
|
return structures.sockaddrNl.format({
|
|
68
76
|
value: {
|
|
69
77
|
nl_family: AF_NETLINK,
|
package/package.json
CHANGED