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
Why Is Crond Failing to Run a Non-Root Crontab on Alpine Linux
How to Make a Bash Shell Script Interact with Another Command Line Program
Sed Help: Matching and Replacing a Literal "\N" (Not the Newline)
Check If a Program in a Specific Path Is Running
Prohibit Unaligned Memory Accesses on X86/X86_64
Use a C Library in Swift on Linux
Getting "I Won't Open a Connection To" When Connecting to Ftp Server from Google Compute Engine
How to Return Exit Code 0 from a Failed Command
Loading Linux Text File into Excel Using Vba
How to Disable Socket Creation for a Linux Process, for Sandboxing
How to Save the Output of This Awk Command to File
Debugging Shared Libraries with Gdbserver
Can Ptrace Tell If an X86 System Call Used the 64-Bit or 32-Bit Abi
Which Jdk's Distributions Can Run 'Javac -Source 1.6 -Target 1.5'
How to Download the Torvalds Linux Kernel Master, (Re)Compile It, and Boot It with Qemu
Strange File Permission in Docker Container (Question Marks on Permission Bit and User Bit)