Ethereal-dev: [Ethereal-dev] Wiretap as DLL, again

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: Gilbert Ramirez <gram@xxxxxxxxxx>
Date: Thu, 26 Oct 2000 00:44:15 -0400
Tonight I once again tried to get Wiretap on Win32 to work as a DLL,
and found the point at which it fails. It was unexpected.
Tethereal (and ethereal, but I'm testing Tethereal) cannot fstat()
the file descriptor passed back from wiretap, even though the
open (wtap_open_offline()) succeeds. But when wiretap
is compiled as an archive library, the fstat() succeeds.

Attached is a patch with some debug printf()'s, just to show where
the last point of execution is.

 wth = wtap_open_offline(fname, &err, FALSE);
  if (wth == NULL)
    goto fail;

  /* Find the size of the file. */
  fh = wtap_file(wth);
  fd = wtap_fd(wth);
printf("t0, fd=%d\n", fd);
  if (fstat(fd, &cf_stat) < 0) {
    err = errno;
    wtap_close(wth);
printf("t1\n");	<----------------- this point is reached.
    goto fail;
  }

Ideas?

--gilbert
? wiretap.dll
? epan/config.h
? epan/ethereal.lib
? wiretap/wtap.def
? wiretap/wiretap.exp
? wiretap/wiretap.dll
Index: Makefile.nmake
===================================================================
RCS file: /usr/local/cvsroot/ethereal/Makefile.nmake,v
retrieving revision 1.59
diff -u -r1.59 Makefile.nmake
--- Makefile.nmake	2000/10/19 06:45:10	1.59
+++ Makefile.nmake	2000/10/26 04:39:28
@@ -192,7 +192,7 @@
 	strerror.obj	\
 	mkstemp.obj
 
-ethereal_LIBS= wiretap\libwtap.lib gtk\libui.lib epan\ethereal.lib \
+ethereal_LIBS= wiretap\wiretap.lib gtk\libui.lib epan\ethereal.lib \
 	wsock32.lib user32.lib \
 	$(GTK_DIR)\gtk\gtk-$(GTK_VERSION).lib \
 	$(GTK_DIR)\gdk\gdk-$(GTK_VERSION).lib \
@@ -200,13 +200,13 @@
 	$(GLIB_DIR)\gmodule\gmodule-$(GLIB_VERSION).lib \
 	$(PCAP_DIR)\lib\libpcap.lib
 
-tethereal_LIBS= wiretap\libwtap.lib epan\ethereal.lib \
+tethereal_LIBS= wiretap\wiretap.lib epan\ethereal.lib \
 	wsock32.lib user32.lib \
 	$(GLIB_DIR)\glib-$(GLIB_VERSION).lib \
 	$(GLIB_DIR)\gmodule\gmodule-$(GLIB_VERSION).lib \
 	$(PCAP_DIR)\lib\libpcap.lib
 
-editcap_LIBS= wiretap\libwtap.lib wsock32.lib user32.lib \
+editcap_LIBS= wiretap\wiretap.lib wsock32.lib user32.lib \
 	$(GLIB_DIR)\glib-$(GLIB_VERSION).lib \
 	$(GLIB_DIR)\gmodule\gmodule-$(GLIB_VERSION).lib
 
@@ -216,19 +216,19 @@
 
 all: wiretap gtk epan $(EXECUTABLES) $(RESOURCES)
 
-ethereal.exe	: config.h $(ethereal_OBJECTS) $(EXTRA_OBJECTS) image\ethereal.res wiretap\libwtap.lib gtk\libui.lib plugins
+ethereal.exe	: config.h $(ethereal_OBJECTS) $(EXTRA_OBJECTS) image\ethereal.res wiretap\wiretap.lib gtk\libui.lib plugins
 	@echo Linking $@
 	$(LINK) @<<
 		/OUT:ethereal.exe $(LDFLAGS) /SUBSYSTEM:windows $(ethereal_LIBS) $(ethereal_OBJECTS) $(EXTRA_OBJECTS) image\ethereal.res
 <<
 
-tethereal.exe	: config.h $(tethereal_OBJECTS) $(EXTRA_OBJECTS) image\tethereal.res wiretap\libwtap.lib plugins
+tethereal.exe	: config.h $(tethereal_OBJECTS) $(EXTRA_OBJECTS) image\tethereal.res wiretap\wiretap.lib plugins
 	@echo Linking $@
 	$(LINK) @<<
 		/OUT:tethereal.exe $(LDFLAGS) /SUBSYSTEM:console $(tethereal_LIBS) $(tethereal_OBJECTS) $(EXTRA_OBJECTS) image\tethereal.res
 <<
 
-editcap.exe	: config.h editcap.obj getopt.obj wiretap\libwtap.lib image\editcap.res
+editcap.exe	: config.h editcap.obj getopt.obj wiretap\wiretap.lib image\editcap.res
 	@echo Linking $@
 	$(LINK) @<<
 		/OUT:editcap.exe $(LDFLAGS) /SUBSYSTEM:console editcap.obj getopt.obj $(editcap_LIBS) image\editcap.res
Index: tethereal.c
===================================================================
RCS file: /usr/local/cvsroot/ethereal/tethereal.c,v
retrieving revision 1.51
diff -u -r1.51 tethereal.c
--- tethereal.c	2000/10/16 23:18:03	1.51
+++ tethereal.c	2000/10/26 04:39:29
@@ -1081,9 +1081,11 @@
   /* Find the size of the file. */
   fh = wtap_file(wth);
   fd = wtap_fd(wth);
+printf("t0, fd=%d\n", fd);
   if (fstat(fd, &cf_stat) < 0) {
     err = errno;
     wtap_close(wth);
+printf("t1\n");
     goto fail;
   }
 
Index: wiretap/Makefile.nmake
===================================================================
RCS file: /usr/local/cvsroot/ethereal/wiretap/Makefile.nmake,v
retrieving revision 1.15
diff -u -r1.15 Makefile.nmake
--- Makefile.nmake	2000/09/19 17:27:08	1.15
+++ Makefile.nmake	2000/10/26 04:39:29
@@ -32,8 +32,16 @@
 	toshiba.obj \
 	wtap.obj
 
-libwtap.lib	: config.h $(OBJECTS)
-	lib /out:libwtap.lib $(OBJECTS)
+wiretap_LIBS = \
+	wsock32.lib \
+	$(GLIB_DIR)\glib-$(GLIB_VERSION).lib 
+
+#wiretap.lib	: config.h $(OBJECTS)
+#	lib /out:wiretap.lib $(OBJECTS)
+
+wiretap.dll wiretap.lib wiretap.exp : config.h $(OBJECTS)
+	link /NOLOGO /DLL /OUT:wiretap.dll /IMPLIB:wiretap.lib \
+		/DEF:wtap.def $(OBJECTS) $(wiretap_LIBS)
 
 ascend-grammar.c ascend-grammar.h : ascend-grammar.y
 	$(YACC) $(YACC_OPTS) -d -p ascend ascend-grammar.y -o ascend-grammar.c
Index: wiretap/file.c
===================================================================
RCS file: /usr/local/cvsroot/ethereal/wiretap/file.c,v
retrieving revision 1.62
diff -u -r1.62 file.c
--- file.c	2000/09/19 17:22:09	1.62
+++ file.c	2000/10/26 04:39:30
@@ -148,12 +148,13 @@
 	struct stat statb;
 	wtap	*wth;
 	int	i;
-
+printf("a\n");
 	/* First, make sure the file is valid */
 	if (stat(filename, &statb) < 0) {
 		*err = errno;
 		return NULL;
 	}
+printf("b\n");
 	if (! S_ISREG(statb.st_mode) && ! S_ISFIFO(statb.st_mode)) {
 		if (S_ISDIR(statb.st_mode))
 			*err = EISDIR;
@@ -161,6 +162,7 @@
 			*err = WTAP_ERR_NOT_REGULAR_FILE;
 		return NULL;
 	}
+printf("c\n");
 
 	errno = ENOMEM;
 	wth = g_malloc(sizeof(wtap));
@@ -168,6 +170,7 @@
 		*err = errno;
 		return NULL;
 	}
