aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/README.developer23
-rw-r--r--epan/diam_dict.l159
-rw-r--r--epan/dissectors/packet-giop.c3
-rw-r--r--epan/dissectors/packet-isakmp.c2
-rw-r--r--epan/dissectors/packet-ssl-utils.c19
-rw-r--r--epan/dissectors/packet-ssl.c3
-rw-r--r--epan/radius_dict.l92
-rw-r--r--epan/uat.c169
-rw-r--r--epan/uat_load.l55
-rw-r--r--wiretap/file_util.h6
-rw-r--r--wiretap/k12.c332
11 files changed, 440 insertions, 423 deletions
diff --git a/doc/README.developer b/doc/README.developer
index b07a84f938..ffe8accfd0 100644
--- a/doc/README.developer
+++ b/doc/README.developer
@@ -262,8 +262,15 @@ to include it explicitly - in order to get "open()", "close()",
"read()", "write()", etc. mapped to "_open()", "_close()", "_read()",
"_write()", etc..
-When opening a file with "fopen()", "freopen()", or "fdopen()", if the
-file contains ASCII text, use "r", "w", "a", and so on as the open mode
+Do not use "open()", "rename()", "mkdir()", "stat()", "unlink()", "remove()",
+"fopen()", "freopen()" directly. Instead use "eth_open()", "eth_rename()",
+"eth_mkdir()", "eth_stat()", "eth_unlink()", "eth_remove()", "eth_fopen()",
+"eth_freopen()": these wrapper functions change the path and file name from
+UTF8 to UTF16 on Windows allowing the functions to work correctly when the
+path or file name contain non-ASCII characters.
+
+When opening a file with "eth_fopen()", "eth_freopen()", or "eth_fdopen()", if
+the file contains ASCII text, use "r", "w", "a", and so on as the open mode
- but if it contains binary data, use "rb", "wb", and so on. On
Windows, if a file is opened in a text mode, writing a byte with the
value of octal 12 (newline) to the file causes two bytes, one with the
@@ -274,7 +281,7 @@ lines that end with newline and Windows' DEC-style lines that end with
carriage return/line feed).
In addition, that also means that when opening or creating a binary
-file, you must use "open()" (with O_CREAT and possibly O_TRUNC if the
+file, you must use "eth_open()" (with O_CREAT and possibly O_TRUNC if the
file is to be created if it doesn't exist), and OR in the O_BINARY flag.
That flag is not present on most, if not all, UNIX systems, so you must
also do
@@ -1338,7 +1345,7 @@ fence does not already exist.
1.5.9 The col_set_time function.
-The 'col_set_time' function takes a nstime value as it's third argument.
+The 'col_set_time' function takes a nstime value as it's third argument.
This nstime value is a relative value and will be added as such to the
column. The fourth argument is the filtername holding this value. This
way, rightclicking on the column makes it possible to build a filter
@@ -2847,16 +2854,16 @@ So add the following items to the struct that is used for the protocol data:
nstime_t ts_first;
nstime_t ts_prev;
-The ts_prev value should only be set during the first run through the
+The ts_prev value should only be set during the first run through the
packets (ie pinfo->fd->flags.visited is false).
Next step is to use the per packet information (described in section 2.5)
to keep the calculated delta timestamp, as it can only be calculated
-on the first run through the packets. This is because a packet can be
+on the first run through the packets. This is because a packet can be
selected in random order once the whole file has been read.
After calculating the conversation timestamps, it is time to put them in
-the appropriate columns with the function 'col_set_time' (described in
+the appropriate columns with the function 'col_set_time' (described in
section 1.5.9). There are two columns for conversation timestamps:
COL_REL_CONV_TIME, /* Relative time to beginning of conversation */
@@ -2873,7 +2880,7 @@ timestamp columns give the user the power to control these columns.
data structure which uses additional memory, which should be avoided
if these timestamps are not needed)
-Have a look at the differences to packet-tcp.[ch] in SVN 22966 and
+Have a look at the differences to packet-tcp.[ch] in SVN 22966 and
SVN 23058 to see the implementation of conversation timestamps for
the tcp-dissector.
diff --git a/epan/diam_dict.l b/epan/diam_dict.l
index 754bfd6af0..1927845689 100644
--- a/epan/diam_dict.l
+++ b/epan/diam_dict.l
@@ -55,11 +55,11 @@
** Foundation, Inc., 51 Franklin Street, Fifth Floor,
** Boston, MA 02110-1301, USA.
*/
-
+
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
-
+
#include <glib.h>
#include <stdio.h>
#include <string.h>
@@ -69,6 +69,7 @@
#include "emem.h"
#include "diam_dict.h"
#include "diam_dict_lex.h"
+#include <wiretap/file_util.h>
typedef struct entity_t {
char* name;
@@ -175,7 +176,7 @@ application_end<\/application>
command_start <command
command_end<\/command>
-typedefn_start <typedefn
+typedefn_start <typedefn
avp_start <avp
avp_end <\/avp>
@@ -206,7 +207,7 @@ description_attr description=\042
%S GET_ATTR GET_UINT_ATTR END_ATTR OUTSIDE IN_DICT IN_APPL IN_AVP APPL_ATTRS IGNORE_ATTR
%S TYPE_ATTRS GAVP_ATTRS ENUM_ATTRS AVP_ATTRS VENDOR_ATTRS COMMAND_ATTRS TYPEDEFN_ATTRS
%S XMLPI_ATTRS XMLPI_GETKEY XMLPI_GETVAL XMLPI_ENDATTR
-%%
+%%
<LOADING>{doctype} ;
<LOADING>{doctype_end} ;
@@ -222,10 +223,10 @@ description_attr description=\042
xmlpi->key = NULL;
xmlpi->value = NULL;
xmlpi->next = NULL;
-
+
if (!dict->xmlpis) last_xmlpi = dict->xmlpis = xmlpi;
else last_xmlpi = last_xmlpi->next = xmlpi;
-
+
BEGIN XMLPI_ATTRS;
}
@@ -273,9 +274,9 @@ description_attr description=\042
<LOADING>{entity} {
char* p = ++yytext;
entity_t* e;
-
+
while(*p != ';') p++;
-
+
*p = '\0';
D(("looking for entity: %s\n",yytext));
@@ -284,10 +285,10 @@ description_attr description=\042
fprintf(stderr, "included files nested to deeply\n");
yyterminate();
}
-
+
include_stack[include_stack_ptr++] = YY_CURRENT_BUFFER;
-
+
for (e = ents.next; e; e = e->next) {
if (strcmp(e->name,yytext) == 0) {
yyin = ddict_open(sys_dir,e->file);
@@ -304,20 +305,20 @@ description_attr description=\042
break;
}
}
-
+
if (!e) {
fprintf(stderr, "Could not find entity: '%s'", e->name );
yyterminate();
}
-
+
}
-<<EOF>> {
+<<EOF>> {
if (!yyin) yyterminate();
-
+
fclose(yyin);
D(("closing: %p %i\n",yyin,include_stack_ptr));
-
+
if ( --include_stack_ptr < 0 ) {
D(("DONE READING\n"));
yyin = NULL;
@@ -369,12 +370,12 @@ description_attr description=\042
<IN_DICT>{applictation_start} {
D(("applictation_start\n"));
-
+
appl = g_malloc(sizeof(ddict_application_t));
appl->name = NULL;
appl->code = 0;
appl->next = NULL;
-
+
if (!dict->applications) last_appl = dict->applications = appl;
else last_appl = last_appl->next = appl;
@@ -389,18 +390,18 @@ description_attr description=\042
<IN_APPL>{command_end} ;
-<IN_APPL>{command_start} {
+<IN_APPL>{command_start} {
D(("command_start\n"));
-
+
cmd = g_malloc(sizeof(ddict_cmd_t));
cmd->name = NULL;
cmd->vendor = NULL;
cmd->code = 0;
cmd->next = NULL;
-
+
if (!dict->cmds) last_cmd = dict->cmds = cmd;
else last_cmd = last_cmd->next = cmd;
-
+
BEGIN COMMAND_ATTRS;
}
@@ -412,15 +413,15 @@ description_attr description=\042
<IN_APPL>{vendor_start} {
D(("vendor_start\n"));
-
+
vnd = g_malloc(sizeof(ddict_vendor_t));
vnd->name = NULL;
vnd->code = 0;
vnd->next = NULL;
-
+
if (!dict->vendors) last_vnd = dict->vendors = vnd;
else last_vnd = last_vnd->next = vnd;
-
+
BEGIN VENDOR_ATTRS;
}
@@ -432,15 +433,15 @@ description_attr description=\042
<IN_APPL>{typedefn_start} {
D(("typedefn_start\n"));
-
+
typedefn = g_malloc(sizeof(ddict_typedefn_t));
typedefn->name = NULL;
typedefn->parent = NULL;
typedefn->next = NULL;
-
+
if (!dict->typedefns) last_typedefn = dict->typedefns = typedefn;
else last_typedefn = last_typedefn->next = typedefn;
-
+
BEGIN TYPEDEFN_ATTRS;
}
@@ -452,7 +453,7 @@ description_attr description=\042
<IN_APPL>{avp_start} {
D(("avp_start\n"));
-
+
avp = g_malloc(sizeof(ddict_avp_t));
avp->name = NULL;
avp->description = NULL;
@@ -462,7 +463,7 @@ description_attr description=\042
avp->enums = NULL;
avp->gavps = NULL;
avp->next = NULL;
-
+
if (! dict->avps ) last_avp = dict->avps = avp;
else last_avp = last_avp->next = avp;
@@ -483,14 +484,14 @@ description_attr description=\042
<IN_AVP>{type_start} { BEGIN TYPE_ATTRS; }
<TYPE_ATTRS>{typename_attr} { ATTR_STR(avp->type); }
-<IN_AVP>{gavp_start} {
+<IN_AVP>{gavp_start} {
D(("gavp_start\n"));
-
+
gavp = g_malloc(sizeof(ddict_gavp_t));
gavp->name = NULL;
gavp->code = 0;
gavp->next = NULL;
-
+
if (!avp->gavps) last_gavp = avp->gavps = gavp;
else last_gavp = last_gavp->next = gavp;
@@ -501,14 +502,14 @@ description_attr description=\042
<GAVP_ATTRS>{name_attr} { ATTR_STR(gavp->name); }
-<IN_AVP>{enum_start} {
+<IN_AVP>{enum_start} {
D(("enum_start\n"));
-
+
enumitem = g_malloc(sizeof(ddict_enum_t));
enumitem->name = NULL;
enumitem->code = 0;
enumitem->next = NULL;
-
+
if (!avp->enums) last_enumitem = avp->enums = enumitem;
else last_enumitem = last_enumitem->next = enumitem;
@@ -548,11 +549,11 @@ static int debugging = 0;
static void ddict_debug(const char* fmt, ...) {
va_list ap;
-
+
va_start(ap, fmt);
if (debugging) vfprintf(stderr, fmt, ap);
va_end(ap);
-
+
fflush(stderr);
}
@@ -574,12 +575,12 @@ static void append_to_buffer(char* txt, int len) {
if (strbuf == NULL) {
read_ptr = write_ptr = strbuf = g_malloc(size_strbuf);
}
-
+
if ( (len_strbuf + len) >= size_strbuf ) {
read_ptr = strbuf = g_realloc(strbuf,size_strbuf *= 2);
}
-
- write_ptr = strbuf + len_strbuf;
+
+ write_ptr = strbuf + len_strbuf;
strncpy(write_ptr,txt,len);
len_strbuf += len;
@@ -587,13 +588,13 @@ static void append_to_buffer(char* txt, int len) {
static size_t file_input(char* buf, size_t max) {
size_t read;
-
+
read = fread(buf,1,max,yyin);
if ( read == max ) {
return max;
} else if (read > 0) {
- return read;
+ return read;
} else {
return YY_NULL;
}
@@ -609,8 +610,8 @@ static size_t string_input(char* buf, size_t max) {
memcpy(buf,read_ptr,max);
read_ptr += max;
-
- return max;
+
+ return max;
}
static FILE* ddict_open(const char* system_directory, const char* filename) {
@@ -623,8 +624,8 @@ static FILE* ddict_open(const char* system_directory, const char* filename) {
} else {
fname = strdup(filename);
}
-
- fh = fopen(fname,"r");
+
+ fh = eth_fopen(fname,"r");
D(("fname: %s fh: %p\n",fname,fh));
@@ -635,9 +636,9 @@ static FILE* ddict_open(const char* system_directory, const char* filename) {
}
ddict_t* ddict_scan(const char* system_directory, const char* filename, int dbg) {
-
+
debugging = dbg;
-
+
sys_dir = system_directory;
yyin = ddict_open(sys_dir,filename);
@@ -646,10 +647,10 @@ ddict_t* ddict_scan(const char* system_directory, const char* filename, int dbg)
D(("unable to open %s\n", filename));
return NULL;
}
-
+
write_ptr = NULL;
read_ptr = NULL;
-
+
dict = g_malloc(sizeof(ddict_t));
dict->applications = NULL;
dict->cmds = NULL;
@@ -657,7 +658,7 @@ ddict_t* ddict_scan(const char* system_directory, const char* filename, int dbg)
dict->typedefns = NULL;
dict->avps = NULL;
dict->xmlpis = NULL;
-
+
appl = NULL;
avp = NULL;
enumitem = NULL;
@@ -666,7 +667,7 @@ ddict_t* ddict_scan(const char* system_directory, const char* filename, int dbg)
cmd = NULL;
vnd = NULL;
xmlpi = NULL;
-
+
last_appl = NULL;
last_avp = NULL;
last_enumitem = NULL;
@@ -680,9 +681,9 @@ ddict_t* ddict_scan(const char* system_directory, const char* filename, int dbg)
current_yyinput = file_input;
BEGIN LOADING;
yylex();
-
+
D(("\n---------------\n%s\n------- %d -------\n",strbuf,len_strbuf));
-
+
current_yyinput = string_input;
BEGIN OUTSIDE;
@@ -691,7 +692,7 @@ ddict_t* ddict_scan(const char* system_directory, const char* filename, int dbg)
g_free(strbuf);
strbuf = NULL;
size_strbuf = 8192;
-
+
return dict;
}
@@ -703,50 +704,50 @@ void ddict_free(ddict_t* d) {
ddict_avp_t *a, *an;
#define FREE_NAMEANDOBJ(n) do { if(n->name) g_free(n->name); g_free(n); } while(0)
-
+
for (p = d->applications; p; p = pn ) {
pn = p->next;
FREE_NAMEANDOBJ(p);
}
-
+
for (v = d->vendors; v; v = vn) {
- vn = v->next;
+ vn = v->next;
if (!v->desc) g_free(v->desc);
FREE_NAMEANDOBJ(v);
}
-
+
for (c = d->cmds; c; c = cn ) {
cn = c->next;
FREE_NAMEANDOBJ(c);
}
-
+
for (t = d->typedefns; t; t = tn) {
- tn = t->next;
+ tn = t->next;
if (!t->parent) g_free(t->parent);
FREE_NAMEANDOBJ(t);
}
-
+
for (a = d->avps; a; a = an) {
ddict_gavp_t* g, *gn;
ddict_enum_t* e, *en;
an = a->next;
-
+
for (g = a->gavps; g; g = gn) {
gn = g->next;
FREE_NAMEANDOBJ(g);
}
-
+
for (e = a->enums; e; e = en) {
en = e->next;
FREE_NAMEANDOBJ(e);
}
-
+
if (!a->vendor) g_free(a->vendor);
if (!a->type) g_free(a->type);
if (!a->description) g_free(a->description);
FREE_NAMEANDOBJ(a);
}
-
+
g_free(d);
}
@@ -756,24 +757,24 @@ void ddict_print(FILE* fh, ddict_t* d) {
ddict_cmd_t* c;
ddict_typedefn_t* t;
ddict_avp_t* a;
-
-
+
+
for (p = d->applications; p; p = p->next) {
fprintf(fh,"Application: %s[%u]:\n",
p->name ? p->name : "-",
p->code);
}
-
+
for (v = d->vendors; v; v = v->next) {
fprintf(fh,"Vendor: %s[%u]:\n",
v->name ? v->name : "-",
v->code);
}
-
+
for (c = d->cmds; c; c = c->next) {
fprintf(fh,"Command: %s[%u] \n",
c->name ? c->name : "-",
- c->code);
+ c->code);
}
for (t = d->typedefns; t; t = t->next) {
@@ -781,14 +782,14 @@ void ddict_print(FILE* fh, ddict_t* d) {
t->name ? t->name : "-",
t->parent ? t->parent : "" );
}
-
+
for (a = d->avps; a; a = a->next) {
ddict_gavp_t* g;
ddict_enum_t* e;
fprintf(fh,"AVP: %s[%u:%s] %s %s\n",
a->name ? a->name : "-",
- a->code,
- a->vendor ? a->vendor : "None",
+ a->code,
+ a->vendor ? a->vendor : "None",
a->type ? a->type : "-",
a->description ? a->description : "");
@@ -796,7 +797,7 @@ void ddict_print(FILE* fh, ddict_t* d) {
fprintf(fh,"\tGAVP: %s\n",
g->name ? g->name : "-" );
}
-
+
for (e = a->enums; e; e = e->next) {
fprintf(fh,"\tEnum: %s[%u]\n",
e->name ? e->name : "-",
@@ -811,20 +812,20 @@ int main(int argc, char** argv) {
char* dname = NULL;
char* fname;
int i = 1;
-
+
switch (argc) {
case 3:
dname = argv[i++];
- case 2:
+ case 2:
fname = argv[i];
break;
default:
fprintf(stderr,"%s: usage [dictionary_dir] dictionary_filename\n",argv[0]);
return 1;
}
-
+
d = ddict_scan(dname,fname,1);
-
+
ddict_print(stdout, d);
return 0;
diff --git a/epan/dissectors/packet-giop.c b/epan/dissectors/packet-giop.c
index 1a0275124b..c5d3fe28b2 100644
--- a/epan/dissectors/packet-giop.c
+++ b/epan/dissectors/packet-giop.c
@@ -301,6 +301,7 @@
#include "packet-giop.h"
#include "packet-tcp.h"
+#include <wiretap/file_util.h>
/*
* Set to 1 for DEBUG output - TODO make this a runtime option
@@ -1289,7 +1290,7 @@ static void read_IOR_strings_from_file(const gchar *name, int max_iorlen) {
gboolean stream_is_big_endian;
- fp = fopen(name,"r"); /* open read only */
+ fp = eth_fopen(name,"r"); /* open read only */
if (fp == NULL) {
if (errno == EACCES)
diff --git a/epan/dissectors/packet-isakmp.c b/epan/dissectors/packet-isakmp.c
index c2ebfe2451..79cfc00637 100644
--- a/epan/dissectors/packet-isakmp.c
+++ b/epan/dissectors/packet-isakmp.c
@@ -3181,7 +3181,7 @@ isakmp_init_protocol(void) {
G_ALLOC_AND_FREE);
if (logf)
fclose(logf);
- logf = fopen(pluto_log_path, "r");
+ logf = eth_fopen(pluto_log_path, "r");
scan_pluto_log();
#endif /* HAVE_LIBNETTLE */
diff --git a/epan/dissectors/packet-ssl-utils.c b/epan/dissectors/packet-ssl-utils.c
index af1a2e1d71..0626fce489 100644
--- a/epan/dissectors/packet-ssl-utils.c
+++ b/epan/dissectors/packet-ssl-utils.c
@@ -36,6 +36,7 @@
#include "packet-ssl-utils.h"
#include <epan/emem.h>
+#include <wiretap/file_util.h>
/*
* Lookup tables
@@ -312,9 +313,9 @@ const value_string ssl_31_ciphersuite[] = {
{ 0x001d, "SSL_FORTEZZA_KEA_WITH_FORTEZZA_CBC_SHA" },
#if 0 /* Because it clashes with KRB5, is never used any more, and is safe
to remove according to David Hopwood <david.hopwood@zetnet.co.uk>
- of the ietf-tls list */
+ of the ietf-tls list */
{ 0x001e, "SSL_FORTEZZA_KEA_WITH_RC4_128_SHA" },
-#endif
+#endif
/* RFC 2712 */
{ 0x001E, "TLS_KRB5_WITH_DES_CBC_SHA" },
@@ -336,7 +337,7 @@ const value_string ssl_31_ciphersuite[] = {
{ 0x002C, "TLS_PSK_WITH_NULL_SHA" },
{ 0x002D, "TLS_DHE_PSK_WITH_NULL_SHA" },
{ 0x002E, "TLS_RSA_PSK_WITH_NULL_SHA" },
-
+
/* RFC 3268 */
{ 0x002F, "TLS_RSA_WITH_AES_128_CBC_SHA" },
{ 0x0030, "TLS_DH_DSS_WITH_AES_128_CBC_SHA" },
@@ -350,7 +351,7 @@ const value_string ssl_31_ciphersuite[] = {
{ 0x0038, "TLS_DHE_DSS_WITH_AES_256_CBC_SHA" },
{ 0x0039, "TLS_DHE_RSA_WITH_AES_256_CBC_SHA" },
{ 0x003A, "TLS_DH_anon_WITH_AES_256_CBC_SHA" },
-
+
/* ??? */
{ 0x0060, "TLS_RSA_EXPORT1024_WITH_RC4_56_MD5" },
{ 0x0061, "TLS_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5" },
@@ -375,7 +376,7 @@ const value_string ssl_31_ciphersuite[] = {
{ 0x0087, "TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA" },
{ 0x0088, "TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA" },
{ 0x0089, "TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA" },
-
+
/* RFC 4279 */
{ 0x008A, "TLS_PSK_WITH_RC4_128_SHA" },
{ 0x008B, "TLS_PSK_WITH_3DES_EDE_CBC_SHA" },
@@ -397,7 +398,7 @@ const value_string ssl_31_ciphersuite[] = {
{ 0x0099, "TLS_DHE_DSS_WITH_SEED_CBC_SHA" },
{ 0x009A, "TLS_DHE_RSA_WITH_SEED_CBC_SHA" },
{ 0x009B, "TLS_DH_anon_WITH_SEED_CBC_SHA" },
-
+
/* From RFC 4492 */
{ 0xc001, "TLS_ECDH_ECDSA_WITH_NULL_SHA" },
{ 0xc002, "TLS_ECDH_ECDSA_WITH_RC4_128_SHA" },
@@ -435,7 +436,7 @@ const value_string ssl_31_ciphersuite[] = {
{ 0xC020, "TLS_SRP_SHA_WITH_AES_256_CBC_SHA" },
{ 0xC021, "TLS_SRP_SHA_RSA_WITH_AES_256_CBC_SHA" },
{ 0xC022, "TLS_SRP_SHA_DSS_WITH_AES_256_CBC_SHA" },
-
+
/* these from http://www.mozilla.org/projects/
security/pki/nss/ssl/fips-ssl-ciphersuites.html */
{ 0xfefe, "SSL_RSA_FIPS_WITH_DES_CBC_SHA"},
@@ -2396,7 +2397,7 @@ ssl_parse_key_list(const gchar * keys_list, GHashTable *key_hash, GTree* associa
ip[0], ip[1], ip[2], ip[3], service->port, filename);
/* try to load pen file*/
- fp = fopen(filename, "rb");
+ fp = eth_fopen(filename, "rb");
if (!fp) {
fprintf(stderr, "can't open file %s \n",filename);
continue;
@@ -2485,7 +2486,7 @@ ssl_set_debug(char* name)
else if (!name || (strcmp(name, "") ==0))
ssl_debug_file = NULL;
else
- ssl_debug_file = fopen(name, "w");
+ ssl_debug_file = eth_fopen(name, "w");
if (!use_stderr && ssl_debug_file)
debug_file_must_be_closed = 1;
}
diff --git a/epan/dissectors/packet-ssl.c b/epan/dissectors/packet-ssl.c
index 55efbd03cd..c4b60da5cb 100644
--- a/epan/dissectors/packet-ssl.c
+++ b/epan/dissectors/packet-ssl.c
@@ -119,6 +119,7 @@
#include "inet_v6defs.h"
#include "packet-ssl.h"
#include "packet-ssl-utils.h"
+#include <wiretap/file_util.h>
static gboolean ssl_desegment = TRUE;
@@ -331,7 +332,7 @@ ssl_parse(void)
if (ssl_keys_list && (ssl_keys_list[0] != 0))
{
if (file_exists(ssl_keys_list)) {
- if ((ssl_keys_file = fopen(ssl_keys_list, "r"))) {
+ if ((ssl_keys_file = eth_fopen(ssl_keys_list, "r"))) {
read_failed = FALSE;
fstat(fileno(ssl_keys_file), &statb);
size = statb.st_size;
diff --git a/epan/radius_dict.l b/epan/radius_dict.l
index dcdd5c18a6..749f33568e 100644
--- a/epan/radius_dict.l
+++ b/epan/radius_dict.l
@@ -51,11 +51,11 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-
+
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
-
+
#include <glib.h>
#include <stdio.h>
#include <stdlib.h>
@@ -64,19 +64,21 @@
#include <epan/packet.h>
#include <epan/dissectors/packet-radius.h>
#include "radius_dict_lex.h"
+#include <wiretap/file_util.h>
+
#define ECHO
#define MAX_INCLUDE_DEPTH 10
void add_vendor(const gchar* name, guint32 vendor_id);
void add_value(const gchar* attrib_name,const gchar* value_repr, long value);
void add_attribute(const gchar*,const gchar*, radius_attr_dissector_t,const gchar*, gboolean, gboolean);
-
+
static YY_BUFFER_STATE include_stack[10];
static int include_stack_ptr = 0;
-
+
static radius_dictionary_t* dict = NULL;
static GHashTable* value_strings = NULL; /* GArray(value_string) by attribute name */
-
+
static gchar* attr_name = NULL;
static gchar* attr_id = NULL;
static radius_attr_dissector_t* attr_type = NULL;
@@ -86,12 +88,12 @@
static gboolean encrypted = FALSE;
static gboolean has_tag = FALSE;
static gchar* current_vendor = NULL;
-
+
static GString* error = NULL;
static gchar* directory = NULL;
static int linenums[] = {1,1,1,1,1,1,1,1,1,1};
static gchar* fullpaths[] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
-
+
%}
%START WS_OUT VENDOR VENDOR_W_NAME ATTR ATTR_W_NAME ATTR_W_ID ATTR_W_TYPE ATTR_W_VENDOR VALUE VALUE_W_ATTR VALUE_W_NAME INCLUDE JUNK BEGIN_VENDOR END_VENDOR
@@ -175,7 +177,7 @@
g_free(attr_id);
g_free(attr_vendor);
g_free(attr_name);
- linenums[include_stack_ptr]++;
+ linenums[include_stack_ptr]++;
BEGIN WS_OUT;
};
@@ -189,14 +191,14 @@
g_string_sprintfa(error, "$INCLUDE files nested to deeply\n");
yyterminate();
}
-
+
include_stack[include_stack_ptr++] = YY_CURRENT_BUFFER;
-
+
fullpaths[include_stack_ptr] = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s",
directory,yytext);
- yyin = fopen( fullpaths[include_stack_ptr], "r" );
-
+ yyin = eth_fopen( fullpaths[include_stack_ptr], "r" );
+
if (!yyin) {
if (errno) {
g_string_sprintfa(error, "Could not open file: '%s', error: %s\n", fullpaths[include_stack_ptr], strerror(errno) );
@@ -206,22 +208,22 @@
linenums[include_stack_ptr] = 1;
yy_switch_to_buffer(yy_create_buffer( yyin, YY_BUF_SIZE ) );
}
-
+
BEGIN WS_OUT;
}
<<EOF>> {
-
+
fclose(yyin);
yyin = NULL;
-
+
if ( --include_stack_ptr < 0 ) {
yyterminate();
} else {
g_free(fullpaths[include_stack_ptr+1]);
fullpaths[include_stack_ptr+1] = NULL;
-
+
yy_delete_buffer( YY_CURRENT_BUFFER );
yy_switch_to_buffer(include_stack[include_stack_ptr]);
}
@@ -236,12 +238,12 @@
void add_vendor(const gchar* name, guint32 vendor_id) {
radius_vendor_info_t* v = g_malloc(sizeof(radius_vendor_info_t));
-
+
v->name = g_strdup(name);
v->code = vendor_id;
v->attrs_by_id = g_hash_table_new(g_direct_hash,g_direct_equal);
v->ett = -1;
-
+
g_hash_table_insert(dict->vendors_by_id,GUINT_TO_POINTER(v->code),v);
g_hash_table_insert(dict->vendors_by_name, (gpointer) v->name, v);
}
@@ -249,11 +251,11 @@ void add_vendor(const gchar* name, guint32 vendor_id) {
void add_attribute(const gchar* name, const gchar* code, radius_attr_dissector_t type, const gchar* vendor_name, gboolean crypt, gboolean tagged) {
radius_attr_info_t* a = g_malloc(sizeof(radius_attr_info_t));
GHashTable* by_id;
-
+
if (vendor_name) {
radius_vendor_info_t* v;
v = g_hash_table_lookup(dict->vendors_by_name,vendor_name);
-
+
if (! v) {
g_string_sprintfa(error, "Vendor: '%s', does not exist in %s:%i \n", vendor_name, fullpaths[include_stack_ptr], linenums[include_stack_ptr] );
BEGIN JUNK;
@@ -264,7 +266,7 @@ void add_attribute(const gchar* name, const gchar* code, radius_attr_dissector_
} else {
by_id = dict->attrs_by_id;
}
-
+
a->name = g_strdup(name);
a->code = strtol(code,NULL,10);
a->encrypt = crypt;
@@ -277,7 +279,7 @@ void add_attribute(const gchar* name, const gchar* code, radius_attr_dissector_
a->hf_tag = -1;
a->hf_len = -1;
a->ett = -1;
-
+
g_hash_table_insert(by_id,GUINT_TO_POINTER(a->code),a);
g_hash_table_insert(dict->attrs_by_name,(gpointer) (a->name),a);
}
@@ -285,15 +287,15 @@ void add_attribute(const gchar* name, const gchar* code, radius_attr_dissector_
void add_value(const gchar* attrib_name, const gchar* value_repr, long value) {
value_string v;
GArray* a = g_hash_table_lookup(value_strings,attrib_name);
-
+
if (! a) {
a = g_array_new(TRUE,TRUE,sizeof(value_string));
g_hash_table_insert(value_strings,g_strdup(attrib_name),a);
}
-
+
v.value = value;
v.strptr = g_strdup(value_repr);
-
+
g_array_append_val(a,v);
}
@@ -301,12 +303,12 @@ void add_value(const gchar* attrib_name, const gchar* value_repr, long value) {
static void setup_attrs(gpointer k _U_, gpointer v, gpointer p _U_) {
radius_attr_info_t* a = v;
gpointer key;
-
+
union {
GArray* a;
gpointer p;
} vs;
-
+
if (g_hash_table_lookup_extended(value_strings,a->name,&key,&vs.p) ) {
a->vs = (value_string*) vs.a->data;
g_array_free(vs.a,FALSE);
@@ -317,19 +319,19 @@ static void setup_attrs(gpointer k _U_, gpointer v, gpointer p _U_) {
static void setup_vendors(gpointer k _U_, gpointer v, gpointer p) {
radius_vendor_info_t* vnd = v;
-
- g_hash_table_foreach(vnd->attrs_by_id,setup_attrs,p);
+
+ g_hash_table_foreach(vnd->attrs_by_id,setup_attrs,p);
}
static gboolean destroy_value_strings(gpointer k, gpointer v, gpointer p _U_) {
value_string* vs = (value_string*)(((GArray*)v)->data);
-
+
g_free(k);
-
+
for (;vs->strptr;vs++) {
g_free((void*)vs->strptr);
}
-
+
g_array_free(v,TRUE);
return TRUE;
}
@@ -337,7 +339,7 @@ static gboolean destroy_value_strings(gpointer k, gpointer v, gpointer p _U_) {
static gboolean destroy_attrs(gpointer k _U_, gpointer v, gpointer p _U_) {
radius_attr_info_t* a = v;
int i;
-
+
g_free((gpointer) (a->name));
if (a->vs) {
for(i=0; a->vs[i].strptr; i++) {
@@ -360,7 +362,7 @@ static gboolean destroy_vendors(gpointer k _U_, gpointer v, gpointer p) {
static void destroy_dict(radius_dictionary_t* d) {
g_hash_table_foreach_remove(d->attrs_by_id,destroy_attrs,NULL);
- g_hash_table_foreach_remove(d->vendors_by_id,destroy_vendors,NULL);
+ g_hash_table_foreach_remove(d->vendors_by_id,destroy_vendors,NULL);
g_hash_table_destroy(d->vendors_by_id);
g_hash_table_destroy(d->attrs_by_id);
g_hash_table_destroy(d->vendors_by_name);
@@ -370,16 +372,16 @@ static void destroy_dict(radius_dictionary_t* d) {
radius_dictionary_t* radius_load_dictionary (gchar* dir, const gchar* filename, gchar** err_str) {
int i;
-
+
directory = dir;
-
+
fullpaths[include_stack_ptr] = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s",
directory,filename);
-
+
error = g_string_new("");
- yyin = fopen(fullpaths[include_stack_ptr],"r");
-
+ yyin = eth_fopen(fullpaths[include_stack_ptr],"r");
+
if (!yyin) {
g_string_sprintfa(error, "Could not open file: '%s', error: %s\n", fullpaths[include_stack_ptr], strerror(errno) );
g_free(fullpaths[include_stack_ptr]);
@@ -393,24 +395,24 @@ radius_dictionary_t* radius_load_dictionary (gchar* dir, const gchar* filename,
dict->attrs_by_name = g_hash_table_new(g_str_hash,g_str_equal);
dict->vendors_by_id = g_hash_table_new(g_direct_hash,g_direct_equal);
dict->vendors_by_name = g_hash_table_new(g_str_hash,g_str_equal);
-
+
value_strings = g_hash_table_new(g_str_hash,g_str_equal);
-
+
BEGIN WS_OUT;
yylex();
if (yyin != NULL) fclose(yyin);
yyin = NULL;
-
+
for (i=0; i < 10; i++) {
if (fullpaths[i]) g_free(fullpaths[i]);
}
-
+
g_hash_table_foreach(dict->attrs_by_id,setup_attrs,NULL);
- g_hash_table_foreach(dict->vendors_by_id,setup_vendors,NULL);
+ g_hash_table_foreach(dict->vendors_by_id,setup_vendors,NULL);
g_hash_table_foreach_remove(value_strings,destroy_value_strings,NULL);
-
+
if (error->len > 0) {
*err_str = error->str;
g_string_free(error,FALSE);
diff --git a/epan/uat.c b/epan/uat.c
index 1d3dd753af..b5148753c9 100644
--- a/epan/uat.c
+++ b/epan/uat.c
@@ -11,17 +11,17 @@
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 2001 Gerald Combs
- *
+ *
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
@@ -43,6 +43,7 @@
#include <epan/filesystem.h>
#include <epan/packet.h>
#include <epan/range.h>
+#include <wiretap/file_util.h>
#include "uat-int.h"
@@ -65,14 +66,14 @@ uat_t* uat_new(const char* name,
uat_field_t* flds_array) {
uat_t* uat = g_malloc(sizeof(uat_t));
guint i;
-
+
if (!all_uats)
all_uats = g_ptr_array_new();
-
+
g_ptr_array_add(all_uats,uat);
-
+
g_assert(name && size && filename && data_ptr && numitems_ptr);
-
+
uat->name = g_strdup(name);
uat->record_size = size;
uat->filename = g_strdup(filename);
@@ -89,23 +90,23 @@ uat_t* uat_new(const char* name,
uat->free_rep = NULL;
uat->help = help;
uat->category = category;
-
+
for (i=0;flds_array[i].name;i++) {
fld_data_t* f = g_malloc(sizeof(fld_data_t));
-
+
f->colnum = i+1;
f->rep = NULL;
f->free_rep = NULL;
-
+
flds_array[i].priv = f;
}
-
+
uat->ncols = i;
-
-
+
+
*data_ptr = NULL;
*numitems_ptr = 0;
-
+
return uat;
}
@@ -113,22 +114,22 @@ void* uat_add_record(uat_t* uat, const void* data) {
void* rec;
g_array_append_vals (uat->user_data, data, 1);
-
+
rec = uat->user_data->data + (uat->record_size * (uat->user_data->len-1));
-
+
if (uat->copy_cb) {
uat->copy_cb(rec, data, uat->record_size);
}
-
+
UAT_UPDATE(uat);
-
+
return rec;
}
void uat_swap(uat_t* uat, guint a, guint b) {
guint s = uat->record_size;
void* tmp = ep_alloc(s);
-
+
g_assert( a < uat->user_data->len && b < uat->user_data->len );
if (a == b) return;
@@ -140,15 +141,15 @@ void uat_swap(uat_t* uat, guint a, guint b) {
}
void uat_remove_record_idx(uat_t* uat, guint idx) {
-
+
g_assert( idx < uat->user_data->len );
if (uat->free_cb) {
uat->free_cb(UAT_INDEX_PTR(uat,idx));
}
-
+
g_array_remove_index(uat->user_data, idx);
-
+
UAT_UPDATE(uat);
}
@@ -158,52 +159,52 @@ gchar* uat_get_actual_filename(uat_t* uat, gboolean for_writing) {
if (! for_writing ) {
gchar* data_fname = get_datafile_path(uat->filename);
-
+
if (file_exists(data_fname)) {
return data_fname;
}
}
-
+
if ((! file_exists(pers_fname) ) && (! for_writing ) ) {
return NULL;
}
-
+
return pers_fname;
}
static void putfld(FILE* fp, void* rec, uat_field_t* f) {
guint fld_len;
const char* fld_ptr;
-
+
f->cb.tostr(rec,&fld_ptr,&fld_len,f->cbdata.tostr,f->fld_data);
-
+
switch(f->mode){
case PT_TXTMOD_ENUM:
case PT_TXTMOD_STRING: {
guint i;
-
+
putc('"',fp);
-
+
for(i=0;i<fld_len;i++) {
char c = fld_ptr[i];
-
+
if (c == '"' || c == '\\' || ! isprint((guchar)c) ) {
fprintf(fp,"\\x%.2x",c);
} else {
putc(c,fp);
}
}
-
+
putc('"',fp);
return;
}
case PT_TXTMOD_HEXBYTES: {
guint i;
-
+
for(i=0;i<fld_len;i++) {
fprintf(fp,"%.2x",((guint8*)fld_ptr)[i]);
}
-
+
return;
}
default:
@@ -215,11 +216,11 @@ gboolean uat_save(uat_t* uat, char** error) {
guint i;
gchar* fname = uat_get_actual_filename(uat,TRUE);
FILE* fp;
-
+
if (! fname ) return FALSE;
- fp = fopen(fname,"w");
-
+ fp = eth_fopen(fname,"w");
+
if (!fp) {
*error = ep_strdup_printf("uat_save: error opening '%s': %s",fname,strerror(errno));
return FALSE;
@@ -228,15 +229,15 @@ gboolean uat_save(uat_t* uat, char** error) {
*error = NULL;
fprintf(fp,"# This file is automatically generated, DO NOT MODIFY.\n");
-
+
for ( i = 0 ; i < uat->user_data->len ; i++ ) {
void* rec = uat->user_data->data + (uat->record_size * i);
uat_field_t* f;
guint j;
f = uat->fields;
-
-
+
+
for( j=0 ; j < uat->ncols ; j++ ) {
putfld(fp, rec, &(f[j]));
fputs((j == uat->ncols - 1) ? "\n" : "," ,fp);
@@ -245,16 +246,16 @@ gboolean uat_save(uat_t* uat, char** error) {
}
fclose(fp);
-
+
uat->changed = FALSE;
-
+
return TRUE;
}
void uat_destroy(uat_t* uat) {
/* XXX still missing a destructor */
g_ptr_array_remove(all_uats,uat);
-
+
}
void uat_clear(uat_t* uat) {
@@ -265,9 +266,9 @@ void uat_clear(uat_t* uat) {
uat->free_cb(UAT_INDEX_PTR(uat,i));
}
}
-
+
g_array_set_size(uat->user_data,0);
-
+
*((uat)->user_ptr) = NULL;
*((uat)->nrows_p) = 0;
}
@@ -295,24 +296,24 @@ void uat_cleanup(void) {
void uat_foreach_table(uat_cb_t cb,void* user_data) {
guint i;
-
+
for (i=0; i < all_uats->len; i++)
cb(g_ptr_array_index(all_uats,i), user_data);
-
-}
+
+}
void uat_load_all(void) {
guint i;
gchar* err;
-
+
for (i=0; i < all_uats->len; i++) {
uat_t* u = g_ptr_array_index(all_uats,i);
err = NULL;
-
+
if (!u->loaded)
uat_load(u, &err);
-
+
if (err) {
report_failure("Error loading table '%s': %s",u->name,err);
}
@@ -325,7 +326,7 @@ gboolean uat_fld_chk_str(void* u1 _U_, const char* strptr, unsigned len _U_, voi
*err = "NULL pointer";
return FALSE;
}
-
+
*err = NULL;
return TRUE;
}
@@ -335,7 +336,7 @@ gboolean uat_fld_chk_proto(void* u1 _U_, const char* strptr, unsigned len, void*
char* name = ep_strndup(strptr,len);
g_strdown(name);
g_strchug(name);
-
+
if (find_dissector(name)) {
*err = NULL;
return TRUE;
@@ -345,19 +346,19 @@ gboolean uat_fld_chk_proto(void* u1 _U_, const char* strptr, unsigned len, void*
}
} else {
*err = NULL;
- return TRUE;
+ return TRUE;
}
}
gboolean uat_fld_chk_num_dec(void* u1 _U_, const char* strptr, unsigned len, void* u2 _U_, void* u3 _U_, const char** err) {
char* str = ep_strndup(strptr,len);
long i = strtol(str,&str,10);
-
+
if ( ( i == 0) && (errno == ERANGE || errno == EINVAL) ) {
*err = strerror(errno);
return FALSE;
}
-
+
*err = NULL;
return TRUE;
}
@@ -365,12 +366,12 @@ gboolean uat_fld_chk_num_dec(void* u1 _U_, const char* strptr, unsigned len, voi
gboolean uat_fld_chk_num_hex(void* u1 _U_, const char* strptr, unsigned len, void* u2 _U_, void* u3 _U_, const char** err) {
char* str = ep_strndup(strptr,len);
long i = strtol(str,&str,16);
-
+
if ( ( i == 0) && (errno == ERANGE || errno == EINVAL) ) {
*err = strerror(errno);
return FALSE;
}
-
+
*err = NULL;
return TRUE;
}
@@ -379,7 +380,7 @@ gboolean uat_fld_chk_enum(void* u1 _U_, const char* strptr, unsigned len, void*
char* str = ep_strndup(strptr,len);
guint i;
value_string* vs = v;
-
+
for(i=0;vs[i].strptr;i++) {
if (g_str_equal(vs[i].strptr,str)) {
*err = NULL;
@@ -395,7 +396,7 @@ gboolean uat_fld_chk_range(void* u1 _U_, const char* strptr, unsigned len, void*
char* str = ep_strndup(strptr,len);
range_t* r = NULL;
convert_ret_t ret = range_convert_str(&r, str,GPOINTER_TO_UINT(u3));
-
+
switch ( ret ) {
case CVT_NO_ERROR:
*err = NULL;
@@ -415,7 +416,7 @@ gboolean uat_fld_chk_range(void* u1 _U_, const char* strptr, unsigned len, void*
static int xton(char d) {
switch(d) {
case '0': return 0;
- case '1': return 1;
+ case '1': return 1;
case '2': return 2;
case '3': return 3;
case '4': return 4;
@@ -438,23 +439,23 @@ char* uat_unbinstring(const char* si, guint in_len, guint* len_p) {
guint8* buf;
guint len = in_len/2;
int i = 0;
-
+
if (in_len%2) {
return NULL;
}
-
+
buf= g_malloc(len);
*len_p = len;
-
+
while(in_len) {
int d1 = xton(*(si++));
int d0 = xton(*(si++));
-
+
buf[i++] = (d1 * 16) + d0;
-
+
in_len -= 2;
}
-
+
return (void*)buf;
}
@@ -477,27 +478,27 @@ char* uat_unesc(const char* si, guint in_len, guint* len_p) {
case 'r': *(p++) = '\r'; len++; break;
case 't': *(p++) = '\t'; len++; break;
case 'v': *(p++) = '\v'; len++; break;
-
+
case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
{
int c0 = 0;
int c1 = 0;
int c2 = 0;
int c = 0;
-
+
c0 = (*s) - '0';
-
+
if ( s[1] >= '0' && s[1] <= '7' ) {
c1 = c0;
c0 = (*++s) - '0';
-
+
if ( s[1] >= '0' && s[1] <= '7' ) {
c2 = c1;
c1 = c0;
@@ -506,15 +507,15 @@ char* uat_unesc(const char* si, guint in_len, guint* len_p) {
}
c = (64 * c2) + (8 * c1) + c0;
*(p++) = (char) (c > 255 ? 255 : c);
- len++;
+ len++;
break;
}
-
+
case 'x':
{
char c1 = *(s+1);
char c0 = *(s+2);
-
+
if (isxdigit((guchar)c1) && isxdigit((guchar)c0)) {
*(p++) = (xton(c1) * 0x10) + xton(c0);
s += 2;
@@ -535,7 +536,7 @@ char* uat_unesc(const char* si, guint in_len, guint* len_p) {
break;
}
}
-
+
if (len_p) *len_p = len;
return buf;
}
@@ -550,7 +551,7 @@ char* uat_esc(const char* buf, guint len) {
char* out = ep_alloc0((4*len)+1);
const guint8* b;
char* s = out;
-
+
for (b = (void*)buf; b < end; b++) {
if (isprint(*b) ) {
*(s++) = (*b);
@@ -559,9 +560,9 @@ char* uat_esc(const char* buf, guint len) {
s+=4;
}
}
-
+
return out;
-
+
}
CHK_STR_IS_DEF(isprint)
diff --git a/epan/uat_load.l b/epan/uat_load.l
index 53175811bf..f5422e4cec 100644
--- a/epan/uat_load.l
+++ b/epan/uat_load.l
@@ -34,17 +34,17 @@
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 2001 Gerald Combs
- *
+ *
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
@@ -52,19 +52,20 @@
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
-
+
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
-
+
#include <glib.h>
#include <epan/emem.h>
#include "uat-int.h"
#include "uat_load_lex.h"
-
+#include <wiretap/file_util.h>
+
static uat_t* uat;
static guint colnum;
static gchar* ptr;
@@ -119,22 +120,22 @@ comment #[^\n]*\n
<START_OF_LINE,NEXT_FIELD>{separator} {
ptr = g_strdup("");
len = 0;
-
+
DUMP_FIELD("empty->next");
-
+
SET_FIELD();
-
+
if ( colnum >= uat->ncols ) {
ERROR(("more fields than required"));
}
-
+
BEGIN NEXT_FIELD;
}
<START_OF_LINE,NEXT_FIELD>{newline} {
ptr = "";
len = 0;
-
+
BEGIN END_OF_RECORD;
yyless(yyleng);
@@ -142,8 +143,8 @@ comment #[^\n]*\n
<START_OF_LINE,NEXT_FIELD>{quoted_string} {
ptr = uat_undquote(yytext,yyleng,&len);
-
-
+
+
if (colnum < uat->ncols - 1) {
DUMP("quoted_str->s");
BEGIN SEPARATOR;
@@ -159,7 +160,7 @@ comment #[^\n]*\n
if (!ptr) {
ERROR(("uneven hexstring for field %s",uat->fields[colnum].name));
}
-
+
if ( colnum < uat->ncols - 1 ) {
DUMP("binstring->s");
BEGIN SEPARATOR;
@@ -170,7 +171,7 @@ comment #[^\n]*\n
}
<SEPARATOR>{separator} {
-
+
DUMP_FIELD("separator->next");
SET_FIELD();
@@ -178,7 +179,7 @@ comment #[^\n]*\n
if ( colnum >= uat->ncols ) {
ERROR(("more fields than required"));
}
-
+
BEGIN NEXT_FIELD;
}
@@ -201,27 +202,27 @@ comment #[^\n]*\n
<END_OF_RECORD>{newline} {
void* rec;
const gchar* err = NULL;
-
+
linenum++;
DUMP_FIELD("newline->start");
SET_FIELD();
-
+
rec = uat_add_record(uat, record);
if (uat->update_cb)
uat->update_cb(rec,&err);
-
+
if (err) {
ERROR(("%s",err));
}
-
+
colnum = 0;;
ptr = NULL;
len = 0;
memset(record,0,uat->record_size);
-
+
BEGIN START_OF_LINE;
}
@@ -250,21 +251,21 @@ gboolean uat_load(uat_t* uat_in, char** err) {
UAT_UPDATE(uat);
return TRUE;
}
-
- if (!(yyin = fopen(fname,"r"))) {
+
+ if (!(yyin = eth_fopen(fname,"r"))) {
*err = strerror(errno);
return FALSE;
}
-
+
error = NULL;
colnum = 0;
record = g_malloc0(uat->record_size);
linenum = 1;
-
+
BEGIN START_OF_LINE;
DUMP(fname);
-
+
yylex();
yyrestart(NULL);
@@ -275,7 +276,7 @@ gboolean uat_load(uat_t* uat_in, char** err) {
*err = ep_strdup(error);
return FALSE;
} else {
- UAT_UPDATE(uat);
+ UAT_UPDATE(uat);
*err = NULL;
return TRUE;
}
diff --git a/wiretap/file_util.h b/wiretap/file_util.h
index 40830ff85e..57f5a5e30c 100644
--- a/wiretap/file_util.h
+++ b/wiretap/file_util.h
@@ -40,8 +40,10 @@ extern "C" {
#endif
-/* Win32: Since GLib2.6, we use UTF8 throughout the code, so file functions must tweak a given filename
- from UTF8 to UTF16 as we use NT Unicode (Win9x - now unsupported - used locale based encoding here). */
+/* Win32: Since GLib2.6, we use UTF8 throughout the code, so file functions
+ * must tweak a given filename from UTF8 to UTF16 as we use NT Unicode (Win9x
+ * - now unsupported - used locale based encoding here).
+ */
#if defined _WIN32 && (GLIB_MAJOR_VERSION > 2 || (GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION >= 6))
#include <stdio.h>
diff --git a/wiretap/k12.c b/wiretap/k12.c
index 19364d04f9..48aa620426 100644
--- a/wiretap/k12.c
+++ b/wiretap/k12.c
@@ -52,10 +52,10 @@ static unsigned debug_level = 0;
void k12_fprintf(char* fmt, ...) {
va_list ap;
-
+
va_start(ap,fmt);
vfprintf(dbg_out, fmt, ap);
- va_end(ap);
+ va_end(ap);
}
#define CAT(a,b) a##b
@@ -67,39 +67,39 @@ void k12_fprintf(char* fmt, ...) {
void k12_hexdump(guint level, gint64 offset, char* label, unsigned char* b, unsigned len) {
static const char* c2t[] = {
- "00","01","02","03","04","05","06","07","08","09","0a","0b","0c","0d","0e","0f",
- "10","11","12","13","14","15","16","17","18","19","1a","1b","1c","1d","1e","1f",
- "20","21","22","23","24","25","26","27","28","29","2a","2b","2c","2d","2e","2f",
- "30","31","32","33","34","35","36","37","38","39","3a","3b","3c","3d","3e","3f",
- "40","41","42","43","44","45","46","47","48","49","4a","4b","4c","4d","4e","4f",
- "50","51","52","53","54","55","56","57","58","59","5a","5b","5c","5d","5e","5f",
- "60","61","62","63","64","65","66","67","68","69","6a","6b","6c","6d","6e","6f",
- "70","71","72","73","74","75","76","77","78","79","7a","7b","7c","7d","7e","7f",
- "80","81","82","83","84","85","86","87","88","89","8a","8b","8c","8d","8e","8f",
- "90","91","92","93","94","95","96","97","98","99","9a","9b","9c","9d","9e","9f",
- "a0","a1","a2","a3","a4","a5","a6","a7","a8","a9","aa","ab","ac","ad","ae","af",
- "b0","b1","b2","b3","b4","b5","b6","b7","b8","b9","ba","bb","bc","bd","be","bf",
- "c0","c1","c2","c3","c4","c5","c6","c7","c8","c9","ca","cb","cc","cd","ce","cf",
- "d0","d1","d2","d3","d4","d5","d6","d7","d8","d9","da","db","dc","dd","de","df",
- "e0","e1","e2","e3","e4","e5","e6","e7","e8","e9","ea","eb","ec","ed","ee","ef",
+ "00","01","02","03","04","05","06","07","08","09","0a","0b","0c","0d","0e","0f",
+ "10","11","12","13","14","15","16","17","18","19","1a","1b","1c","1d","1e","1f",
+ "20","21","22","23","24","25","26","27","28","29","2a","2b","2c","2d","2e","2f",
+ "30","31","32","33","34","35","36","37","38","39","3a","3b","3c","3d","3e","3f",
+ "40","41","42","43","44","45","46","47","48","49","4a","4b","4c","4d","4e","4f",
+ "50","51","52","53","54","55","56","57","58","59","5a","5b","5c","5d","5e","5f",
+ "60","61","62","63","64","65","66","67","68","69","6a","6b","6c","6d","6e","6f",
+ "70","71","72","73","74","75","76","77","78","79","7a","7b","7c","7d","7e","7f",
+ "80","81","82","83","84","85","86","87","88","89","8a","8b","8c","8d","8e","8f",
+ "90","91","92","93","94","95","96","97","98","99","9a","9b","9c","9d","9e","9f",
+ "a0","a1","a2","a3","a4","a5","a6","a7","a8","a9","aa","ab","ac","ad","ae","af",
+ "b0","b1","b2","b3","b4","b5","b6","b7","b8","b9","ba","bb","bc","bd","be","bf",
+ "c0","c1","c2","c3","c4","c5","c6","c7","c8","c9","ca","cb","cc","cd","ce","cf",
+ "d0","d1","d2","d3","d4","d5","d6","d7","d8","d9","da","db","dc","dd","de","df",
+ "e0","e1","e2","e3","e4","e5","e6","e7","e8","e9","ea","eb","ec","ed","ee","ef",
"f0","f1","f2","f3","f4","f5","f6","f7","f8","f9","fa","fb","fc","fd","fe","ff"
};
unsigned i;
-
+
if (debug_level < level) return;
-
+
fprintf(dbg_out,"%s(%.8llx,%.4x): ",label,offset,len);
-
+
for (i=0 ; i<len ; i++) {
-
+
if (!(i%32))
fprintf(dbg_out,"\n");
else if (!(i%4))
fprintf(dbg_out," ");
-
+
fprintf(dbg_out,c2t[b[i]]);
}
-
+
fprintf(dbg_out,"\n");
}
@@ -129,7 +129,7 @@ static const guint8 k12_file_magic[] = { 0x00, 0x00, 0x02, 0x00 ,0x12, 0x05, 0x0
struct _k12_t {
guint32 file_len;
guint32 num_of_records; /* XXX: not sure about this */
-
+
GHashTable* src_by_id; /* k12_srcdsc_recs by input */
GHashTable* src_by_name; /* k12_srcdsc_recs by stack_name */
@@ -152,13 +152,13 @@ typedef struct _k12_src_desc_t {
#define K12_REC_STK_FILE 0x00070042 /* a dump of an stk file */
#define K12_REC_SRCDSC2 0x00070043 /* another port-stack mapping */
#define K12_REC_TEXT 0x00070044 /* a string containing something with a grammar (conditions/responses?) */
-#define K12_REC_START 0x00020030 /* a string containing human readable start time */
+#define K12_REC_START 0x00020030 /* a string containing human readable start time */
#define K12_REC_STOP 0x00020031 /* a string containing human readable stop time */
#define K12_MASK_PACKET 0xfffffff0 /* the last nibble in packet records somentimes change (not yet understood why) */
/* offsets of elements in the records */
-#define K12_RECORD_LEN 0x0 /* uint32, in bytes */
+#define K12_RECORD_LEN 0x0 /* uint32, in bytes */
#define K12_RECORD_TYPE 0x4 /* uint32, see above */
#define K12_RECORD_FRAME_LEN 0x8 /* uint32, in bytes */
#define K12_RECORD_SRC_ID 0xc /* uint32 */
@@ -177,8 +177,8 @@ typedef struct _k12_src_desc_t {
#define K12_PACKET_FRAME 0x20 /* start of the actual frame in the record */
-#define K12_PACKET_OFFSET_VP 0x08 /* 2 bytes, big endian */
-#define K12_PACKET_OFFSET_VC 0x0a /* 2 bytes, big endian */
+#define K12_PACKET_OFFSET_VP 0x08 /* 2 bytes, big endian */
+#define K12_PACKET_OFFSET_VC 0x0a /* 2 bytes, big endian */
#define K12_PACKET_OFFSET_CID 0x0c /* 1 byte */
/* elements of the source description records */
@@ -205,7 +205,7 @@ typedef struct _k12_src_desc_t {
* This reads the next record without the eventual 0x10 bytes.
* returns the lenght of the record + the stuffing (if any)
*
- * XXX: works at most with 0x1FFF bytes per record
+ * XXX: works at most with 0x1FFF bytes per record
*/
static gint get_record(guint8** bufferp, FILE* fh, gint64 file_offset) {
static guint8* buffer = NULL;
@@ -215,10 +215,10 @@ static gint get_record(guint8** bufferp, FILE* fh, gint64 file_offset) {
guint actual_len, left;
guint8 junk[0x14];
guint8* writep;
-
+
/* where the next unknown 0x10 bytes are stuffed to the file */
guint junky_offset = 0x2000 - (gint) ( (file_offset - 0x200) % 0x2000 );
-
+
K12_DBG(6,("get_record: ENTER: junky_offset=%lld, file_offset=%lld",junky_offset,file_offset));
/* no buffer is given, lets create it */
@@ -226,26 +226,26 @@ static gint get_record(guint8** bufferp, FILE* fh, gint64 file_offset) {
buffer = g_malloc(0x2000);
buffer_len = 0x2000;
}
-
+
*bufferp = buffer;
-
+
if ( junky_offset == 0x2000 ) {
/* the lenght of the record is 0x10 bytes ahead from we are reading */
read = file_read(junk,1,0x14,fh);
-
+
if (read == 2 && junk[0] == 0xff && junk[1] == 0xff) {
- K12_DBG(1,("get_record: EOF"));
+ K12_DBG(1,("get_record: EOF"));
return 0;
} else if ( read < 0x14 ){
K12_DBG(1,("get_record: SHORT READ"));
return -1;
}
-
+
memcpy(buffer,&(junk[0x10]),4);
} else {
/* the lenght of the record is right where we are reading */
read = file_read(buffer,1, 0x4, fh);
-
+
if (read == 2 && buffer[0] == 0xff && buffer[1] == 0xff) {
K12_DBG(1,("get_record: EOF"));
return 0;
@@ -254,25 +254,25 @@ static gint get_record(guint8** bufferp, FILE* fh, gint64 file_offset) {
return -1;
}
}
-
+
actual_len = left = pntohl(buffer);
junky_offset -= 0x4;
-
+
K12_DBG(5,("get_record: GET length=%d",left));
g_assert(left >= 4);
-
+
while (left > buffer_len) *bufferp = buffer = g_realloc(buffer,buffer_len*=2);
-
+
writep = buffer + 4;
left -= 4;
-
+
do {
K12_DBG(6,("get_record: looping left=%d junky_offset=%lld",left,junky_offset));
if (junky_offset > left) {
read += last_read = file_read(writep,1, left, fh);
-
+
if ( last_read != left ) {
K12_DBG(1,("get_record: SHORT READ"));
return -1;
@@ -282,27 +282,27 @@ static gint get_record(guint8** bufferp, FILE* fh, gint64 file_offset) {
}
} else {
read += last_read = file_read(writep,1, junky_offset, fh);
-
+
if ( last_read != junky_offset ) {
K12_DBG(1,("get_record: SHORT READ, read=%d expected=%d",last_read, junky_offset));
return -1;
}
-
+
writep += last_read;
read += last_read = file_read(junk,1, 0x10, fh);
-
+
if ( last_read != 0x10 ) {
K12_DBG(1,("get_record: SHORT READ"));
return -1;
}
-
+
left -= junky_offset;
junky_offset = 0x2000;
}
-
+
} while(left);
-
+
K12_HEXDMP(5,file_offset, "GOT record", buffer, actual_len);
return read;
}
@@ -316,17 +316,17 @@ static gboolean k12_read(wtap *wth, int *err, gchar **err_info _U_, gint64 *data
guint32 src_id;
guint64 ts;
guint32 extra_len;
-
+
offset = wth->data_offset;
-
- /* ignore the record if it isn't a packet */
+
+ /* ignore the record if it isn't a packet */
do {
K12_DBG(5,("k12_read: offset=%i",offset));
-
+
*data_offset = offset;
-
+
len = get_record(&buffer, wth->fh, offset);
-
+
if (len < 0) {
*err = WTAP_ERR_SHORT_READ;
return FALSE;
@@ -334,11 +334,11 @@ static gboolean k12_read(wtap *wth, int *err, gchar **err_info _U_, gint64 *data
*err = 0;
return FALSE;
}
-
+
type = pntohl(buffer + K12_RECORD_TYPE);
src_id = pntohl(buffer + K12_RECORD_SRC_ID);
-
-
+
+
if ( ! (src_desc = g_hash_table_lookup(wth->capture.k12->src_by_id,GUINT_TO_POINTER(src_id))) ) {
/*
* Some records from K15 files have a port ID of an undeclared
@@ -349,29 +349,29 @@ static gboolean k12_read(wtap *wth, int *err, gchar **err_info _U_, gint64 *data
*/
src_desc = g_hash_table_lookup(wth->capture.k12->src_by_id,GUINT_TO_POINTER(src_id&K12_RECORD_SRC_ID_MASK));
}
-
+
K12_DBG(5,("k12_read: record type=%x src_id=%x",type,src_id));
-
+
offset += len;
-
+
} while ( ((type & K12_MASK_PACKET) != K12_REC_PACKET) || !src_id || !src_desc );
-
+
wth->data_offset = offset;
-
+
ts = pntohll(buffer + K12_PACKET_TIMESTAMP);
-
+
wth->phdr.ts.secs = (guint32) ((ts / 2000000) + 631152000);
wth->phdr.ts.nsecs = (guint32) ( (ts % 2000000) * 500 );
-
+
K12_DBG(3,("k12_read: PACKET RECORD type=%x src_id=%x secs=%u nsecs=%u",type,src_id, wth->phdr.ts.secs,wth->phdr.ts.nsecs));
-
+
wth->phdr.len = wth->phdr.caplen = pntohl(buffer + K12_RECORD_FRAME_LEN) & 0x00001FFF;
extra_len = len - K12_PACKET_FRAME - wth->phdr.caplen;
-
+
/* the frame */
buffer_assure_space(wth->frame_buffer, wth->phdr.caplen);
memcpy(buffer_start_ptr(wth->frame_buffer), buffer + K12_PACKET_FRAME, wth->phdr.caplen);
-
+
/* extra information need by some protocols */
buffer_assure_space(&(wth->capture.k12->extra_info), extra_len);
memcpy(buffer_start_ptr(&(wth->capture.k12->extra_info)),
@@ -380,14 +380,14 @@ static gboolean k12_read(wtap *wth, int *err, gchar **err_info _U_, gint64 *data
wth->pseudo_header.k12.extra_length = extra_len;
wth->pseudo_header.k12.input = src_id;
-
+
K12_DBG(5,("k12_read: wth->pseudo_header.k12.input=%x wth->phdr.len=%i input_name='%s' stack_file='%s' type=%x",
wth->pseudo_header.k12.input,wth->phdr.len,src_desc->input_name,src_desc->stack_file,src_desc->input_type));\
-
+
wth->pseudo_header.k12.input_name = src_desc->input_name;
wth->pseudo_header.k12.stack_file = src_desc->stack_file;
wth->pseudo_header.k12.input_type = src_desc->input_type;
-
+
switch(src_desc->input_type) {
case K12_PORT_ATMPVC:
if ((long)(K12_PACKET_FRAME + wth->phdr.len + K12_PACKET_OFFSET_CID) < len) {
@@ -400,11 +400,11 @@ static gboolean k12_read(wtap *wth, int *err, gchar **err_info _U_, gint64 *data
default:
memcpy(&(wth->pseudo_header.k12.input_info),&(src_desc->input_info),sizeof(src_desc->input_info));
break;
-
+
}
wth->pseudo_header.k12.stuff = wth->capture.k12;
-
+
return TRUE;
}
@@ -415,19 +415,19 @@ static gboolean k12_seek_read(wtap *wth, gint64 seek_off, union wtap_pseudo_head
long len;
guint32 extra_len;
guint32 input;
-
+
K12_DBG(5,("k12_seek_read: ENTER"));
-
+
if ( file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) {
K12_DBG(5,("k12_seek_read: SEEK ERROR"));
return FALSE;
}
-
+
if ((len = get_record(&buffer, wth->random_fh, seek_off)) < 1) {
K12_DBG(5,("k12_seek_read: READ ERROR"));
return FALSE;
}
-
+
memcpy(pd, buffer + K12_PACKET_FRAME, length);
extra_len = len - K12_PACKET_FRAME - length;
@@ -440,10 +440,10 @@ static gboolean k12_seek_read(wtap *wth, gint64 seek_off, union wtap_pseudo_head
pseudo_header->k12.extra_info = (void*)buffer_start_ptr(&(wth->capture.k12->extra_info));
pseudo_header->k12.extra_length = extra_len;
}
-
+
input = pntohl(buffer + K12_RECORD_SRC_ID);
K12_DBG(5,("k12_seek_read: input=%.8x",input));
-
+
if ( ! (src_desc = g_hash_table_lookup(wth->capture.k12->src_by_id,GUINT_TO_POINTER(input))) ) {
/*
* Some records from K15 files have a port ID of an undeclared
@@ -454,14 +454,14 @@ static gboolean k12_seek_read(wtap *wth, gint64 seek_off, union wtap_pseudo_head
*/
src_desc = g_hash_table_lookup(wth->capture.k12->src_by_id,GUINT_TO_POINTER(input&K12_RECORD_SRC_ID_MASK));
}
-
+
if (src_desc) {
K12_DBG(5,("k12_seek_read: input_name='%s' stack_file='%s' type=%x",src_desc->input_name,src_desc->stack_file,src_desc->input_type));
if (pseudo_header) {
pseudo_header->k12.input_name = src_desc->input_name;
pseudo_header->k12.stack_file = src_desc->stack_file;
pseudo_header->k12.input_type = src_desc->input_type;
-
+
switch(src_desc->input_type) {
case K12_PORT_ATMPVC:
if ((long)(K12_PACKET_FRAME + length + K12_PACKET_OFFSET_CID) < len) {
@@ -476,11 +476,11 @@ static gboolean k12_seek_read(wtap *wth, gint64 seek_off, union wtap_pseudo_head
break;
}
}
-
+
wth->pseudo_header.k12.input_name = src_desc->input_name;
wth->pseudo_header.k12.stack_file = src_desc->stack_file;
wth->pseudo_header.k12.input_type = src_desc->input_type;
-
+
switch(src_desc->input_type) {
case K12_PORT_ATMPVC:
if ((long)(K12_PACKET_FRAME + length + K12_PACKET_OFFSET_CID) < len) {
@@ -494,7 +494,7 @@ static gboolean k12_seek_read(wtap *wth, gint64 seek_off, union wtap_pseudo_head
memcpy(&(wth->pseudo_header.k12.input_info),&(src_desc->input_info),sizeof(src_desc->input_info));
break;
}
-
+
} else {
K12_DBG(5,("k12_seek_read: NO SRC_RECORD FOUND"));
@@ -507,14 +507,14 @@ static gboolean k12_seek_read(wtap *wth, gint64 seek_off, union wtap_pseudo_head
memset(&(wth->pseudo_header.k12),0,sizeof(wth->pseudo_header.k12));
wth->pseudo_header.k12.input_name = "unknown port";
wth->pseudo_header.k12.stack_file = "unknown stack file";
-
+
}
-
+
if (pseudo_header) {
pseudo_header->k12.input = input;
pseudo_header->k12.stuff = wth->capture.k12;
}
-
+
wth->pseudo_header.k12.input = input;
wth->pseudo_header.k12.stuff = wth->capture.k12;
@@ -526,34 +526,34 @@ static gboolean k12_seek_read(wtap *wth, gint64 seek_off, union wtap_pseudo_head
static k12_t* new_k12_file_data(void) {
k12_t* fd = g_malloc(sizeof(k12_t));
-
+
fd->file_len = 0;
fd->num_of_records = 0;
fd->src_by_name = g_hash_table_new(g_str_hash,g_str_equal);
fd->src_by_id = g_hash_table_new(g_direct_hash,g_direct_equal);
buffer_init(&(fd->extra_info), 100);
-
+
return fd;
}
static gboolean destroy_srcdsc(gpointer k _U_, gpointer v, gpointer p _U_) {
k12_src_desc_t* rec = v;
-
+
if(rec->input_name)
g_free(rec->input_name);
-
+
if(rec->stack_file)
g_free(rec->stack_file);
-
+
g_free(rec);
-
+
return TRUE;
}
static void destroy_k12_file_data(k12_t* fd) {
g_hash_table_destroy(fd->src_by_id);
- g_hash_table_foreach_remove(fd->src_by_name,destroy_srcdsc,NULL);
+ g_hash_table_foreach_remove(fd->src_by_name,destroy_srcdsc,NULL);
g_hash_table_destroy(fd->src_by_name);
buffer_free(&(fd->extra_info));
g_free(fd);
@@ -581,16 +581,16 @@ int k12_open(wtap *wth, int *err, gchar **err_info _U_) {
guint32 stack_len;
guint i;
k12_t* file_data;
-
+
#ifdef DEBUG_K12
gchar* env_level = getenv("K12_DEBUG_LEVEL");
env_file = getenv("K12_DEBUG_FILENAME");
- if ( env_file ) dbg_out = fopen(env_file,"w");
+ if ( env_file ) dbg_out = eth_fopen(env_file,"w");
else dbg_out = stderr;
if ( env_level ) debug_level = strtoul(env_level,NULL,10);
K12_DBG(1,("k12_open: ENTER debug_level=%u",debug_level));
#endif
-
+
if ( file_read(header_buffer,1,0x200,wth->fh) != 0x200 ) {
K12_DBG(1,("k12_open: FILE HEADER TOO SHORT"));
return 0;
@@ -600,31 +600,31 @@ int k12_open(wtap *wth, int *err, gchar **err_info _U_) {
return 0;
}
}
-
+
offset = 0x200;
-
+
file_data = new_k12_file_data();
-
+
file_data->file_len = pntohl( header_buffer + 0x8);
file_data->num_of_records = pntohl( header_buffer + 0xC );
-
+
K12_DBG(5,("k12_open: FILE_HEADER OK: offset=%x file_len=%i records=%i",
offset,
file_data->file_len,
file_data->num_of_records ));
-
+
do {
-
+
len = get_record(&read_buffer, wth->fh, offset);
-
+
if ( len <= 0 ) {
K12_DBG(1,("k12_open: BAD HEADER RECORD",len));
return -1;
}
-
-
+
+
type = pntohl( read_buffer + K12_RECORD_TYPE );
-
+
if ( (type & K12_MASK_PACKET) == K12_REC_PACKET) {
/*
* we are at the first packet record, rewind and leave.
@@ -637,16 +637,16 @@ int k12_open(wtap *wth, int *err, gchar **err_info _U_) {
break;
} else if (type == K12_REC_SRCDSC || type == K12_REC_SRCDSC2 ) {
rec = g_malloc0(sizeof(k12_src_desc_t));
-
+
rec_len = pntohl( read_buffer + K12_RECORD_LEN );
extra_len = pntohs( read_buffer + K12_SRCDESC_EXTRALEN );
name_len = pntohs( read_buffer + K12_SRCDESC_NAMELEN );
stack_len = pntohs( read_buffer + K12_SRCDESC_STACKLEN );
-
+
rec->input = pntohl( read_buffer + K12_RECORD_SRC_ID );
-
+
K12_DBG(5,("k12_open: INTERFACE RECORD offset=%x interface=%x",offset,rec->input));
-
+
if (name_len == 0 || stack_len == 0
|| 0x20 + extra_len + name_len + stack_len > rec_len ) {
g_free(rec);
@@ -659,11 +659,11 @@ int k12_open(wtap *wth, int *err, gchar **err_info _U_) {
switch(( rec->input_type = pntohl( read_buffer + K12_SRCDESC_EXTRATYPE ) )) {
case K12_PORT_DS0S:
rec->input_info.ds0mask = 0x00000000;
-
+
for (i = 0; i < 32; i++) {
- rec->input_info.ds0mask |= ( *(read_buffer + K12_SRCDESC_DS0_MASK + i) == 0xff ) ? 0x1<<(31-i) : 0x0;
+ rec->input_info.ds0mask |= ( *(read_buffer + K12_SRCDESC_DS0_MASK + i) == 0xff ) ? 0x1<<(31-i) : 0x0;
}
-
+
break;
case K12_PORT_ATMPVC:
rec->input_info.atm.vp = pntohs( read_buffer + K12_SRCDESC_ATM_VPI );
@@ -676,19 +676,19 @@ int k12_open(wtap *wth, int *err, gchar **err_info _U_) {
don't have this information */
if (read_buffer[K12_SRCDESC_PORT_TYPE] >= 0x14
&& read_buffer[K12_SRCDESC_PORT_TYPE] <= 0x17)
- /* For ATM2_E1DS1, ATM2_E3DS3,
+ /* For ATM2_E1DS1, ATM2_E3DS3,
ATM2_STM1EL and ATM2_STM1OP */
rec->input_type = K12_PORT_ATMPVC;
}
rec->input_name = g_memdup(read_buffer + K12_SRCDESC_EXTRATYPE + extra_len, name_len);
rec->stack_file = g_memdup(read_buffer + K12_SRCDESC_EXTRATYPE + extra_len + name_len, stack_len);
-
+
g_strdown(rec->stack_file);
-
+
g_hash_table_insert(file_data->src_by_id,GUINT_TO_POINTER(rec->input),rec);
g_hash_table_insert(file_data->src_by_name,rec->stack_file,rec);
-
+
offset += len;
continue;
} else {
@@ -696,7 +696,7 @@ int k12_open(wtap *wth, int *err, gchar **err_info _U_) {
continue;
}
} while(1);
-
+
wth->data_offset = offset;
wth->file_type = WTAP_FILE_K12;
wth->file_encap = WTAP_ENCAP_K12;
@@ -705,19 +705,19 @@ int k12_open(wtap *wth, int *err, gchar **err_info _U_) {
wth->subtype_seek_read = k12_seek_read;
wth->subtype_close = k12_close;
wth->capture.k12 = file_data;
- wth->tsprecision = WTAP_FILE_TSPREC_NSEC;
+ wth->tsprecision = WTAP_FILE_TSPREC_NSEC;
return 1;
}
int k12_dump_can_write_encap(int encap) {
-
+
if (encap == WTAP_ENCAP_PER_PACKET)
return WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED;
-
+
if (encap != WTAP_ENCAP_K12)
return WTAP_ERR_UNSUPPORTED_ENCAP;
-
+
return 0;
}
@@ -739,7 +739,7 @@ static gboolean do_fwrite(const void *data, size_t size, size_t count, FILE *str
static gboolean k12_dump_record(wtap_dumper *wdh, long len, guint8* buffer, int *err_p) {
long junky_offset = (0x2000 - ( (wdh->dump.k12->file_offset - 0x200) % 0x2000 )) % 0x2000;
-
+
if (len > junky_offset) {
if (junky_offset) {
if (! do_fwrite(buffer, 1, junky_offset, wdh->fh, err_p))
@@ -747,17 +747,17 @@ static gboolean k12_dump_record(wtap_dumper *wdh, long len, guint8* buffer, int
}
if (! do_fwrite(dumpy_junk, 1, 0x10, wdh->fh, err_p))
return FALSE;
-
+
if (! do_fwrite(buffer+junky_offset, 1, len - junky_offset, wdh->fh, err_p))
return FALSE;
-
+
wdh->dump.k12->file_offset += len + 0x10;
} else {
if (! do_fwrite(buffer, 1, len, wdh->fh, err_p))
return FALSE;
wdh->dump.k12->file_offset += len;
}
-
+
wdh->dump.k12->num_of_records++;
return TRUE;
}
@@ -772,48 +772,48 @@ static void k12_dump_src_setting(gpointer k _U_, gpointer v, gpointer p) {
union {
guint8 buffer[0x2000];
-
+
struct {
guint32 len;
guint32 type;
guint32 unk32_1;
guint32 input;
-
+
guint16 unk32_2;
guint16 color;
guint32 unk32_3;
guint32 unk32_4;
guint16 unk16_1;
guint16 extra_len;
-
+
guint16 name_len;
guint16 stack_len;
-
+
struct {
guint32 type;
-
+
union {
struct {
guint32 unk32;
guint8 mask[32];
} ds0mask;
-
+
struct {
guint8 unk_data[0x10];
guint16 vp;
guint16 vc;
} atm;
-
+
guint32 unk;
} desc;
} extra;
} record;
} obj;
-
+
obj.record.type = g_htonl(K12_REC_SRCDSC);
obj.record.unk32_1 = g_htonl(0x00000001);
obj.record.input = g_htonl(src_desc->input);
-
+
obj.record.unk32_2 = g_htons(0x0000);
obj.record.color = g_htons(0x060f);
obj.record.unk32_3 = g_htonl(0x00000003);
@@ -824,13 +824,13 @@ static void k12_dump_src_setting(gpointer k _U_, gpointer v, gpointer p) {
default:
obj.record.unk32_4 = g_htonl(0x01000100);
}
-
+
obj.record.unk16_1 = g_htons(0x0000);
obj.record.name_len = strlen(src_desc->input_name) + 1;
obj.record.stack_len = strlen(src_desc->stack_file) + 1;
-
+
obj.record.extra.type = g_htonl(src_desc->input_type);
-
+
switch (src_desc->input_type) {
case K12_PORT_ATMPVC:
obj.record.extra_len = g_htons(0x18);
@@ -851,22 +851,22 @@ static void k12_dump_src_setting(gpointer k _U_, gpointer v, gpointer p) {
offset = 0x2c;
break;
}
-
+
memcpy(obj.buffer + offset,
src_desc->input_name,
obj.record.name_len);
-
+
memcpy(obj.buffer + offset + obj.record.name_len,
src_desc->stack_file,
obj.record.stack_len);
-
+
len = offset + obj.record.name_len + obj.record.stack_len;
len += (len % 4) ? 4 - (len % 4) : 0;
-
+
obj.record.len = g_htonl(len);
obj.record.name_len = g_htons(obj.record.name_len);
obj.record.stack_len = g_htons(obj.record.stack_len);
-
+
k12_dump_record(wdh,len,obj.buffer, &errxxx); /* fwrite errs ignored: see k12_dump below */
}
@@ -881,15 +881,15 @@ static gboolean k12_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
guint32 type;
guint32 frame_len;
guint32 input;
-
+
guint32 datum_1;
guint32 datum_2;
guint64 ts;
-
+
guint8 frame[0x1fc0];
} record;
} obj;
-
+
if (wdh->dump.k12->num_of_records == 0) {
k12_t* file_data = pseudo_header->k12.stuff;
/* XXX: We'll assume that any fwrite errors in k12_dump_src_setting will */
@@ -901,19 +901,19 @@ static gboolean k12_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
}
obj.record.len = 0x20 + phdr->len;
obj.record.len += (obj.record.len % 4) ? 4 - obj.record.len % 4 : 0;
-
+
len = obj.record.len;
-
+
obj.record.len = g_htonl(obj.record.len);
-
+
obj.record.type = g_htonl(K12_REC_PACKET);
obj.record.frame_len = g_htonl(phdr->len);
obj.record.input = g_htonl(pseudo_header->k12.input);
-
+
obj.record.ts = GUINT64_TO_BE((((guint64)phdr->ts.secs - 631152000) * 2000000) + (phdr->ts.nsecs / 1000 * 2));
-
+
memcpy(obj.record.frame,pd,phdr->len);
-
+
return k12_dump_record(wdh,len,obj.buffer, err);
}
@@ -924,53 +924,53 @@ static gboolean k12_dump_close(wtap_dumper *wdh, int *err) {
guint8 b[sizeof(guint32)];
guint32 u;
} d;
-
+
if (! do_fwrite(k12_eof, 1, 2, wdh->fh, err))
return FALSE;
-
+
if (fseek(wdh->fh, 8, SEEK_SET) == -1) {
*err = errno;
return FALSE;
}
-
+
d.u = g_htonl(wdh->dump.k12->file_len);
-
+
if (! do_fwrite(d.b, 1, 4, wdh->fh, err))
return FALSE;
-
+
d.u = g_htonl(wdh->dump.k12->num_of_records);
-
+
if (! do_fwrite(d.b, 1, 4, wdh->fh, err))
return FALSE;
-
+
return TRUE;
}
gboolean k12_dump_open(wtap_dumper *wdh, gboolean cant_seek, int *err) {
-
+
if (cant_seek) {
*err = WTAP_ERR_CANT_WRITE_TO_PIPE;
return FALSE;
}
-
+
if ( ! do_fwrite(k12_file_magic, 1, 8, wdh->fh, err)) {
return FALSE;
}
-
+
if (fseek(wdh->fh, 0x200, SEEK_SET) == -1) {
*err = errno;
return FALSE;
}
-
+
wdh->subtype_write = k12_dump;
wdh->subtype_close = k12_dump_close;
-
+
wdh->dump.k12 = g_malloc(sizeof(k12_dump_t));
wdh->dump.k12->file_len = 0x200;
wdh->dump.k12->num_of_records = 0;
wdh->dump.k12->file_offset = 0x200;
-
+
return TRUE;
}