网络地址结构体解析
来源:互联网 发布:高级linux书籍 编辑:程序博客网 时间:2024/06/05 02:49
include <netinet/in.h>// All pointers to socket address structures are often cast to pointers// to this type before use in various functions and system calls:struct sockaddr { unsigned short sa_family; // address family, AF_xxx char sa_data[14]; // 14 bytes of protocol address};// IPv4 AF_INET sockets:struct sockaddr_in { short sin_family; // e.g. AF_INET, AF_INET6 unsigned short sin_port; // e.g. htons(3490) struct in_addr sin_addr; // see struct in_addr, below char sin_zero[8]; // zero this if you want to};struct in_addr { unsigned long s_addr; // load with inet_pton()};// IPv6 AF_INET6 sockets:struct sockaddr_in6 { u_int16_t sin6_family; // address family, AF_INET6 u_int16_t sin6_port; // port number, Network Byte Order u_int32_t sin6_flowinfo; // IPv6 flow information struct in6_addr sin6_addr; // IPv6 address u_int32_t sin6_scope_id; // Scope ID};struct in6_addr { unsigned char s6_addr[16]; // load with inet_pton()};// General socket address holding structure, big enough to hold either// struct sockaddr_in or struct sockaddr_in6 data:struct sockaddr_storage { sa_family_t ss_family; // address family // all this is padding, implementation specific, ignore it: char __ss_pad1[_SS_PAD1SIZE]; int64_t __ss_align; char __ss_pad2[_SS_PAD2SIZE];};
Description
These are the basic structures for all syscalls and functions that deal with internet addresses. Often you'll use getaddinfo() to fill these structures out, and then will read them when you have to.
In memory, the
Just kidding on that end-of-the-universe thing...if the universe does end when you cast a
So, with that in mind, remember that whenever a function says it takes a
There's also this
Now, that
Example // IPv4:struct sockaddr_in ip4addr;int s;ip4addr.sin_family = AF_INET;ip4addr.sin_port = htons(3490);inet_pton(AF_INET, "10.0.0.1", &ip4addr.sin_addr);s = socket(PF_INET, SOCK_STREAM, 0);bind(s, (struct sockaddr*)&ip4addr, sizeof ip4addr);// IPv6:struct sockaddr_in6 ip6addr;int s;ip6addr.sin6_family = AF_INET6;ip6addr.sin6_port = htons(4950);inet_pton(AF_INET6, "2001:db8:8714:3a90::12", &ip6addr.sin6_addr);s = socket(PF_INET6, SOCK_STREAM, 0);bind(s, (struct sockaddr*)&ip6addr, sizeof ip6addr);
- 网络地址结构体解析
- 域名和网络地址结构体---struct hostent
- linux中的网络地址结构记录
- 有关网络地址的解析图例
- 网络地址
- 网络地址
- 网络地址
- 网络地址
- AVI结构解析 结构体
- FIle_Operation结构体解析
- x264_t 结构体解析
- DEFUN结构体解析
- cpu_bitmap结构体解析
- cpu_anim结构体解析
- 解析 virDomainDef 结构体
- struct net_device结构体解析
- linux i2c_driver 结构体解析
- IplImage结构体数据解析
- C# post数据时 出现如下错误: System.Net.WebException: 远程服务器返回错误: (417) Expectation Failed 的解决办法
- poj 1189 钉子和小球 DP
- 利用javaScript动态增加表格行,删除表格行
- Microsoft Kinect SDK比较PrimeSense OpenNI
- gdb debug memory address
- 网络地址结构体解析
- Asp.net 网站发布到服务器后 访问报错:这是预编译工具生成的标记文件,不应删除!
- 什么是ActiveRecord
- 集群技术
- 加入jquery.validate.min.js,getJson 回调函数无法正常执行
- android的color值
- Java的一些常识
- C#预处理器指令
- 基于UDP协议的网络程序