+printf("d\n");
 
 /* Win32 needs the O_BINARY flag for open() */
 #ifndef O_BINARY
@@ -182,11 +185,13 @@
 		g_free(wth);
 		return NULL;
 	}
+printf("e, fd=%d\n", wth->fd);
 	if (!(wth->fh = filed_open(wth->fd, "rb"))) {
 		*err = errno;
 		g_free(wth);
 		return NULL;
 	}
+printf("f\n");
 
 	if (do_random) {
 		if (!(wth->random_fh = file_open(filename, "rb"))) {
@@ -198,6 +203,7 @@
 	} else
 		wth->random_fh = NULL;
 
+printf("g\n");
 	/* initialization */
 	wth->file_encap = WTAP_ENCAP_UNKNOWN;
 	wth->data_offset = 0;
@@ -212,25 +218,32 @@
 			/* I/O error - give up */
 			file_close(wth->fh);
 			g_free(wth);
+printf("h1\n");
 			return NULL;
 
 		case 0:
 			/* No I/O error, but not that type of file */
+printf("h2\n");
 			break;
 
 		case 1:
 			/* We found the file type */
+printf("h3\n");
 			goto success;
 		}
 	}
 
+printf("I\n");
 	/* Well, it's not one of the types of file we know about. */
 	if (wth->random_fh != NULL)
 		file_close(wth->random_fh);
+printf("j\n");
 	file_close(wth->fh);
+printf("k\n");
 	g_free(wth);
 	*err = WTAP_ERR_FILE_UNKNOWN_FORMAT;
 	return NULL;
+printf("L\n");
 
 success:
 	wth->frame_buffer = g_malloc(sizeof(struct Buffer));