2000-11-01 19:21:35

by Dennis Bjorklund

[permalink] [raw]
Subject: Broadcast

I'm trying to turn of the broadcast flag for a network card. But I
can't, why??

I have two network-cards in the machine and an application (rwhod) that
wants to send it's messages out on every interface that can broadcast. But
never want to broadcast anything on this interface so why not turn it
of? If I could that is..

This is what happens:

$ ifconfig eth1
eth1 Link encap:Ethernet HWaddr 00:50:BA:6E:76:63
inet addr:192.168.0.1 Bcast:192.168.0.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:143190 errors:0 dropped:194 overruns:0 frame:0
TX packets:143584 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
Interrupt:9 Base address:0xe400

$ ifconfig eth1 -broadcast
$ ifconfig eth1
eth1 Link encap:Ethernet HWaddr 00:50:BA:6E:76:63
inet addr:192.168.0.1 Bcast:192.168.0.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:143228 errors:0 dropped:194 overruns:0 frame:0
TX packets:143622 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
Interrupt:9 Base address:0xe400

As you can see. It still says BROADCAST.

This is on the 2.2.16 kernel and

$ ifconfig -V
net-tools 1.54
ifconfig 1.39 (1999-03-18)

/Dennis


2000-11-01 19:28:38

by William T Wilson

[permalink] [raw]
Subject: Re: Broadcast

On Wed, 1 Nov 2000, Dennis Bjorklund wrote:

> I'm trying to turn of the broadcast flag for a network card. But I
> can't, why??

Broadcast determines the type of connection - broadcast or point-to-point
(there can be other types also, but you will not see them much).

You wouldn't want to do this anyway. It means Ethernet broadcasts, not IP
broadcasts. IP will not work over Ethernet without broadcasts.

> I have two network-cards in the machine and an application (rwhod)
> that wants to send it's messages out on every interface that can
> broadcast. But never want to broadcast anything on this interface so
> why not turn it of? If I could that is..

Do you really need rwhod at all?

If rwhod doesn't have an option as to which address to bind to, your only
choice is to block its communication with ipchains.

2000-11-01 19:31:19

by Rik van Riel

[permalink] [raw]
Subject: Re: Broadcast

On Wed, 1 Nov 2000, Dennis Bjorklund wrote:

> I'm trying to turn of the broadcast flag for a network card. But
> I can't, why??

Because ethernet is a broadcast medium (in contrast
to P-t-P media)

> eth1 Link encap:Ethernet HWaddr 00:50:BA:6E:76:63
> inet addr:192.168.0.1 Bcast:192.168.0.255 Mask:255.255.255.0
> UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

Rik
--
"What you're running that piece of shit Gnome?!?!"
-- Miguel de Icaza, UKUUG 2000

http://www.conectiva.com/ http://www.surriel.com/

2000-11-01 20:05:29

by Dennis Bjorklund

[permalink] [raw]
Subject: Re: Broadcast

On Wed, 1 Nov 2000, William T Wilson wrote:

> If rwhod doesn't have an option as to which address to bind to, your only
> choice is to block its communication with ipchains.

I don't think you can specify the addresses. It looks at the interfaces
and sends to the ones that can broadcast.

I have solved it with ipchains but then rwhod fills my /var/log/messages
with lines like:

Nov 1 20:40:28 x rwhod[650]: sendto(192.168.0.1): Operation not permitted
Nov 1 20:43:28 x rwhod[650]: sendto(192.168.0.1): Operation not permitted
Nov 1 20:46:28 x rwhod[650]: sendto(192.168.0.1): Operation not permitted

It's a lot of messages...

So if you cant turn of broadcast why does ifconfig have an option that
says it turns of broadcast.

[-]broadcast [addr]
If the address argument is given, set the protocol broadcast
address for this interface. Otherwise, set (or clear) the
IFF_BROADCAST flag for the interface.

And rwhod looks at the IFF_BROADCAST flag.

/Dennis

2000-11-01 20:10:10

by Richard B. Johnson

[permalink] [raw]
Subject: Re: Broadcast

On Wed, 1 Nov 2000, Dennis Bjorklund wrote:

> I'm trying to turn of the broadcast flag for a network card. But I
> can't, why??
>

Your version of `ifconfig` is probably broken (just like mine).
`strace` it and see:
ioctl(5, SIOCGIFFLAGS, 0xbffff620) = 0
ioctl(5, SIOCSIFFLAGS, 0xbffff620) = 0
_exit(0) = ?

