IPV4 IPV6 数据成员
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | 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 */ }; |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步