zoukankan      html  css  js  c++  java
  • linux 协议栈初始化(一)

    以下是协议栈初始化函数调用层次结构

    socket.c :BSD socket层,属于表示层,为应用层系统调用提供接口;

    af_inet.c :INET Socket层,属于会话层,屏蔽底层协议

    以下是sock_init()函数

    void sock_init(void)
    {
        int i;
    
        printk("Swansea University Computer Society NET3.019\n");
    
        /*
         *    Initialize all address (protocol) families. 
         */
         
        for (i = 0; i < NPROTO; ++i) pops[i] = NULL;
    
        /*
         *    Initialize the protocols module. 
         */
    
        proto_init();
    
    #ifdef CONFIG_NET
        /* 
         *    Initialize the DEV module. 
         */
    
        dev_init();
      
        /*
         *    And the bottom half handler 
         */
    
        bh_base[NET_BH].routine= net_bh;
        enable_bh(NET_BH);
    #endif  
    }
    for (i = 0; i < NPROTO; ++i) pops[i] = NULL;

    pops[]定义如下: 

    static struct proto_ops *pops[NPROTO];

    proto_ops结构体定义如下:

    struct proto_ops {
      int    family;
    
      int    (*create)    (struct socket *sock, int protocol);
      int    (*dup)        (struct socket *newsock, struct socket *oldsock);
      int    (*release)    (struct socket *sock, struct socket *peer);
      int    (*bind)        (struct socket *sock, struct sockaddr *umyaddr,
                 int sockaddr_len);
      int    (*connect)    (struct socket *sock, struct sockaddr *uservaddr,
                 int sockaddr_len, int flags);
      int    (*socketpair)    (struct socket *sock1, struct socket *sock2);
      int    (*accept)    (struct socket *sock, struct socket *newsock,
                 int flags);
      int    (*getname)    (struct socket *sock, struct sockaddr *uaddr,
                 int *usockaddr_len, int peer);
      int    (*read)        (struct socket *sock, char *ubuf, int size,
                 int nonblock);
      int    (*write)    (struct socket *sock, char *ubuf, int size,
                 int nonblock);
      int    (*select)    (struct socket *sock, int sel_type,
                 select_table *wait);
      int    (*ioctl)    (struct socket *sock, unsigned int cmd,
                 unsigned long arg);
      int    (*listen)    (struct socket *sock, int len);
      int    (*send)        (struct socket *sock, void *buff, int len, int nonblock,
                 unsigned flags);
      int    (*recv)        (struct socket *sock, void *buff, int len, int nonblock,
                 unsigned flags);
      int    (*sendto)    (struct socket *sock, void *buff, int len, int nonblock,
                 unsigned flags, struct sockaddr *, int addr_len);
      int    (*recvfrom)    (struct socket *sock, void *buff, int len, int nonblock,
                 unsigned flags, struct sockaddr *, int *addr_len);
      int    (*shutdown)    (struct socket *sock, int flags);
      int    (*setsockopt)    (struct socket *sock, int level, int optname,
                 char *optval, int optlen);
      int    (*getsockopt)    (struct socket *sock, int level, int optname,
                 char *optval, int *optlen);
      int    (*fcntl)    (struct socket *sock, unsigned int cmd,
                 unsigned long arg);    
    };
  • 相关阅读:
    poj2452
    bnuoj16491
    1326: The contest(并查集+分组背包)
    BNUOJ-1065或运算的简单解法
    递推、规律思维题总结
    uva10160(dfs+状态压缩)
    第七章 人工智能,7.1 基于深度强化学习与自适应在线学习的搜索和推荐算法研究(作者:灵培、霹雳、哲予)
    第六章 大数据,6.3 突破传统,4k大屏的沉浸式体验(作者: 彦川、小丛)
    第六章 大数据,6.2 双11背后的大规模数据处理(作者:惠岸 朋春 谦乐)
    第六章 大数据,6.1 双11数据大屏背后的实时计算处理(作者:藏六 黄晓锋 同杰)
  • 原文地址:https://www.cnblogs.com/wanzaixiaoxin/p/2664144.html
Copyright © 2011-2022 走看看