aboutsummaryrefslogtreecommitdiffstats
path: root/capture.c
AgeCommit message (Collapse)AuthorFilesLines
1999-09-30Add a new global flag "capture_child", which is TRUE if we're a childGuy Harris1-20/+38
process for a sync mode or fork mode capture. Have that flag control whether we do things that *only* the parent or *only* the child should do, rather than basing it solely on the setting of "sync_mode" or "fork_mode" (or, in the case of stuff done in the child process either in sync mode or fork mode, rather than basing it on the setting of those flags at all). Split "do_capture()" into a "run_capture()" routine that starts a capture (possibly by forking off and execing a child process, if we're supposed to do sync mode or fork mode captures), and that assumes the file to which the capture is to write has already been opened and that "cf.save_file_fd" is the file descriptor for that file, and a "do_capture()" routine that creates a temporary file, getting an FD for it, and calls "run_capture()". Use "run_capture()", rather than "capture()", for "-k" captures, so that it'll do the capture in a child process if "-S" or "-F" was specified ("do_capture()" won't do because "-k" captures should write to the file specified by the "-w" flag, not some random temporary file). For child process captures, however, just use "capture()" - the child process shouldn't itself fork off a child if we're in sync or fork mode, and should just write to the file whose file descriptor was specified by the "-W" flag on the command line. All this allows you to do "ethereal -S -w <file> -i <interface> -k" to start a sync mode capture from the command line. svn path=/trunk/; revision=740
1999-09-30If we're given the "-k" flag, don't start the capture until after we've:Guy Harris1-3/+3
popped up the top-level window (so that it looks like a capture started from "Capture/Start"); initialized the colors (so that we don't dump core when reading in the capture file); popped up any message box for failure to read the preferences file. This means we start the capture in "main()", rather than in the realize callback for the main window, so get rid of that callback. If we're a child process that's just capturing to a file for our parent to read, however, we shouldn't pop up the top-level window, because that's our parent's job; when running that child, set its "argv[0]" to a special name, so that 1) it shows up in a "ps" with a special name; 2) we don't have to invent Yet Another Flag to say "you're the child". (We may want to use the name to turn on *all* behaviors that the capture child, and only the capture child, should exhibit.) If "-w" and "-k" were both specified, attempt to open the file specified by "-w" and, if that succeeds, set "cf.save_file_fd" to refer to it, so that "-w" plus "-k" works again, rather than popping up a "The file to which the capture would be saved ... could not be opened: Bad file descriptor." message box. svn path=/trunk/; revision=739
1999-09-25Squelch a (justified, although the child process *shouldn't* ever sendGuy Harris1-2/+2
us, at that point, a character with the 8th bit set) complaint about a "char" array subscript in an "isdigit()" call by making the character unsigned. svn path=/trunk/; revision=724
1999-09-23Close the capture file in "do_capture()", right before unlinking theGuy Harris1-14/+8
current capture file if it's a temporary file, out of paranoia (so that we don't get into a state where we have a capture file open but unlinked - it's probably harmless to be in that state, as the file will remain around until close, modulo NFS fun, and we may never be in that state for very long, but I'd rather have it obviously stated in the code). Remove the close in "capture()", and put one before the other call to "capture()", in "main_realize_cb()" (is that call necessary, e.g. if you pass "-r <filename>" *and* "-k", for some perverse reason, as command-line arguments?). If "cf.save_file" is non-null, free it before setting it, regardless of whether it refers to a temporary file name or not. svn path=/trunk/; revision=712
1999-09-23If we forcibly turn off "fork_mode" if the user doesn't enable "UpdateGuy Harris1-4/+4
list of packets in real time" in the "Capture/Start" dialog box, "ethereal -F" won't work - you get your choice of non-forked capture or "-S". Don't have "fork_mode" track "sync_mode"; instead, in those places where we check for "fork_mode", check for "sync_mode" as well. svn path=/trunk/; revision=711
1999-09-23In fork mode, close the capture file in "do_capture()", because theGuy Harris1-44/+63
child will nuke that file before we get to open the capture in "tail_cap_file()" - assuming we do, because the capture may not start. If we fail while writing to, or closing, a capture file we've opened for writing, don't treat that as a capture error, as we may have saved at least some packets to the capture file (that's the way it worked before my recent checkins). svn path=/trunk/; revision=710
1999-09-23Move the toolkit-independent code to create a temporary capture file,Guy Harris1-224/+372
and to fork off and run a separate copy of "ethereal" for "-S" and "-F" captures or just call "capture()" otherwise, out of "gtk/capture_dlg.c" and into a routine in "capture.c". If the attempt to create said temporary capture file fails, pop up a dialog box and don't do the capture. Have the child capture process send a message upstream after it either successfully starts the capture and syncs out the header of the capture file, or fails to start the capture; the message indicates whether it succeeded or failed, and, if it failed, includes a failure message. This: avoids the use of a signal, and thus means we don't have to worry about whether to capture the signal, or whether to start or stop capturing depending on whether this particular capture is in sync mode or not; lets us pop up the message box for the error in the parent process if we're in sync mode, rather than doing it in the child, which didn't work well. Add a check button to the Capture/Start dialog box, so that we can control, for each capture, whether it's to be done in sync mode or not. svn path=/trunk/; revision=708
1999-09-11"capture.c" doesn't do socket "ioctl"s any more - the code to do that isGuy Harris1-5/+1
now in "gtk/capture_dlg.c" - so it doesn't need to include <sys/sockio.h> on, for example, Solaris... ...but "gtk/capture_dlg.c" does need to include it. "gtk/capture_dlg.c" also may need to include "snprintf.h", as it uses "snprintf()". svn path=/trunk/; revision=655
1999-09-09More shuffling of GTK-related routines to gtk subdirectory.Gilbert Ramirez1-433/+3
svn path=/trunk/; revision=636
1999-09-09More shuffling of GTK-related files to gtk subdirectory.Gilbert Ramirez1-2/+2
svn path=/trunk/; revision=635
1999-09-08Don't include in the list of interfaces offered by the "capture" dialogGuy Harris1-6/+32
box interfaces we can't open; this filters out loopback interfaces on e.g. Solaris (which you can't get at with a DLPI device, so you can't capture traffic on them), and also means we don't report *any* interfaces if you don't have permission to open any (which means you don't have permission to capture packets). If we don't find any interfaces, pop up a message box saying so. Free up the interface "ioctl" buffer, and close the socket we were using, before returning from "get_interface_list()". If "get_interface_list()" returns a null pointer (meaning it failed), don't pop up the "capture" dialog box. svn path=/trunk/; revision=634
1999-09-01Moved GTK-dependent routines for file dialogues, print dialogues, printGilbert Ramirez1-2/+2
preferences, and menus to gtk subdirectory. svn path=/trunk/; revision=623
1999-08-24Removed unnecessary #include "etypes.h" lines.Gilbert Ramirez1-2/+1
svn path=/trunk/; revision=565
1999-08-24Add a new Wiretap encapsulation type WTAP_ENCAP_FDDI_BITSWAPPED, meaningGuy Harris1-1/+2
"FDDI with the MAC addresses bit-swapped"; whether the MAC addresses are bit-swapped is a property of the machine on which the capture was taken, not of the machine on which the capture is being read - right now, none of the capture file formats we read indicate whether FDDI MAC addresses are bit-swapped, but this does let us treat non-"libpcap" captures as being bit-swapped or not bit-swapped independent of the machine on which they're being read (and of the machine on which they were captured, but I have the impression they're bit-swapped on most platforms), and allows us to, if, as, and when we implement packet capture in Wiretap, mark packets in a capture file written in Wiretap-native format based on the machine on which they are captured (assuming the rule "Ultrix, Alpha, and BSD/OS are the only platforms that don't bit-swap", or some other compile-time rule, gets the right answer, or that some platform has drivers that can tell us whether the addresses are bit-swapped). (NOTE: if, for any of the capture file formats used only on one platform, FDDI MAC addresses aren't bit-swapped, the code to read that capture file format should be fixed to flag them as not bit-swapped.) Use the encapsulation type to decide whether to bit-swap addresses in "dissect_fddi()". svn path=/trunk/; revision=557
1999-08-22Get rid of some cruft left in by previous checkins as placeholders.Guy Harris1-13/+4
Get rid of WTAP_ENCAP_NONE; replace it with WTAP_ENCAP_UNKNOWN, which means "I can't handle that file, it's using an encapsulation I don't support". Check for encapsulations we don't support, and return an error (as is already done in "libpcap.c"). Check for too-large packet sizes, and return an error (as is already done in "libpcap.c"). Print unsigned quantities in Wiretap messages with "%u", not "%d". svn path=/trunk/; revision=544
1999-08-22Have the message boxes put up for "libpcap" errors include the errorGuy Harris1-7/+9
message from "libpcap". svn path=/trunk/; revision=541
1999-08-22DLT_NULL, from "libpcap", means different things on different platformsGuy Harris1-28/+111
and in different capture files; throw in some heuristics to try to figure out whether the 4-byte header is: 1) PPP-over-HDLC (some version of ISDN4BSD?); 2) big-endian AF_ value (BSD on big-endian platforms); 3) little-endian AF_ value (BSD on little-endian platforms); 4) two octets of 0 followed by an Ethernet type (Linux, at least on little-endian platforms, as mutated by "libpcap"). Make a separate Wiretap encapsulation type, WTAP_ENCAP_NULL, corresponding to DLT_NULL. Have the PPP code dissect the frame if it's PPP-over-HDLC, and have "ethertype()" dissect the Ethernet type and the rest of the packet if it's a Linux-style header; dissect it ourselves only if it's an AF_ value. Have Wiretap impose a maximum packet size of 65535 bytes, so that it fails more gracefully when handed a corrupt "libpcap" capture file (other capture file formats with more than a 16-bit capture length field, if any, will have that check added later), and put that size in "wtap.h" and have Ethereal use it as its notion of a maximum packet size. Have Ethereal put up a "this file appears to be damaged or corrupt" message box if Wiretap returns a WTAP_ERR_BAD_RECORD error when opening or reading a capture file. Include loopback interfaces in the list of interfaces offered by the "Capture" dialog box, but put them at the end of the list so that it doesn't default to a loopback interface unless there are no other interfaces. Also, don't require that an interface in the list have an IP address associated with it, and only put one entry in the list for a given interface (SIOCGIFCONF returns one entry per interface *address*, not per *interface* - and even if you were to use only IP addresses, an interface could conceivably have more than one IP address). Exclusively use Wiretap encapsulation types internally, even when capturing; don't use DLT_ types. svn path=/trunk/; revision=540
1999-08-19Use "g_strdup()" rather than "strdup()".Guy Harris1-2/+2
svn path=/trunk/; revision=517
1999-08-19Have the per-capture-file-type open routines "wtap_open_offline()" callsGuy Harris1-5/+4
return 1 on success, -1 if they got an error, and 0 if the file isn't of the type that file is checking for, and supply an error code if they return -1; have "wtap_open_offline()" use that error code. Also, have the per-capture-file-type open routines treat errors accessing the file as errors, and return -1, rather than just returning 0 so that we try another file type. Have the per-capture-file-type read routines "wtap_loop()" calls return -1 and supply an error code on error (and not, as they did in some cases, call "g_error()" and abort), and have "wtap_loop()", if the read routine returned an error, return FALSE (and pass an error-code-pointer argument onto the read routines, so they fill it in), and return TRUE on success. Add some new error codes for them to return. Now that "wtap_loop()" can return a success/failure indication and an error code, in "read_cap_file()" put up a message box if we get an error reading the file, and return the error code. Handle the additional errors we can get when opening a capture file. If the attempt to open a capture file succeeds, but the attempt to read it fails, don't treat that as a complete failure - we may have managed to read some of the capture file, and we should display what we managed to read. svn path=/trunk/; revision=516
1999-08-18"wtap_pcap_encap_to_wtap_encap()" shouldn't return a file type if itGuy Harris1-1/+7
can't translate the encapsulation type, it should return an encapsulation type; we add a new one, WTAP_ENCAP_UNKNOWN. and have it return that. Have "capture()" handle "wtap_pcap_encap_to_wtap_encap()" returning that encapsulation type (if it happens, we need to add a new Wiretap encapsulation type to handle the new "libpcap" encapsulation type). svn path=/trunk/; revision=513
1999-08-18Make "wtap_dump()" and "wtap_dump_close()" return error codes, and checkGuy Harris1-7/+38
for errors when closing a file to which we've written packets (we don't bother checking if we're giving up on a capture). Add some more error checks in Wiretap. Make a single list of all Wiretap error codes, giving them all different values (some can be returned by more than one routine, so they shouldn't be per-routine). svn path=/trunk/; revision=510
1999-08-18Add to Wiretap the ability to write capture files; for now, it can onlyGuy Harris1-33/+69
write them in "libpcap" format, but the mechanism can have other formats added. When creating the temporary file for a capture, use "create_tempfile()", to close a security hole opened by the fact that "tempnam()" creates a temporary file, but doesn't open it, and we open the file with the name it gives us - somebody could remove the file and plant a link to some file, and, if as may well be the case when Ethereal is capturing packets, it's running as "root", that means we write a capture on top of that file.... (The aforementioned changes to Wiretap let you open a capture file for writing given an file descriptor, "fdopen()"-style, which this change requires.) svn path=/trunk/; revision=509
1999-08-15The "loop_data" structure is used only in "capture.c"; move itsGuy Harris1-1/+10
definition from "capture.h" to "capture.c". svn path=/trunk/; revision=499
1999-08-15"open_cap_file()", if it succeeds, closes any capture file we had open;Guy Harris1-5/+3
that means it destroys any read filter we had, so we don't need to destroy it in "capture()" after "open_cap_file()" succeeds. svn path=/trunk/; revision=498
1999-08-15Don't preserve the read filter from file to file - you won't necessarilyGuy Harris1-5/+10
want to read the next file with the same filter that you used on the last file. In the "File/Open" dialog box, parse the read filter before trying to open the file, and if the parse fails, leave the dialog box up so the user still has the filter and file name around and can try to fix the problem. Keep the compiled read filter attached to the "capture_file" structure, so you don't have to reparse it on a "File/Reload". svn path=/trunk/; revision=497
1999-08-15"read_cap_file()" doesn't need to be passed a file name as an argument -Guy Harris1-2/+2
it's called after "open_cap_file()" has been called, and is always passed the file name passed to "open_cap_file()", and that file name is stored as "cf->filename", so "read_cap_file()" can just use "cf->filename" as the pathname of the file. svn path=/trunk/; revision=494
1999-08-15Split "load_cap_file()" into "open_cap_file()" and "read_cap_file()".Guy Harris1-3/+3
The former, which used to be called by "load_cap_file()", now just opens the file and, if the open succeeds, closes any capture file we previously had open, reinitializes any protocols that need reinitialization, and saves information about the new capture file in the "capture_file" structure to which it was passed a pointer. The latter reads the file already opened by "read_cap_file()". For "File/Open", call "open_cap_file()" before dismissing the file selection box; if it fails, "open_cap_file()" will have popped up a message box complaining about it - just return, leaving the file selection box open so the user can, after dismissing the message box, either try again with a different file name, or dismiss the file selection box. (Other file selection boxes should be made to work the same way.) If "open_cap_file()" succeeds, dismiss the file selection box, and read the capture file in. svn path=/trunk/; revision=492
1999-08-14Add ICMP to the set of packet types counted in the window shown while aGuy Harris1-2/+11
capture is in progress. svn path=/trunk/; revision=491
1999-08-10Display counts of NetBEUI/NBF frames as "NetBIOS".Guy Harris1-3/+3
svn path=/trunk/; revision=467
1999-08-10Jeff Foster's changes to add support for NetBEUI/NBF (NetBIOS atop 802.2Guy Harris1-13/+22
LLC, the original NetBIOS encapsulation). svn path=/trunk/; revision=466
1999-08-10Change the test of pcap_dispatch returned valueLaurent Deniel1-3/+3
which might be -1. svn path=/trunk/; revision=465
1999-08-10Fix the -S option timeout handling:Laurent Deniel1-23/+15
- when in a live capture mode no packet is received during a timeout, the displayer process is notified about any remaining captured packets. Note that this fix works on Linux only with a patched libpcap. - remove unnecessary time() call and sync_time loop_data field. Thanks to John McDermott for his help during fixing and testing. svn path=/trunk/; revision=464
1999-08-10Add the ability to specify a filter to be used when reading the file toGuy Harris1-6/+3
the "Open File" dialog box (the "Open File" dialog box equivalent of the "-R" flag). Have "load_cap_file()" take the filter expression as an argument, and make the global "rfilter" into a member of a "capture_file" structure. When reading a temporary capture file after a live capture, don't apply any filter. Move the code that pops up error boxes on file opens when reading a capture file back to "load_cap_file()"; it also pops up error boxes if the filter expression can't be parsed. Don't enable "File/Save" or "File/Save As..." if an attempt to read a capture file fails - if there was already an open capture file, it was closed by "load_cap_file()", so we no longer have an open file to save. svn path=/trunk/; revision=460
1999-08-05Use execlp instead of execl to scan the PATH for theLaurent Deniel1-11/+11
ethereal executable (but this is only performed if ethereal_path (i.e. arg[0]) does not contain any '/'). svn path=/trunk/; revision=445
1999-08-03Update version numbers to 0.7.0, and update win32 Makefiles. I made someGilbert Ramirez1-1/+15
initial #ifdef changes to capture.c to support the win32 version of libpcap. svn path=/trunk/; revision=428
1999-08-02Changed the chmod() call to a pair of umask() calls that straddle theGilbert Ramirez1-2/+9
call to pcap_dump_open. This allows us to control the readability of the temporary trace file, and avoid a race condition in which a user could open the trace file after the pcap_dump_open() call and the subsequent chmod() call. Thanks to Jeorg for pointing for pointing out the race condition. svn path=/trunk/; revision=421
1999-07-31chmod() the temporary capture file to 0600 so that only the user canGilbert Ramirez1-2/+6
read the trace. We chmod() after pcap creates the file, but before it actually writes data there. Thanks to Frederic Peters <fpeters@multimania.com>, the Debian maintainer of Ethereal, for pointing this out. svn path=/trunk/; revision=413
1999-07-28Fix the -S option :Laurent Deniel1-4/+12
- read only the real number of packets that have been written by the child process. That's avoid incomplete packet read. - special timeout handling no more necessary and the whole real time capture and display behavior is much more satisfying with this patch. - wiretap modified to allow the reading of 'count' packets with wtap_loop. svn path=/trunk/; revision=398
1999-07-28Added a bug fix from Erik Daughtrey that sets cf_filter to NULL after beingGerald Combs1-1/+2
freed. svn path=/trunk/; revision=393
1999-07-24Have "close_cap_file()" disable all menu items that make sense only ifGuy Harris1-6/+16
you have a capture. Leave the job of enabling and disabling menu items that make sense only if you have a capture (except for "File/Save" and "File/Save As...", for now) up to "load_cap_file()", "close_cap_file()", and the like - don't scatter that stuff throughout the code. Disable "File/Print Packet" if no packet is selected; enable it only if a packet is selected. If there's a selected packet, and a display filter is run: if the selected packet passed the filter, re-select it; if the selected packet didn't pass the filter, un-select it. If we've opened a live "pcap" capture, but can't do the capture because we can't get the netmask info, or can't parse the capture filter string, or can't install the filter, close the live capture and the dump and delete the dump file. If we failed to open a live "pcap" capture, don't try to read the capture file - it doesn't exist. svn path=/trunk/; revision=384
1999-07-23Add a "File/Print" menu item, which prints *all* the packets in theGuy Harris1-2/+3
capture to a file or printer. This should eventually get the ability to print either all the packets or only the packets selected by the display filter, and possibly also the ability to print only packets M through N. Get rid of "cur" member of "capture_file" structure; nobody used it. There's no need to pass a pointer to a "dialog_button" variable to "simple_dialog()" for the error boxes displayed if a file copy or move fails; that dialog box is just a message box and has only an "OK" button. Put the declaration of "prefs" into "prefs.h". svn path=/trunk/; revision=378
1999-07-20If doing a catpure with "-S", as soon as we've created the capture fileGuy Harris1-11/+10
(this assumes that "libpcap" writes out the header as soon as that happens, which is the case for "libpcap" 0.4), we sync it out (to make sure said header is in the file), and signal the parent process, so that it opens the capture file and updates its windows to indicate that the capture is in progress. svn path=/trunk/; revision=371
1999-07-20Fix a comment.Guy Harris1-2/+2
svn path=/trunk/; revision=369
1999-07-13Since ethereal is now dependent on GTK+-1.2.x (because of proto_tree andGilbert Ramirez1-7/+1
display filter code, which uses features in GLIB-1.2.x), I removed the vestigial code supporting old 1.0.x and 1.1.x GTK+ versions. svn path=/trunk/; revision=360
1999-07-09Added the ability to create a read-only ethereal, i.e., one thatGilbert Ramirez1-3/+5
doesn't link with libpcap, so no packet captures can be made. The "--disable-pcap" option has been added to the configure script. Docs have been updated. And the string buffer size in the simple_dialog() has been doubled so that Johan's e-mail address in the "About" dialogue window doesn't get chopped off. svn path=/trunk/; revision=351
1999-06-22Added Aaron Hillegass' summary dialogue. We're ignoring the problem withGilbert Ramirez1-1/+3
NetMon statistic packets for now. We might fix that problem with wiretap, either filtering out those packets, and/or providing the summary information through a new wiretap API. svn path=/trunk/; revision=326
1999-06-21Found some erroneous usages of gtk_signal_connect_object. I always wonderedGilbert Ramirez1-19/+14
why I had to swap fields (data = w) in some of the callback functions when I added support for gtk+-1.1. Because of the use of gtk_signal_connect_object, the wrong value was being sent to the callback function. We were just lucky that with gtk+-1.0 it worked. gtk_signal_connect_object is for use with callbacks that take one argument. gtk_signal_connect is for use with callbacks that take two arguments. svn path=/trunk/; revision=324
1999-06-19Added "Capture" and "Display" menus; "Capture" has a "Start" item, whichGuy Harris1-51/+14
is the same as "Tools/Capture", and "Display" has an "Options" item, which pops up a dialog box to let you change the "default" time-stamp column display format on the fly (the "default" is what the "-t" command-line option sets), and have the display change when you do that. Made infrastructure changes to make the immediate display update work. Removed some unused functions, declared some functions used only in the file in which they're defined "static", and removed some unnecessary #includes. svn path=/trunk/; revision=317
1999-06-12Improve the alert boxes put up for file open/read/write errors. (SomeGuy Harris1-8/+21
influence came from http://developer.apple.com/techpubs/mac/HIGuidelines/HIGuidelines-232.html which has a section on dialog box and alert box messages. However, we're largely dealing with technoids, not with The Rest Of Us, so I didn't go as far as one perhaps should.) Unfortunately, it looks like it's a bit more work to arrange that, if you give a bad file name to the "-r" flag, the dialog box pop up only *after* the main window pops up - it has the annoying habit of popping up *before* the main window pops up, and sometimes getting *obscured* by it, when I do that. The removal of the dialog box stuff from "load_cap_file()" was intended to facilitate that work. (It might also be nice if, when an open from the "File/Open" menu item fails, we keep the file selection box open, and give the user a chance to correct typos, choose another file name, etc.) svn path=/trunk/; revision=310
1999-06-11Added PPPoE, PPTP, GRE, and ISAKMP dissectors.Gilbert Ramirez1-2/+11
svn path=/trunk/; revision=303