In this case the flags were gotten with SIOCGIFFLAGS, then the
exact same stuff was written back with SIOCSIFFLAGS.


Cheers,
Dick Johnson

Penguin : Linux version 2.2.17 on an i686 machine (801.18 BogoMips).

"Memory is like gasoline. You use it up when you are running. Of
course you get it all back when you reboot..."; Actual explanation
obtained from the Micro$oft help desk.


2000-11-01 20:55:04

by Dennis Bjorklund

[permalink] [raw]
Subject: Re: Broadcast

On Wed, 1 Nov 2000, Richard B. Johnson wrote:

> > I'm trying to turn of the broadcast flag for a network card. But I
> > can't, why??
>
> Your version of `ifconfig` is probably broken (just like mine).
> `strace` it and see:
> ioctl(5, SIOCGIFFLAGS, 0xbffff620) = 0
> ioctl(5, SIOCSIFFLAGS, 0xbffff620) = 0
>
> In this case the flags were gotten with SIOCGIFFLAGS, then the
> exact same stuff was written back with SIOCSIFFLAGS.

IFF_BROADCAST is bit number 1 (that is 0x2). So in this case it indicates
that the broadcast bit is not set before and not set after. But why do I
see BROADCAST listed when i do "ifconfig eth1" then. This bit should be
set.

Right now I'm a bit confused. There is something strange going on here
that I don't understand.

/Dennis

2000-11-01 21:03:06

by Dennis Bjorklund

[permalink] [raw]
Subject: Re: Broadcast

On Wed, 1 Nov 2000, Dennis Bjorklund wrote:

> > ioctl(5, SIOCGIFFLAGS, 0xbffff620) = 0
> > ioctl(5, SIOCSIFFLAGS, 0xbffff620) = 0
> >
> > In this case the flags were gotten with SIOCGIFFLAGS, then the
> > exact same stuff was written back with SIOCSIFFLAGS.
>
> IFF_BROADCAST is bit number 1 (that is 0x2). So in this case it indicates
> that the broadcast bit is not set before and not set after. But why do I
> see BROADCAST listed when i do "ifconfig eth1" then. This bit should be
> set.
>
> Right now I'm a bit confused. There is something strange going on here
> that I don't understand.

Forget this comment.

The 0xbffff620 is an adress and nothing else. It should be the same. The
flag is toggled in the struct that the adress points to.

It explains the strace but not why I can't clear the flag..

/Dennis

2000-11-01 21:07:46

by Richard B. Johnson

[permalink] [raw]
Subject: Re: Broadcast

On Wed, 1 Nov 2000, Dennis Bjorklund wrote:

> On Wed, 1 Nov 2000, Richard B. Johnson wrote:
>
> > > I'm trying to turn of the broadcast flag for a network card. But I
> > > can't, why??
> >
> > Your version of `ifconfig` is probably broken (just like mine).
> > `strace` it and see:
> > ioctl(5, SIOCGIFFLAGS, 0xbffff620) = 0
> > ioctl(5, SIOCSIFFLAGS, 0xbffff620) = 0
> >
> > In this case the flags were gotten with SIOCGIFFLAGS, then the
> > exact same stuff was written back with SIOCSIFFLAGS.
>
> IFF_BROADCAST is bit number 1 (that is 0x2). So in this case it indicates
> that the broadcast bit is not set before and not set after. But why do I
> see BROADCAST listed when i do "ifconfig eth1" then. This bit should be
> set.
>
> Right now I'm a bit confused. There is something strange going on here
> that I don't understand.
>

Well I screwed up the explaination. That number is a pointer, so it
won't change. However, I made some software for an imbedded system
that sets up ethernet. It was during this time that I noted that
`ifconfig` doesn't always do what it's told, but the kernel does:


/*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
/*
* File ifconfig.c Created 12-DEC-1999 Richard B. Johnson
*
* This replaces the usual Unix `ifconfig` program to configure the
* network interface devices. It gets its network parameters from
* shared memory.
*/
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <string.h>
#include <linux/if.h>
#include <plib.h>

#define IF_NOTSET(a) \
if(!!ioctl(s, (a), &ifr))

#define EXTRACT_ADDR(m) \
*((unsigned long *) &ifr.m.sa_data[2])

