diff options
author | Gilbert Ramirez <gram@alumni.rice.edu> | 2000-09-28 03:16:29 +0000 |
---|---|---|
committer | Gilbert Ramirez <gram@alumni.rice.edu> | 2000-09-28 03:16:29 +0000 |
commit | 9d9850f209ff7b5f350c7e83719eebaa76a72edd (patch) | |
tree | ccf03ab311c3d67e880750071dcba5cb31d73e42 /epan | |
parent | cba2930d6bb7e8cf2b0c03d14203624b56460835 (diff) |
More EPAN-related code movements. Get rid of usage of #include "globals.h"
and #include "util.h" from epan code. Move get_home_dir() into epan/filesystem.c
as it's used by plugins.c.
svn path=/trunk/; revision=2461
Diffstat (limited to 'epan')
-rw-r--r-- | epan/Makefile.am | 4 | ||||
-rw-r--r-- | epan/dfilter.c | 3 | ||||
-rw-r--r-- | epan/epan.h | 6 | ||||
-rw-r--r-- | epan/filesystem.c | 118 | ||||
-rw-r--r-- | epan/filesystem.h | 33 | ||||
-rw-r--r-- | epan/pint.h | 13 | ||||
-rw-r--r-- | epan/plugins.c | 7 | ||||
-rw-r--r-- | epan/strutil.h | 6 |
8 files changed, 180 insertions, 10 deletions
diff --git a/epan/Makefile.am b/epan/Makefile.am index da1e3c9e2a..8d267d8059 100644 --- a/epan/Makefile.am +++ b/epan/Makefile.am @@ -2,7 +2,7 @@ # Automake file for the EPAN library # (Ethereal Protocol ANalyzer Library) # -# $Id: Makefile.am,v 1.3 2000/09/27 05:18:05 gram Exp $ +# $Id: Makefile.am,v 1.4 2000/09/28 03:16:15 gram Exp $ # # Ethereal - Network traffic analyzer # By Gerald Combs <gerald@zing.org> @@ -46,6 +46,8 @@ libepan_a_SOURCES = \ except.c \ except.h \ exception.h \ + filesystem.c \ + filesystem.h \ packet.c \ packet.h \ pint.h \ diff --git a/epan/dfilter.c b/epan/dfilter.c index 73fe5253e0..9911fd600c 100644 --- a/epan/dfilter.c +++ b/epan/dfilter.c @@ -1,7 +1,7 @@ /* dfilter.c * Routines for display filters * - * $Id: dfilter.c,v 1.1 2000/09/27 04:54:48 gram Exp $ + * $Id: dfilter.c,v 1.2 2000/09/28 03:16:15 gram Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -41,7 +41,6 @@ #include "proto.h" #include "dfilter.h" -#include "util.h" #include "dfilter-int.h" #include "dfilter-grammar.h" diff --git a/epan/epan.h b/epan/epan.h index 87463449ea..649627c44e 100644 --- a/epan/epan.h +++ b/epan/epan.h @@ -6,6 +6,7 @@ #ifndef EPAN_H +#include <glib.h> void epan_init(void); void epan_cleanup(void); @@ -46,4 +47,9 @@ epan_dissect_new(epan_t*, guint8* data, guint len, guint32 wtap_encap, void epan_dissect_free(epan_t*, epan_dissect_t*); +/* Should this be ".libepan"? For backwards-compatibility, I'll keep + * it ".ethereal" for now. + */ +#define PF_DIR ".ethereal" + #endif /* EPAN_H */ diff --git a/epan/filesystem.c b/epan/filesystem.c new file mode 100644 index 0000000000..bd89677f90 --- /dev/null +++ b/epan/filesystem.c @@ -0,0 +1,118 @@ +/* filesystem.c + * Filesystem utility routines + * + * $Id: filesystem.c,v 1.1 2000/09/28 03:16:16 gram Exp $ + * + * Ethereal - Network traffic analyzer + * By Gerald Combs <gerald@zing.org> + * Copyright 1998 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. + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include <stdlib.h> +#include <glib.h> + +#ifdef HAVE_UNISTD_H +#include <unistd.h> +#endif + +#ifndef WIN32 +#include <pwd.h> +#endif + +#include "filesystem.h" + +const char* +get_home_dir(void) +{ + static const char *home = NULL; +#ifdef WIN32 + char *homedrive, *homepath; + char *homestring; + char *lastsep; +#else + struct passwd *pwd; +#endif + + /* Return the cached value, if available */ + if (home) + return home; +#ifdef WIN32 + /* + * XXX - should we use USERPROFILE anywhere in this process? + * Is there a chance that it might be set but one or more of + * HOMEDRIVE or HOMEPATH isn't set? + */ + homedrive = getenv("HOMEDRIVE"); + if (homedrive != NULL) { + homepath = getenv("HOMEPATH"); + if (homepath != NULL) { + /* + * This is cached, so we don't need to worry about + * allocating multiple ones of them. + */ + homestring = + g_malloc(strlen(homedrive) + strlen(homepath) + 1); + strcpy(homestring, homedrive); + strcat(homestring, homepath); + + /* + * Trim off any trailing slash or backslash. + */ + lastsep = find_last_pathname_separator(homestring); + if (lastsep != NULL && *(lastsep + 1) == '\0') { + /* + * Last separator is the last character + * in the string. Nuke it. + */ + *lastsep = '\0'; + } + home = homestring; + } else + home = homedrive; + } else { + /* + * Try using "windir? + */ + home = "C:"; + } +#else + home = getenv("HOME"); + if (home == NULL) { + /* + * Get their home directory from the password file. + * If we can't even find a password file entry for them, + * use "/tmp". + */ + pwd = getpwuid(getuid()); + if (pwd != NULL) { + /* + * This is cached, so we don't need to worry + * about allocating multiple ones of them. + */ + home = g_strdup(pwd->pw_dir); + } else + home = "/tmp"; + } +#endif + + return home; +} diff --git a/epan/filesystem.h b/epan/filesystem.h new file mode 100644 index 0000000000..e8345daf3c --- /dev/null +++ b/epan/filesystem.h @@ -0,0 +1,33 @@ +/* filesystem.h + * Filesystem utility definitions + * + * $Id: filesystem.h,v 1.1 2000/09/28 03:16:16 gram Exp $ + * + * Ethereal - Network traffic analyzer + * By Gerald Combs <gerald@zing.org> + * Copyright 1998 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. + */ + +#ifndef FILESYSTEM_H +#define FILESYSTEM_H + +/* Returns the user's home directory, via the HOME environment + * variable, or a default directory if HOME is not set */ +const char* get_home_dir(void); + +#endif FILESYSTEM_H diff --git a/epan/pint.h b/epan/pint.h index 38f9201ffc..cb0be3a30c 100644 --- a/epan/pint.h +++ b/epan/pint.h @@ -2,7 +2,7 @@ * Definitions for extracting and translating integers safely and portably * via pointers. * - * $Id: pint.h,v 1.1 2000/09/27 04:54:50 gram Exp $ + * $Id: pint.h,v 1.2 2000/09/28 03:16:16 gram Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -112,4 +112,15 @@ #define htolel(l) (l) #endif +/* Byte ordering */ +#ifndef BYTE_ORDER +# define LITTLE_ENDIAN 4321 +# define BIG_ENDIAN 1234 +# ifdef WORDS_BIGENDIAN +# define BYTE_ORDER BIG_ENDIAN +# else +# define BYTE_ORDER LITTLE_ENDIAN +# endif +#endif + #endif /* PINT_H */ diff --git a/epan/plugins.c b/epan/plugins.c index 8ef8800844..fa50b9faf5 100644 --- a/epan/plugins.c +++ b/epan/plugins.c @@ -1,7 +1,7 @@ /* plugins.c * plugin routines * - * $Id: plugins.c,v 1.1 2000/09/27 04:54:50 gram Exp $ + * $Id: plugins.c,v 1.2 2000/09/28 03:16:16 gram Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -27,6 +27,7 @@ # include "config.h" #endif +#include <epan.h> #include "plugins.h" #ifdef HAVE_PLUGINS @@ -43,6 +44,7 @@ #include <string.h> #include <stdlib.h> +#include <errno.h> #ifdef HAVE_SYS_STAT_H #include <sys/stat.h> @@ -60,8 +62,7 @@ #include <unistd.h> #endif -#include "globals.h" -#include "util.h" +#include "filesystem.h" #ifdef PLUGINS_NEED_ADDRESS_TABLE #include "plugins/plugin_table.h" diff --git a/epan/strutil.h b/epan/strutil.h index fdd95ca891..6464500d73 100644 --- a/epan/strutil.h +++ b/epan/strutil.h @@ -1,7 +1,7 @@ -/* util.h - * Utility definitions +/* strutil.h + * String utility definitions * - * $Id: strutil.h,v 1.1 2000/09/27 04:54:53 gram Exp $ + * $Id: strutil.h,v 1.2 2000/09/28 03:16:17 gram Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> |