File: nse_utility.h

package info (click to toggle)
nmap 7.40-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 50,080 kB
  • ctags: 26,777
  • sloc: ansic: 98,862; cpp: 64,063; python: 17,751; sh: 14,584; xml: 11,448; makefile: 2,635; perl: 2,585; yacc: 660; lex: 457; asm: 372; java: 45; objc: 43
file content (169 lines) | stat: -rw-r--r-- 5,829 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#ifndef NMAP_NSE_UTILITY_H
#define NMAP_NSE_UTILITY_H

class Port;
class Target;

#ifdef HAVE_CONFIG_H
#include "nmap_config.h"
#endif

#if HAVE_STDINT_H
#include <stdint.h>
#endif

/* int nseU_checkinteger (lua_State *L, int arg)
 *
 * Replacement for luaL_checkinteger that does a floor operation first
 */
int nseU_checkinteger (lua_State *L, int arg);

/* int nseU_traceback (lua_State *L)
 *
 * Traceback C Lua function.
 */
int nseU_traceback (lua_State *L);

/* int nseU_placeholder (lua_State *L)
 *
 * Placeholder C Lua function that simply throws a nil error.
 */
int nseU_placeholder (lua_State *L);

/* void nseU_tablen (lua_State *L, int idx)                [-0, +0, -]
 *
 * Calculates the number of entries in the table by iterating over
 * each key/value pair.
 */
size_t nseU_tablen (lua_State *L, int idx);

/* void nseU_setsfield (lua_State *L, int idx,             [-0, +0, e]
 *                      const char *field, const char *value)
 *
 * Sets the field for table at index idx to string value.
 *  (t[field] = value).
 */
void nseU_setsfield (lua_State *L, int idx, const char *field, const char *value);

/* void nseU_setnfield (lua_State *L, int idx,             [-0, +0, e]
 *                      const char *field, lua_Number value)
 *
 * Sets the field for table at index idx to numerical value.
 *  (t[field] = value).
 */
void nseU_setnfield (lua_State *L, int idx, const char *field, lua_Number value);

/* void nseU_setifield (lua_State *L, int idx,             [-0, +0, e]
 *                      const char *field, lua_Integer value)
 *
 * Sets the field for table at index idx to numerical value.
 *  (t[field] = value).
 */
void nseU_setifield (lua_State *L, int idx, const char *field, lua_Integer value);

/* void nseU_setbfield (lua_State *L, int idx,             [-0, +0, e]
 *                      const char *field, int value)
 *
 * Sets the field for table at index idx to boolean value.
 *  (t[field] = value).
 */
void nseU_setbfield (lua_State *L, int idx, const char *field, int value);

/* void nseU_appendfstr (lua_State *L, int idx,             [-0, +0, m]
 *                      const char *fmt, ...)
 *
 * Appends the formatted string to the table at index idx.
 */
void nseU_appendfstr (lua_State *L, int idx, const char *fmt, ...);

/* void nseU_weaktable (lua_State *L, int narr, int nrec,  [-0, +1, e]
 *                      const char *mode)
 *
 * Creates a table using lua_createtable with sizes narr and nrec. Creates
 * a metatable with its __mode field set to mode.
 */
void nseU_weaktable (lua_State *L, int narr, int nrec, const char *mode);

/* int nseU_success (lua_State *L)                         [-0, +1, -]
 *
 * Indicates successful return of the running function by pushing
 * boolean true and returning 1. Use as a tail call:
 *   return nseU_success(L);
 */
int nseU_success (lua_State *L);

/* int nseU_safeerror (lua_State *L, const char *fmt, ...) [-0, +1, -]
 *
 * Indicates unsuccessful return of the running function by pushing
 * boolean false and and a formatted error message. Use as a tail call:
 *   return nseU_safeerror(L, "%s", "a generic error");
 */
int nseU_safeerror (lua_State *L, const char *fmt, ...);

/* void nseU_typeerror (lua_State *L, int idx,             [-0, +1, v]
 *                      const char *err)
 *
 * Raises a type error. Same as Lua 5.1.
 */
void nseU_typeerror (lua_State *L, int idx, const char *err);

/* void *nseU_checkudata (lua_State *L, int idx,           [-0, +0, v]
 *                        int upvalue, const char *name)
 *
 * Checks that value at index idx is a full userdata which a metatable
 * equal to upvalue. name is the name of your object for error message
 * purposes.
 */
void *nseU_checkudata (lua_State *L, int idx, int upvalue, const char *name);

/* void nseU_checktarget (lua_State *L, int idx,           [-0, +0, v]
 *                        const char **address,
 *                        const char **targetname)
 *
 * Check for a valid target specification at index idx.  This function checks
 * for a string at idx or a table containing the typical host table fields,
 * 'ip' and 'targetname' in particular.
 *
 * The address and targetname string pointers are only valid if the target
 * specification persists.
 */
void nseU_checktarget (lua_State *L, int idx, const char **address, const char **targetname);

/* void nseU_opttarget (lua_State *L, int idx,           [-0, +0, v]
 *                      const char **address,
 *                      const char **targetname)
 *
 * Like nseU_checktarget, but sets *address and *targetname to NULL and returns
 * success if the argument at idx is none or nil.
 */
void nseU_opttarget (lua_State *L, int idx, const char **address, const char **targetname);

/* uint16_t nseU_checkport (lua_State *L, int idx,         [-0, +0, v]
 *                          const char **protocol)
 *
 * Check for a valid port specification at index idx.
 *
 * The protocol string pointer is only valid if the port specification
 * persists.
 */
uint16_t nseU_checkport (lua_State *L, int idx, const char **protocol);

/* Target *nseU_gettarget (lua_State *L, int idx)          [-0, +0, v]
 *
 * This function checks the value at index for a valid host table. It locates
 * the associated Target (C++) class object associated with the host and
 * returns it. If the Target is not being scanned then an error will be raised.
 */
Target *nseU_gettarget (lua_State *L, int idx);

/* Port *nseU_getport (lua_State *L, Target *target,       [-0, +0, v]
 *                     Port *port, int idx)
 *
 * This function checks the value at index for a valid port table. It locates
 * the associated Port (C++) class object associated with the host and
 * returns it.
 */
Port *nseU_getport (lua_State *L, Target *target, Port *port, int idx);

#endif