Ethereal-users: Re: [ethereal-users] can't open an interface without IPv4 address assigned

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

From: Guy Harris <gharris@xxxxxxxxxxxx>
Date: Tue, 31 Oct 2000 23:35:45 -0800
On Tue, Sep 26, 2000 at 08:34:01AM -0600, Eichert, Diana wrote:
> 	My vote would be for the first time an interface is used.

That turns out to be a pain to do - when doing an "Update list of
packets in real time" capture, the process that tries to get the netmask
isn't the main process, it's the subprocess, and it'd have to tell the
parent process that it couldn't get the netmask.

For now, I've chosen not to put up any warning dialog box, as I suspect
people rarely use filters that check for IP broadcast addresses; here's
a patch to make this work with Ethereal and Tethereal by using a netmask
of 0 (the Tethereal version will print a warning).
? errs
? wiretap/gzio.c
? wiretap/zlib-1.1.3
Index: capture.c
===================================================================
RCS file: /usr/local/cvsroot/ethereal/capture.c,v
retrieving revision 1.130
diff -c -r1.130 capture.c
*** capture.c	2000/10/21 04:20:07	1.130
--- capture.c	2000/11/01 07:28:04
***************
*** 1179,1187 ****
    if (cfile.cfilter && !ld.from_pipe) {
      /* A capture filter was specified; set it up. */
      if (pcap_lookupnet (cfile.iface, &netnum, &netmask, err_str) < 0) {
!       snprintf(errmsg, sizeof errmsg,
!         "Can't use filter:  Couldn't obtain netmask info (%s).", err_str);
!       goto error;
      }
      if (pcap_compile(pch, &cfile.fcode, cfile.cfilter, 1, netmask) < 0) {
        snprintf(errmsg, sizeof errmsg, "Unable to parse filter string (%s).",
--- 1179,1194 ----
    if (cfile.cfilter && !ld.from_pipe) {
      /* A capture filter was specified; set it up. */
      if (pcap_lookupnet (cfile.iface, &netnum, &netmask, err_str) < 0) {
!       /*
!        * Well, we can't get the netmask for this interface; it's used
!        * only for filters that check for broadcast IP addresses, so
!        * we just punt and use 0.  It might be nice to warn the user,
!        * but that's a pain in a GUI application, as it'd involve popping
!        * up a message box, and it's not clear how often this would make
!        * a difference (only filters that check for IP broadcast addresses
!        * use the netmask).
!        */
!       netmask = 0;
      }
      if (pcap_compile(pch, &cfile.fcode, cfile.cfilter, 1, netmask) < 0) {
        snprintf(errmsg, sizeof errmsg, "Unable to parse filter string (%s).",
Index: tethereal.c
===================================================================
RCS file: /usr/local/cvsroot/ethereal/tethereal.c,v
retrieving revision 1.52
diff -c -r1.52 tethereal.c
*** tethereal.c	2000/10/31 08:15:26	1.52
--- tethereal.c	2000/11/01 07:28:07
***************
*** 592,600 ****
    if (cfile.cfilter) {
      /* A capture filter was specified; set it up. */
      if (pcap_lookupnet (cfile.iface, &netnum, &netmask, err_str) < 0) {
!       snprintf(errmsg, sizeof errmsg,
!         "Can't use filter:  Couldn't obtain netmask info (%s).", err_str);
!       goto error;
      }
      if (pcap_compile(ld.pch, &cfile.fcode, cfile.cfilter, 1, netmask) < 0) {
        snprintf(errmsg, sizeof errmsg, "Unable to parse filter string (%s).",
--- 592,605 ----
    if (cfile.cfilter) {
      /* A capture filter was specified; set it up. */
      if (pcap_lookupnet (cfile.iface, &netnum, &netmask, err_str) < 0) {
!       /*
!        * Well, we can't get the netmask for this interface; it's used
!        * only for filters that check for broadcast IP addresses, so
!        * we just warn the user, and punt and use 0.
!        */
!       fprintf(stderr, 
!         "Warning:  Couldn't obtain netmask info (%s)\n.", err_str);
!       netmask = 0;
      }
      if (pcap_compile(ld.pch, &cfile.fcode, cfile.cfilter, 1, netmask) < 0) {
        snprintf(errmsg, sizeof errmsg, "Unable to parse filter string (%s).",