aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Morriss <jeff.morriss@ulticom.com>2007-10-16 15:58:25 +0000
committerJeff Morriss <jeff.morriss@ulticom.com>2007-10-16 15:58:25 +0000
commit53489c8f5d938b927419eb95861034c06f48bcfc (patch)
tree1461a99c8a44276f6a3ab3f1997fc1581ec4fd73
parent853e79144494125bdff6dc64db298483810e4045 (diff)
A few more s/fopen/eth_fopen/
svn path=/trunk/; revision=23207
-rw-r--r--epan/dfilter/dfilter-macro.c9
-rw-r--r--epan/wslua/init_wslua.c93
-rw-r--r--text2pcap.c17
3 files changed, 61 insertions, 58 deletions
diff --git a/epan/dfilter/dfilter-macro.c b/epan/dfilter/dfilter-macro.c
index 255874a321..a865c90cd7 100644
--- a/epan/dfilter/dfilter-macro.c
+++ b/epan/dfilter/dfilter-macro.c
@@ -38,6 +38,7 @@
#include <epan/uat.h>
#include <epan/report_err.h>
#include <epan/proto.h>
+#include <wiretap/file_util.h>
typedef struct {
const char* name;
@@ -60,9 +61,9 @@ static gboolean free_value(gpointer k _U_, gpointer v, gpointer u _U_) {
static gboolean fvt_cache_cb(proto_node * node, gpointer data _U_) {
field_info* finfo = node->finfo;
fvt_cache_entry_t* e;
-
+
if (!finfo) return FALSE;
-
+
if ((e = g_hash_table_lookup(fvt_cache,finfo->hfinfo->abbrev))) {
e->usable = FALSE;
} else if (finfo->value.ftype->val_to_string_repr) {
@@ -103,7 +104,7 @@ static void macro_fprint(dfilter_macro_t* m, void* ud) {
}
void dfilter_macro_save(const gchar* filename, gchar** error) {
- FILE* f = fopen(filename,"w");
+ FILE* f = eth_fopen(filename,"w");
if (!f) {
*error = ep_strdup_printf("Could not open file: '%s', error: %s\n", filename, strerror(errno) );
@@ -552,4 +553,4 @@ void dfilter_macro_get_uat(void** p) {
-
+
diff --git a/epan/wslua/init_wslua.c b/epan/wslua/init_wslua.c
index 285ddc20b1..6ce8273417 100644
--- a/epan/wslua/init_wslua.c
+++ b/epan/wslua/init_wslua.c
@@ -32,6 +32,7 @@
#include <epan/expert.h>
#include <epan/ex-opt.h>
#include <epan/privileges.h>
+#include <wiretap/file_util.h>
static lua_State* L = NULL;
@@ -46,70 +47,70 @@ dissector_handle_t lua_data_handle;
static int wslua_not_register_menu(lua_State* LS) {
luaL_error(LS,"too late to register a menu");
- return 0;
+ return 0;
}
void dissect_lua(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree) {
lua_pinfo = pinfo;
lua_tvb = tvb;
-
+
lua_tree = ep_alloc(sizeof(struct _wslua_treeitem));
lua_tree->tree = tree;
lua_tree->item = proto_tree_add_text(tree,tvb,0,0,"lua fake item");
PROTO_ITEM_SET_HIDDEN(lua_tree->item);
-
+
/*
* almost equivalent to Lua:
* dissectors[current_proto](tvb,pinfo,tree)
*/
-
+
lua_settop(L,0);
-
- lua_rawgeti(L, LUA_REGISTRYINDEX, lua_dissectors_table_ref);
-
+
+ lua_rawgeti(L, LUA_REGISTRYINDEX, lua_dissectors_table_ref);
+
lua_pushstring(L, pinfo->current_proto);
- lua_gettable(L, -2);
-
+ lua_gettable(L, -2);
+
lua_remove(L,1);
-
-
+
+
if (lua_isfunction(L,1)) {
-
+
push_Tvb(L,tvb);
push_Pinfo(L,pinfo);
push_TreeItem(L,lua_tree);
-
+
if ( lua_pcall(L,3,0,0) ) {
const gchar* error = lua_tostring(L,-1);
-
+
proto_item* pi = proto_tree_add_text(tree,tvb,0,0,"Lua Error: %s",error);
expert_add_info_format(pinfo, pi, PI_DEBUG, PI_ERROR ,"Lua Error");
}
} else {
proto_item* pi = proto_tree_add_text(tree,tvb,0,0,"Lua Error: did not find the %s dissector"
" in the dissectors table",pinfo->current_proto);
-
+
expert_add_info_format(pinfo, pi, PI_DEBUG, PI_ERROR ,"Lua Error");
}
-
+
clear_outstanding_tvbs();
clear_outstanding_pinfos();
clear_outstanding_trees();
-
-
+
+
lua_pinfo = NULL;
lua_tree = NULL;
lua_tvb = NULL;
-
+
}
static void iter_table_and_call(lua_State* LS, int env, const gchar* table_name, lua_CFunction error_handler) {
lua_settop(LS,0);
-
+
lua_pushcfunction(LS,error_handler);
lua_pushstring(LS, table_name);
lua_gettable(LS, env);
-
+
if (!lua_istable(LS, 2)) {
report_failure("Lua: either `%s' does not exist or it is not a table!\n",table_name);
lua_close(LS);
@@ -118,7 +119,7 @@ static void iter_table_and_call(lua_State* LS, int env, const gchar* table_name,
}
lua_pushnil(LS);
-
+
while (lua_next(LS, 2)) {
const gchar* name = lua_tostring(L,-2);
@@ -127,7 +128,7 @@ static void iter_table_and_call(lua_State* LS, int env, const gchar* table_name,
if ( lua_pcall(LS,0,0,1) ) {
lua_pop(LS,1);
}
-
+
} else {
report_failure("Lua: Something not a function got its way into the %s.%s",table_name,name);
lua_close(LS);
@@ -154,7 +155,7 @@ static void wslua_init_routine(void) {
lua_prime_all_fields(NULL);
initialized = TRUE;
}
-
+
if (L) {
iter_table_and_call(L, LUA_GLOBALSINDEX, WSLUA_INIT_ROUTINES,init_error_handler);
}
@@ -180,15 +181,15 @@ static int lua_main_error_handler(lua_State* LS) {
void lua_load_script(const gchar* filename) {
FILE* file;
- if (! ( file = fopen(filename,"r")) ) {
+ if (! ( file = eth_fopen(filename,"r")) ) {
report_open_failure(filename,errno,FALSE);
return;
}
lua_settop(L,0);
-
+
lua_pushcfunction(L,lua_main_error_handler);
-
+
switch (lua_load(L,getF,file,filename)) {
case 0:
lua_pcall(L,0,0,1);
@@ -204,7 +205,7 @@ void lua_load_script(const gchar* filename) {
fclose(file);
return;
}
-
+
}
static void basic_logger(const gchar *log_domain _U_,
@@ -223,7 +224,7 @@ int wslua_init(lua_State* LS) {
const gchar* filename;
const funnel_ops_t* ops = funnel_get_funnel_ops();
gboolean run_anyway = FALSE;
-
+
/* set up the logger */
g_log_set_handler(LOG_DOMAIN_LUA, G_LOG_LEVEL_CRITICAL|
G_LOG_LEVEL_WARNING|
@@ -231,23 +232,23 @@ int wslua_init(lua_State* LS) {
G_LOG_LEVEL_INFO|
G_LOG_LEVEL_DEBUG,
ops ? ops->logger : basic_logger, NULL);
-
+
if (!L) {
- if (LS)
+ if (LS)
L = LS;
else
L = luaL_newstate();
}
WSLUA_INIT(L);
-
+
lua_atpanic(L,wslua_panic);
-
+
/* the init_routines table (accessible by the user) */
lua_pushstring(L, WSLUA_INIT_ROUTINES);
lua_newtable (L);
lua_settable(L, LUA_GLOBALSINDEX);
-
+
/* the dissectors table goes in the registry (not accessible) */
lua_newtable (L);
lua_dissectors_table_ref = luaL_ref(L, LUA_REGISTRYINDEX);
@@ -257,15 +258,15 @@ int wslua_init(lua_State* LS) {
/* load system's init.lua */
filename = get_datafile_path("init.lua");
-
+
if (( file_exists(filename))) {
lua_load_script(filename);
}
-
+
/* check if lua is to be disabled */
lua_pushstring(L,"disable_lua");
lua_gettable(L, LUA_GLOBALSINDEX);
-
+
if (lua_isboolean(L,-1) && lua_toboolean(L,-1)) {
/* disable lua */
lua_close(L);
@@ -276,7 +277,7 @@ int wslua_init(lua_State* LS) {
/* check whether we should run other scripts even if running superuser */
lua_pushstring(L,"run_user_scripts_when_superuser");
lua_gettable(L, LUA_GLOBALSINDEX);
-
+
if (lua_isboolean(L,-1) && lua_toboolean(L,-1)) {
run_anyway = TRUE;
}
@@ -285,19 +286,19 @@ int wslua_init(lua_State* LS) {
/* if we are indeed superuser run user scripts only if told to do so */
if ( (!started_with_special_privs()) || run_anyway ) {
filename = get_persconffile_path("init.lua", FALSE);
-
+
if (( file_exists(filename))) {
lua_load_script(filename);
}
-
+
while((filename = ex_opt_get_next("lua_script"))) {
lua_load_script(filename);
}
}
-
+
/* at this point we're set up so register the init routine */
- register_init_routine(wslua_init_routine);
-
+ register_init_routine(wslua_init_routine);
+
/*
* after this point it is too late to register a menu
* disable the function to avoid weirdness
@@ -305,15 +306,15 @@ int wslua_init(lua_State* LS) {
lua_pushstring(L, "register_menu");
lua_pushcfunction(L, wslua_not_register_menu);
lua_settable(L, LUA_GLOBALSINDEX);
-
+
/* set up some essential globals */
lua_pinfo = NULL;
lua_tree = NULL;
lua_tvb = NULL;
-
+
lua_data_handle = find_dissector("data");
lua_malformed = proto_get_id_by_filter_name("malformed");
-
+
Proto_commit(L);
return 0;
diff --git a/text2pcap.c b/text2pcap.c
index 2499de846b..ee44fac128 100644
--- a/text2pcap.c
+++ b/text2pcap.c
@@ -85,6 +85,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <wiretap/file_util.h>
/*
* Just make sure we include the prototype for strptime as well
@@ -582,7 +583,7 @@ write_current_packet (void)
HDR_UDP.length = g_htons(proto_length);
HDR_UDP.checksum = 0;
- u = g_ntohs(in_checksum(&pseudoh, sizeof(pseudoh))) +
+ u = g_ntohs(in_checksum(&pseudoh, sizeof(pseudoh))) +
g_ntohs(in_checksum(&HDR_UDP, sizeof(HDR_UDP))) +
g_ntohs(in_checksum(packet_buf, curr_offset));
HDR_UDP.checksum = g_htons((u & 0xffff) + (u>>16));
@@ -600,7 +601,7 @@ write_current_packet (void)
HDR_TCP.window = g_htons(0x2000);
HDR_TCP.checksum = 0;
- u = g_ntohs(in_checksum(&pseudoh, sizeof(pseudoh))) +
+ u = g_ntohs(in_checksum(&pseudoh, sizeof(pseudoh))) +
g_ntohs(in_checksum(&HDR_TCP, sizeof(HDR_TCP))) +
g_ntohs(in_checksum(packet_buf, curr_offset));
HDR_TCP.checksum = g_htons((u & 0xffff) + (u>>16));
@@ -707,7 +708,7 @@ append_to_preamble(char *str)
char xs[PACKET_PREAMBLE_MAX_LEN];
strcpy(xs, packet_preamble);
while ((c = strchr(xs, '\r')) != NULL) *c=' ';
- fprintf (stderr, "[[append_to_preamble: \"%s\"]]", xs);
+ fprintf (stderr, "[[append_to_preamble: \"%s\"]]", xs);
}
}
}
@@ -767,7 +768,7 @@ parse_preamble (void)
fprintf (stderr, "Failure processing time \"%s\" using time format \"%s\"\n (defaulting to Jan 1,1970 00:00:00 GMT)\n",
packet_preamble, ts_fmt);
if (debug >= 2) {
- fprintf(stderr, "timecode: %02d/%02d/%d %02d:%02d:%02d %d\n",
+ fprintf(stderr, "timecode: %02d/%02d/%d %02d:%02d:%02d %d\n",
timecode.tm_mday, timecode.tm_mon, timecode.tm_year,
timecode.tm_hour, timecode.tm_min, timecode.tm_sec, timecode.tm_isdst);
}
@@ -809,7 +810,7 @@ parse_preamble (void)
if (debug >= 2) {
char *c;
while ((c = strchr(packet_preamble, '\r')) != NULL) *c=' ';
- fprintf(stderr, "[[parse_preamble: \"%s\"]]\n", packet_preamble);
+ fprintf(stderr, "[[parse_preamble: \"%s\"]]\n", packet_preamble);
fprintf(stderr, "Format(%s), time(%u), subsecs(%u)\n", ts_fmt, ts_sec, ts_usec);
}
@@ -1030,7 +1031,7 @@ usage (void)
" (.) but no pattern is required; the remaining number\n"
" is assumed to be fractions of a second.\n"
" NOTE: Date/time fields from the current date/time are\n"
- " used as the default for unspecified fields.\n"
+ " used as the default for unspecified fields.\n"
"\n"
"Output:\n"
" -l <typenum> link-layer type number. Default is 1 (Ethernet). \n"
@@ -1256,7 +1257,7 @@ parse_options (int argc, char *argv[])
if (strcmp(argv[optind], "-")) {
input_filename = strdup(argv[optind]);
- input_file = fopen(input_filename, "rb");
+ input_file = eth_fopen(input_filename, "rb");
if (!input_file) {
fprintf(stderr, "Cannot open file [%s] for reading: %s\n",
input_filename, strerror(errno));
@@ -1269,7 +1270,7 @@ parse_options (int argc, char *argv[])
if (strcmp(argv[optind+1], "-")) {
output_filename = strdup(argv[optind+1]);
- output_file = fopen(output_filename, "wb");
+ output_file = eth_fopen(output_filename, "wb");
if (!output_file) {
fprintf(stderr, "Cannot open file [%s] for writing: %s\n",
output_filename, strerror(errno));