Library match

Buffered network I/O helper functions.

The functions in this module can be used for delimiting data received by the nmap.receive_buf function in the Network I/O API (which see).

Copyright © Same as Nmap--See https://nmap.org/book/man-legal.html

Source: https://svn.nmap.org/nmap/nselib/match.lua

Functions

numbytes (num)

Return a function that allows delimiting at a certain number of bytes.

pattern_limit (pattern, within)

Search for a pattern within a set number of bytes

Functions

numbytes (num)

Return a function that allows delimiting at a certain number of bytes.

This function can be used to get a buffered version of sock:receive_bytes(n) in case a script requires more than one fixed-size chunk, as the unbuffered version may return more bytes than requested and thus would require you to do the parsing on your own.

The keeppattern parameter to receive_buf should be set to true, otherwise the string returned will be 1 less than num

Parameters

num
Number of bytes.

Usage:

sock:receive_buf(match.numbytes(80), true)

See also:

pattern_limit (pattern, within)

Search for a pattern within a set number of bytes

This function behaves just like passing a pattern to receive_buf, but it will only receive a predefined number of bytes before returning the buffer.

Parameters

pattern
The pattern to search for
within
The number of bytes to consume

Usage:

sock:receive_buf(match.pattern_limit("\r\n", 80), true)