Hi,
Answers to your questions are below
1. Bind is only needed when you need to receive packets from a specefic
interface.
2. Please give me some more info on this.
3. I have collected some info from man page for receving broadcast
which will help you in receving broadcast packets
ADDRESS TYPES
The sockaddr_ll is a device independent physical layer address.
struct sockaddr_ll {
unsigned short sll_family; /* Always AF_PACKET */
unsigned short sll_protocol; /* Physical layer protocol */
int sll_ifindex; /* Interface number */
unsigned short sll_hatype; /* Header type */
unsigned char sll_pkttype; /* Packet type */
unsigned char sll_halen; /* Length of address */
unsigned char sll_addr[8]; /* Physical layer address */
};
sll_protocol is the standard ethernet protocol type in network order as
defined in the linux/if_ether.h include file. It defaults to the
socket's protocol. sll_ifindex is the interface index of the interface
(see netdevice(7)); 0 matches any interface (only legal for binding).
sll_hatype is a ARP type as defined in the linux/if_arp.h include file.
sll_pkttype contains the packet type. Valid types are PACKET_HOST for a
packet addressed to the local host, PACKET_BROADCAST for a physical
layer broadcast packet, PACKET_MULTICAST for a packet sent to a
physical layer multicast address, PACKET_OTHERHOST for a packet to some
other host that has been caught by a device driver in promiscuous mode,
and PACKET_OUTGOING for a packet originated from the local host that is
looped back to a packet socket. These types make only sense for
receiving. sll_addr and sll_halen contain the physical layer (e.g. IEEE
802.3) address and its length. The exact interpretation depends on the
device.
When you send packets it is enough to specify sll_family, sll_addr,
sll_halen, sll_ifindex. The other fields should be 0. sll_hatype and
sll_pkttype are set on received packets for your information. For bind
only sll_protocol and sll_ifindex are used.
Please feel free to contact if you need any more info.
Thanks,
Sunil
manolinux wrote:
> Hi,
>
> I'm working with raw-ethernet sockets, and there are some questions
> that have arisen to me during my work. Hope someone knows the answers !
>
> 1) Bind step is always necessary when opening PF_PACKET sockets? Only
> in sending, in receiving, in both?
>
> 2) Is there any patch that solves problem of getting repeated packets
> when using loopback interface + multicast?
>
> 3) I cannot receive broadcast messages from a raw ethernet socket which
> i open this way:
>
> sk = socket (PF_PACKET,SOCK_RAW,0);
>
> do i need to pass any kind of option to the socket to enable broadcast
> receiving?
>
>
> Thanx a lot in advance,
> Manuel Cotallo.
|