1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-23 07:59:03 +00:00

Update the usage examples in match.lua

The example uses of nmap.receive_buf() were missing the second
parameter, keeppattern. Also referenced the match library from
nmap.receive_buf's NSEdoc to avoid reimplementations of buffered
sockets.
This commit is contained in:
dmiller
2014-02-10 19:39:09 +00:00
parent 4e7e7c04f0
commit 298c42d3b4
2 changed files with 12 additions and 7 deletions

View File

@@ -12,11 +12,11 @@ _ENV = stdnse.module("match", stdnse.seeall)
--various functions for use with nse's nsock:receive_buf - function --various functions for use with nse's nsock:receive_buf - function
-- e.g. -- e.g.
-- sock:receive_buf(regex("myregexpattern")) - does a match using pcre- regular- -- sock:receive_buf(regex("myregexpattern"), true) - does a match using pcre
-- - expressions -- regular expressions
-- sock:receive_buf(numbytes(80)) - is the buffered version of -- sock:receive_buf(numbytes(80), true) - is the buffered version of
-- sock:receive_bytes(80) - i.e. it returns -- sock:receive_bytes(80) - i.e. it
-- exactly 80 bytes and no more -- returns exactly 80 bytes and no more
--- Return a function that allows delimiting with a regular expression. --- Return a function that allows delimiting with a regular expression.
-- --
@@ -24,7 +24,7 @@ _ENV = stdnse.module("match", stdnse.seeall)
-- give script developers the ability to use regular expressions for delimiting -- give script developers the ability to use regular expressions for delimiting
-- instead of Lua's string patterns. -- instead of Lua's string patterns.
-- @param pattern The regex. -- @param pattern The regex.
-- @usage sock:receive_buf(match.regex("myregexpattern")) -- @usage sock:receive_buf(match.regex("myregexpattern"), true)
-- @see nmap.receive_buf -- @see nmap.receive_buf
-- @see pcre.exec -- @see pcre.exec
regex = function(pattern) regex = function(pattern)
@@ -42,8 +42,12 @@ end
-- <code>sock:receive_bytes(n)</code> in case a script requires more than one -- <code>sock:receive_bytes(n)</code> in case a script requires more than one
-- fixed-size chunk, as the unbuffered version may return more bytes than -- 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. -- requested and thus would require you to do the parsing on your own.
--
-- The <code>keeppattern</code> parameter to receive_buf should be set to
-- <code>true</code>, otherwise the string returned will be 1 less than
-- <code>num</code>
-- @param num Number of bytes. -- @param num Number of bytes.
-- @usage sock:receive_buf(match.numbytes(80)) -- @usage sock:receive_buf(match.numbytes(80), true)
-- @see nmap.receive_buf -- @see nmap.receive_buf
numbytes = function(num) numbytes = function(num)
local n = num local n = num

View File

@@ -608,6 +608,7 @@ function receive_bytes(n)
-- @return Status (true or false). -- @return Status (true or false).
-- @return Data (if status is true) or error string (if status is false). -- @return Data (if status is true) or error string (if status is false).
-- @see new_socket -- @see new_socket
-- @see match
-- @usage local status, line = socket:receive_buf("\r?\n", false) -- @usage local status, line = socket:receive_buf("\r?\n", false)
function receive_buf(delimiter, keeppattern) function receive_buf(delimiter, keeppattern)