1. #include<sys/types.h>
    2. #include<sys/socket.h>
    3. int socket(int domain,int type,int protocol);

    作用:创建套接字
    参数:
    1.domain:
    AF_INET IPv4 Internet protocols
    AF_INET6 IPv6 Internet protocols
    AF_UNIX, AF_LOCAL Local communication
    AF_NETLINK Kernel user interface device
    AF_PACKET Low level packet interface
    2.type:
    SOCK_STREAM: 流式套接字 唯一对应于TCP
    SOCK_DGRAM: 数据报套接字,唯一对应着UDP
    SOCK_RAW: 原始套接字
    3.protocol:
    一般填0,原始套接字编程时需填充
    返回值:
    成功:文件描述符
    出错:-1

    image.png