/** * This module implements the lowest layer, which exposes the native * interface ({@link RawNetlinkSocket}) to create Netlink sockets and * send / receive raw data over them. Its API is intended to * mirror [`dgram.Socket`](https://nodejs.org/api/dgram.html). * @module */ /// import { EventEmitter } from 'events'; /** * Generates a unique port number to bind to, that is supposedly * not being used. However this is not a guarantee, especially * if you are using native addons that also create Netlink sockets * using other libraries (like libnl). * * Unique port numbers * are generated from the PID (lowest 16 bits) and a random number * for the highest 16 bits. * * @returns Unique port number */ export declare function generateLocalPort(): number; /** * Options for {@link RawNetlinkSocket} */ export interface RawNetlinkSocketOptions { /** Local port number to bind to */ localPort?: number; /** Local groups mask, deprecated (default: 0, i.e. no groups) */ localGroups?: number; /** Enable message peeking (default: true) */ messagePeeking?: boolean; /** Buffer size when receiving messages (ignored if message peeking is enabled) (default: 4kb) */ msgBufferSize?: number; /** Sets the `SO_RCVBUF` socket value. */ recvBufferSize: number; /** Sets the `SO_SNDBUF` socket value. */ sendBufferSize: number; } export interface MessageInfo { /** The sender port */ port: number; /** Sender groups bitmask, deprecated */ groups: number; /** Set if the message was truncated, indicates original size */ truncated?: number; } export interface RawNetlinkSendOptions { /** * Destination port (default: 0, i.e. the kernel) */ port?: number; /** * Destination groups bitmask, deprecated (default: 0, i.e. no groups) */ groups?: number; } export interface ErrnoException extends Error { name: 'ErrnoException'; /** name of the syscall that failed to execute */ syscall: string; /** error code */ errno: number; /** string constant corresponding to {@link errno} */ code: string; } interface EventMap { message(msg: Buffer, rinfo: MessageInfo): void; truncatedMessage(msg: Buffer, rinfo: MessageInfo): void; error(err: ErrnoException): void; close(): void; } /** * TODO * * Missing things: * - Credentials passing * * events: * `message` * `truncatedMessage` * `error` * `close` */ export declare class RawNetlinkSocket extends EventEmitter { emit(event: E, ...args: Parameters): boolean; on(event: E, listener: EventMap[E]): this; once(event: E, listener: EventMap[E]): this; off(event: E, listener: EventMap[E]): this; addListener(event: E, listener: EventMap[E]): this; removeListener(event: E, listener: EventMap[E]): this; private readonly __native; /** * Create a native Netlink socket, bound to the specified protocol * at the specified local address (port). * * If no port is passed, {@link generateLocalPort} will be used and * bind will be retried until we find a free address. * * @param protocol Netlink protocol to bind to (see {@link Protocol}) * @param options Socket options */ constructor(protocol: number, options?: RawNetlinkSocketOptions); private _receive; private _error; send(msg: Uint8Array | Uint8Array[], options?: RawNetlinkSendOptions, callback?: (error?: ErrnoException) => void): void; /** * Close the Netlink socket. After this, all other methods * can no longer be called. Messages pending to be sent * will be discarded, and its completion callback won't be * called. */ close(): void; /** * Return the address this socket is currently bound at. * * @returns Local address */ address(): { port: number; groups: number; }; /** * References this socket, preventing the event loop from * exiting while it is active. The socket is automatically * referenced when it is created. */ ref(): void; /** * Unreferences this socket. The socket is automatically * referenced when it is created. */ unref(): void; /** Joins the specified multicast group */ addMembership(group: number): void; /** Leaves the specified multicast group */ dropMembership(group: number): void; /** Returns the `SO_RCVBUF` socket receive buffer size in bytes */ getRecvBufferSize(): number; /** Returns the `SO_SNDBUF` socket send buffer size in bytes */ getSendBufferSize(): number; /** Sets the `SO_RCVBUF` socket option. Sets the maximum socket receive buffer in bytes. */ setRecvBufferSize(size: number): any; /** Sets the `SO_SNDBUF` socket option. Sets the maximum socket send buffer in bytes. */ setSendBufferSize(size: number): any; } export {};