Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
636 views
in Technique[技术] by (71.8m points)

linux - what is RAW socket in socket programming

When I gone through socket programming I could not clearly understand RAW_SOCKET.

My understanding is

If I open a socket with this option AF_INET , RAW_SOCKET mean's I can create my own header before AF_INET headers but finally the data is send in the format of AF_INET protocol. Is my understanding is correct . If wrong can some explain me.

ThankYou

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

In every layer,packet has two disjoint sections: Header, Payload

non-Raw socket means you can just determine Transport Layer Payload. i.e it is OS task to create Transport,Network and Data Link layer headers.

Raw socket means you can determine every section of packet,either header or payload. Please note that raw socket is a general word. I categorize raw socket into: Network Socket andd Data-Link Socket (or alternativly L3 Socket and L2 Socket)

In L3 Socket you can determine header and payload of packet in network layer. For example if network layer protocol is IPv4, you can determine IPv4 header and payload. Thus you can set transport layer header/payload, ICMP header/payload, Routing Protocols headder/payload.

In L2 Socket you can set header and payload of packet in data link layer, i.e everything in packet. Thus you do everything done with L3 Socket + determine ARP header/payload, PPP header/payload, PPPOE header/payload , .... .

Now in programming:

  • socket(AF_INET,RAW_SOCKET,...) means L3 socket , Network Layer Protocol = IPv4
  • socket(AF_IPX,RAW_SOCKET,...) means L3 socket , Network Layer Protocol = IPX
  • socket(AF_INET6,RAW_SOCKET,...) means L3 socket , Network Layer Protocol=IPv6
  • socket(AF_PACKET,RAW_SOCKET,...) means L2 socket , Data-link Layer Protocol= Ethernet

Third parameter specify payload protocol.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...