Linux Raw Ethernet Socket Bind to Specific Protocol

linux raw ethernet socket bind to specific protocol

I have resolved the issue.

According to http://linuxreviews.org/dictionary/Ethernet/ referring to the 2 byte field following the MAC addresses:

"values of that field between 64 and 1522 indicated the use of the new 802.3 Ethernet format with a length field, while values of 1536 decimal (0600 hexadecimal) and greater indicated the use of the original DIX or Ethernet II frame format with an EtherType sub-protocol identifier."

so I have to make sure my ethertype is >= 0x0600.

According to http://standards.ieee.org/regauth/ethertype/eth.txt use of 0x88b5 and 0x88b6 is "available for public use for prototype and vendor-specific protocol development." So this is what I am going to use as an ethertype. I shouldn't need any further filtering as the kernel should make sure to only pick up ethernet frames with the right destination MAC address and using that protocol.

How to bind a Raw Socket to a specific port?

The man page for raw(7) says:

A raw socket can be bound to a specific local address using the bind(2) call. If it isn't bound all packets with the specified IP protocol are received. In addition a RAW socket can be bound to a specific network device using SO_BINDTODEVICE; see socket(7).

Edit: You cannot bind a raw socket to a specific port because "port" is a concept in TCP and UDP, not IP. Look at the header diagrams for those three protocols and it should become obvious: you are working at a lower level, where the concept of port is not known.

How can i avoid mulitple raw socket bind to the same ip address?

No. The mere fact that its RAW means there's no other protocol except RAW Internet Protocol. Without TCP or UDP, there won't be any port to distinguish which application this packet gets sent to, so instead, everything will have to be filtered through the IP packet's payload. You'd have to do this manually. Best way is to make a program that forwards these packets after inspection to wherever you want it to go.

ether type for adding custom protocol on ethernet frame

You can use any Ethertype that doesn't collide with any protocol in use in your network.

You should use only Ethertypes that you have previously registered with IANA IEEE, especially for anything you're planning to sell at some time.



Related Topics



Leave a reply



Submit