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.
@@ -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
- }) => any;
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, };
@@ -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
  }
@@ -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 createNetlinkStructuresFor: ({ abi }: {
146
- abi: TAbi;
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: any;
150
- nlmsghdr: any;
151
- nlmsgerr: any;
155
+ sockaddrNl: TParserOf<typeof sockaddrNl>;
156
+ nlmsghdr: TParserOf<typeof nlmsghdr>;
157
+ nlmsgerr: TParserOf<typeof nlmsgerr>;
152
158
  };
153
- type TNetlinkStructures = ReturnType<typeof createNetlinkStructuresFor>;
154
- declare const hostStructures: {
159
+ declare const createNetlinkStructuresFor: ({ abi }: {
155
160
  abi: TAbi;
156
- sockaddrNl: any;
157
- nlmsghdr: any;
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
- }) => any;
172
+ }) => Uint8Array;
170
173
  export { sockaddrNlDefinition, nlmsghdrDefinition, nlmsgerrDefinition, createNetlinkStructuresFor, hostStructures, formatNetlinkAddress, };
171
174
  export type { TNetlinkStructures, };
@@ -40,11 +40,21 @@ const nlmsgerrDefinition = {
40
40
  ],
41
41
  } /*as const*/;
42
42
 
43
- const sockaddrNl = define({ definition: sockaddrNlDefinition });
44
- const nlmsghdr = define({ definition: nlmsghdrDefinition });
45
- const nlmsgerr = define({ definition: nlmsgerrDefinition });
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
- const createNetlinkStructuresFor = ({ abi }/*: { abi: TAbi }*/) => {
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
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.5",
2
+ "version": "0.0.6",
3
3
  "name": "node-netlink",
4
4
  "type": "module",
5
5
  "description": "The netlink protocol for Node.js on Linux, on top of sockets you own",