创建socket时的协议参数的疑问~~~
SOCKET socket( int af, int type, int protocol );中, protocol参数是这个socket所用的协议.
我所理解这个参数的意思是: 你的数据是基于这个协议的( 比如:TCP,那么我发送的数据的TCP头不用你构造,接收到的数据也不包含TCP头,内核已经帮你去掉了).
但最近看到的程序与我的理解不同.比如这个从网上找到的ping程序:
sock = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
它用原始套接字,发送数据时不用自已写IP头,但要自已填ICMP头,当收到数据时,能收到IP头!当然也能收到ICMP头!
晕死,搞到我都弄不同白这个 protocol参数是搞什么的,MSDN也只有这句 "Protocol to be used with the socket that is specific to the indicated address family. "
请大牛指点~~~这个protocol的真正用意是什么~
[解决办法]
可以理解为语种(比如中文,英文,德文,法文)么?
报文协议相当于A语言。
流协议相当于B语言。
底层协议相当于C语言。
不同的语言用于不同的沟通。
socket的也是。
-
协议只是一个规定,遵循就好。
[解决办法]
The protocol specifies a particular protocol to be used with the socket. Normally only a single protocol exists to support a particular socket type within a given protocol family, in which case protocol can be specified as 0. However, it is possible that many protocols may exist, in which case a particular protocol must be specified in this manner. The protocol number to use is specific to the “communication domain” in which communication is to take place; see protocols(5). See getprotoent(3) on how to map protocol name strings to protocol numbers.