zoukankan      html  css  js  c++  java
  • Socket Address Structures

    Socket Address Structures

    Most socket functions require a pointer to a socket address structure as an argument. Each supported protocol suite defines its own socket address structure. The names of these structures begin with sockaddr_ and end with a unique suffix for each protocol suite.

    IPv4 Socket Address Structure

    An IPv4 socket address structure, commonly called an "Internet socket address structure," is named sockaddr_in and is defined by including the <netinet/in.h> header. Figure 3.1 shows the POSIX definition.

    Figure 3.1 The Internet (IPv4) socket address structure: sockaddr_in.
    struct in_addr {
      in_addr_t   s_addr;           /* 32-bit IPv4 address */
                                    /* network byte ordered */
    };
    
    struct sockaddr_in {
      uint8_t         sin_len;      /* length of structure (16) */
      sa_family_t     sin_family;   /* AF_INET */
      in_port_t       sin_port;     /* 16-bit TCP or UDP port number */
                                    /* network byte ordered */
      struct in_addr  sin_addr;     /* 32-bit IPv4 address */
                                    /* network byte ordered */
      char            sin_zero[8];  /* unused */
    };

    There are several points we need to make about socket address structures in general using this example:

    • The length member, sin_len, was added with 4.3BSD-Reno, when support for the OSI protocols was added (Figure 1.15). Before this release, the first member was sin_family, which was historically an unsigned short. Not all vendors support a length field for socket address structures and the POSIX specification does not require this member. The datatype that we show, uint8_t, is typical, and POSIX-compliant systems provide datatypes of this form (Figure 3.2).

      Figure 3.2. Datatypes required by the POSIX specification.

      image

  • 相关阅读:
    安卓触摸事件探究
    android关于canvas,path,paint非常好的讲解
    android的Shader
    android中view的生命周期
    JAVA的Random类(转)
    lniux 64位导致adb无法运行解决方案
    [转]Android中attrs.xml文件的使用详解
    FlowLayout
    大数据平台架构技术选型与场景运用(转)
    mysql--java类型对应表
  • 原文地址:https://www.cnblogs.com/haimingwey/p/2474667.html
Copyright © 2011-2022 走看看