zoukankan      html  css  js  c++  java
  • IPV4 IPV6 数据成员

    typedef uint16_t in_port_t;
    
    // Internet address. --- IPV4
    typedef uint32_t in_addr_t;
    struct in_addr{
         in_addr_t s_addr;
    };
    
    
    
    // IPv6 address
    struct in6_addr
    {
    	union
    	{   
    		uint8_t __u6_addr8[16];
    	} __in6_u;
    };  
    
    
    // Structure describing an Internet socket address   --- IPV4
    struct sockaddr_in
    {
    	__SOCKADDR_COMMON (sin_);
    	in_port_t sin_port;         /* Port number.  */
    	struct in_addr sin_addr;        /* Internet address.  */
    
    	/* Pad to size of `struct sockaddr'.  */
    	unsigned char sin_zero[sizeof (struct sockaddr) -
    		__SOCKADDR_COMMON_SIZE -
    		sizeof (in_port_t) -
    		sizeof (struct in_addr)];
    };
    
    
    /* Ditto, for IPv6.  */
    struct sockaddr_in6
    {
    	__SOCKADDR_COMMON (sin6_);
    	in_port_t sin6_port;    /* Transport layer port # */
    	uint32_t sin6_flowinfo; /* IPv6 flow information */
    	struct in6_addr sin6_addr;  /* IPv6 address */
    	uint32_t sin6_scope_id; /* IPv6 scope-id */
    };
    
    struct in_addr 仅一个成员, s_addr (uint32_t)
    struct in6_addr 仅一个成员 __u6_addr ( uint8_t [16])
    
    IPV4: socket_in 共4个成员:
    	unsignedshort	sin_family	--> 协议族类型
    	uint16_t  sin_port 		--> 端口号
    	struct in_addr     sin_addr     --> ip地址
    	unsigned   char sin_zero        --> 
    IPV6: socket_in6 共4个成员:
    	uint16_t sin6_port;   		/* Transport layer port # */
    	uint32_t sin6_flowinfo; 	/* IPv6 flow information */
    	struct in6_addr sin6_addr;	/* IPv6 address */
    	uint32_t sin6_scope_id; 	/* IPv6 scope-id */
    
    struct sockaddr{
      unsignedshort sa_family; /* address family */ 
      char sa_data[14]; /* up to 14 bytes of direct address */
    };
    

      

  • 相关阅读:
    转载:Python十分钟入门
    Think Python: How to Think Like a Computer Scientist
    LeetCode(34):搜索范围
    LeetCode(33):搜索旋转排序数组
    LeetCode(32):最长有效括号
    LeetCode(31): 下一个排列
    LeetCode(30):与所有单词相关联的字串
    LeetCode(29): 两数相除
    LeetCode(28): 实现strStr()
    LeetCode(27): 移除元素
  • 原文地址:https://www.cnblogs.com/mathzzz/p/2669832.html
Copyright © 2011-2022 走看看