/* util.c
* Utility routines
*
- * $Id: util.c,v 1.45 2000/09/17 03:20:05 guy Exp $
+ * $Id: util.c,v 1.51 2001/04/02 09:53:43 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
#include <sys/ioctl.h>
#endif
+#include <pcap.h>
+
#ifndef WIN32
#include <net/if.h>
#endif
return 0;
}
-/*
- * Given a pathname, return a pointer to the last pathname separator
- * character in the pathname, or NULL if the pathname contains no
- * separators.
- */
-static char *
-find_last_pathname_separator(char *path)
-{
- char *separator;
-
-#ifdef WIN32
- char c;
-
- /*
- * We have to scan for '\' or '/'.
- * Get to the end of the string.
- */
- separator = path + strlen(path); /* points to ending '\0' */
- while (separator > path) {
- c = *--separator;
- if (c == '\\' || c == '/')
- return separator; /* found it */
- }
-
- /*
- * OK, we didn't find any, so no directories - but there might
- * be a drive letter....
- */
- return strchr(path, ':');
-#else
- separator = strrchr(path, '/');
-#endif
- return separator;
-}
-
-/*
- * Given a pathname, return the last component.
- */
-char *
-get_basename(char *path)
-{
- char *filename;
-
- filename = find_last_pathname_separator(path);
- if (filename == NULL) {
- /*
- * There're no directories, drive letters, etc. in the
- * name; the pathname *is* the file name.
- */
- filename = path;
- } else {
- /*
- * Skip past the pathname or drive letter separator.
- */
- filename++;
- }
- return filename;
-}
-
-/*
- * Given a pathname, return a string containing everything but the
- * last component. NOTE: this overwrites the pathname handed into
- * it....
- */
-char *
-get_dirname(char *path)
-{
- char *separator;
-
- separator = find_last_pathname_separator(path);
- if (separator == NULL) {
- /*
- * There're no directories, drive letters, etc. in the
- * name; there is no directory path to return.
- */
- return NULL;
- }
-
- /*
- * Get rid of the last pathname separator and the final file
- * name following it.
- */
- *separator = '\0';
-
- /*
- * "path" now contains the pathname of the directory containing
- * the file/directory to which it referred.
- */
- return path;
-}
-
/*
* Collect command-line arguments as a string consisting of the arguments,
* separated by spaces.
#endif
}
+#ifdef linux
+ /*
+ * OK, maybe we have support for the "any" device, to do a cooked
+ * capture on all interfaces at once.
+ * Try opening it and, if that succeeds, add it to the end of
+ * the list of interfaces.
+ */
+ pch = pcap_open_live("any", MIN_PACKET_SIZE, 0, 0, err_str);
+ if (pch != NULL) {
+ /*
+ * It worked; we can use the "any" device.
+ */
+ il = g_list_insert(il, g_strdup("any"), -1);
+ pcap_close(pch);
+ }
+#endif
+
g_free(ifc.ifc_buf);
close(sock);
characters */
do
{
- win95names=names;
+ win95names=(char *)names;
j = 0;
while (win95names[i] != 0)
newname[j++] = win95names[i++];
#endif /* HAVE_LIBPCAP */
-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;
-}
/* Compute the difference between two seconds/microseconds time stamps. */
void