/*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
/*
* See if an ethernet device exists within the kernel. This should fail
* if one does not exist. It attempts to get the current flags from
* the interface.
*/
int chk_eth0()
{
struct ifreq ifr;
int s, status;
if((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
ERRORS(Socket);
memset(&ifr, 0x00, sizeof(ifr));
ifr.ifr_netmask.sa_family = AF_INET;
strcpy(ifr.ifr_name, Eth0);
status = ioctl(s, SIOCGIFFLAGS, &ifr);
(void)close(s);
return status;
}
/*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
/*
* This does all the stuff that the SYS-V 'ifconfig' does to start both
* the loopback and the Ethernet network.
*/
void ifconfig()
{
struct ifreq ifr;
struct ifreq tem;
int s;
if((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
ERRORS(Socket);
/*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
/*
* First set up the loop-back device. This gets the standard hard-coded
* parameters.
*/
if(!pars->lo_up)
{
memset(&tem, 0x00, sizeof(tem));
tem.ifr_netmask.sa_family = AF_INET;
strcpy(tem.ifr_name, Lo);

ifr = tem;
EXTRACT_ADDR(ifr_addr) = 0x0100007F;
IF_NOTSET(SIOCSIFADDR)
logerror(__LINE__,__FILE__,Ioctl, errno);
ifr = tem;
EXTRACT_ADDR(ifr_netmask) = 0x000000FF;
IF_NOTSET(SIOCSIFNETMASK)
logerror(__LINE__,__FILE__,Ioctl, errno);
ifr = tem;
EXTRACT_ADDR(ifr_broadaddr) = 0xFFFFFF7F;
IF_NOTSET(SIOCSIFBRDADDR)
logerror(__LINE__,__FILE__,Ioctl, errno);
ifr = tem;
ifr.ifr_mtu = LO_MTU;
IF_NOTSET(SIOCSIFMTU)
logerror(__LINE__,__FILE__,Ioctl, errno);
ifr = tem;
ifr.ifr_flags = (IFF_UP|IFF_LOOPBACK|IFF_BROADCAST|IFF_RUNNING);
IF_NOTSET(SIOCSIFFLAGS)
logerror(__LINE__,__FILE__,Ioctl, errno);
}
/*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
/*
* Now set up the possibly new parameters for the single Ethernet device.
*/
memset(&tem, 0x00, sizeof(tem));
tem.ifr_netmask.sa_family = AF_INET;
strcpy(tem.ifr_name, Eth0);
/*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
/*
* Shut down old interface by resetting all the flags.
*/
ifr = tem;
ifr.ifr_flags = 0;
IF_NOTSET(SIOCSIFFLAGS)
logerror(__LINE__,__FILE__,Ioctl, errno);
/*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
/*
* Now set it up. It gets an address, a netmask, a broadcast address,
* and some flags. Routes are added later.
*/
ifr = tem;
EXTRACT_ADDR(ifr_addr) = pars->ipaddr;
IF_NOTSET(SIOCSIFADDR)
logerror(__LINE__,__FILE__,Ioctl, errno);
ifr = tem;
EXTRACT_ADDR(ifr_netmask) = pars->netmask;
IF_NOTSET(SIOCSIFNETMASK)
logerror(__LINE__,__FILE__,Ioctl, errno);
ifr = tem;
EXTRACT_ADDR(ifr_broadaddr) = pars->broadcast;
IF_NOTSET(SIOCSIFBRDADDR)
logerror(__LINE__,__FILE__,Ioctl, errno);
ifr = tem;
ifr.ifr_mtu = MTU;
IF_NOTSET(SIOCSIFMTU)
logerror(__LINE__,__FILE__,Ioctl, errno);
ifr = tem;
ifr.ifr_flags = (IFF_UP|IFF_BROADCAST|IFF_RUNNING|IFF_MULTICAST);
IF_NOTSET(SIOCSIFFLAGS)
logerror(__LINE__,__FILE__,Ioctl, errno);
if(!!close(s))
ERRORS(Close);
return;
}

Note that these are just bits in the flag variable:
ifr.ifr_flags = (IFF_UP|IFF_BROADCAST|IFF_RUNNING|IFF_MULTICAST);

You can turn these on/off at will. However, you have to understand
that TCP/IP won't work without broadcast. It's needed to do the
ARP (Address Resolution Protocol), so that peer-to-peer hardware
addresses become known.

Cheers,
Dick Johnson

Penguin : Linux version 2.2.17 on an i686 machine (801.18 BogoMips).

"Memory is like gasoline. You use it up when you are running. Of
course you get it all back when you reboot..."; Actual explanation
obtained from the Micro$oft help desk.