socket中的几个数据结构
sizeof 结构体(struct)和 联合体(union)的大小是不一样的
char short int long
#include <stdio.h>typedef unsigned char u_char ;
typedef unsigned short u_short;
typedef unsigned long u_long ;
typedef unsigned int u_int ;struct in_addr
{union {struct { u_char s_b1,s_b2,s_b3,s_b4; } S_un_b;struct { u_short s_w1,s_w2; } S_un_w;u_long S_addr;} S_un;
};struct sockaddr_in {short sin_family;u_short sin_port;struct in_addr sin_addr;char sin_zero[8];
};struct x1
{int a1;int b1;int c1;
};union x2
{int a1;int b1;int c1;
};
void main()
{printf("%d\n",sizeof(in_addr)); // 4printf("%d\n",sizeof(sockaddr_in)); // 16printf("%d\n",sizeof(x1)); // 12printf("%d\n\n",sizeof(x2)); // 4printf("%d\n",sizeof(char)); // 1printf("%d\n",sizeof(short)); // 2printf("%d\n",sizeof(int)); // 4printf("%d\n\n",sizeof(long)); // 4printf("%d\n",sizeof(u_char)); // 1printf("%d\n",sizeof(u_short)); // 2 printf("%d\n",sizeof(u_int)); // 4 printf("%d\n",sizeof(u_long)); // 4printf("%d\n",sizeof(float)); // 4printf("%d\n",sizeof(double)); // 8
}
socket中的几个数据结构相关推荐
- 简单分析一下socket中的bind
在最开始接触bind的时候,只是在写基于tcp的server端的时候,知道在listen之前需要先bind一下,用来确保socket能在某个固定的端口监听.而bind的时候,函数参数中的端口填自己将要 ...
- Java socket中关闭IO流后,发生什么事?(以关闭输出流为例)
为了方便讲解,我们把 DataOutputstream dout = new DataOutputStream(new BufferedOutputStream(mySocket.getOutputS ...
- PYTHON__关于Socket中的Select使用理解
关于Socket中的Select使用理解 以下是代码和中文注释的个人理解 import socket, select, Queueserver=('192.168.2.100',10086)#创建TC ...
- linux socket默认超时时间设置,Socket中如何设置连接超时 (转)
Socket中如何设置连接超时 (转) Socket中如何设置连接超时 AntGhazi/2001.12.14 主页:antghazi.yeah 把CSDN与中文翻了底朝天,也没找到如何设置socke ...
- python中的序列类型数据结构元素的切片操作_浅析python中的分片与截断序列
浅析python中的分片与截断序列 序列概念 在分片规则里list.tuple.str(字符串)都可以称为序列,都可以按规则进行切片操作 切片操作 注意切片的下标0代表顺序的第一个元素,-1代表倒序的 ...
- Socket中如何设置连接超时
Socket中如何设置连接超时 (antghazi发表于2003-3-16 9:28:38) 设置connect的超时很简单,CSDN上也有人提到过使用select,但却没有一个令人满意与完整的答案. ...
- 《R语言编程艺术》——1.4 R语言中一些重要的数据结构
1.4 R语言中一些重要的数据结构 R有多种数据结构.本节将简单介绍几种常用的数据结构,使读者在深入细节之前先对R语言有个大概的认识.这样,读者至少可以开始尝试一些很有意义的例子,即使这些例子背后更多 ...
- Socket中常见的几个转换函数(htonl,htons,ntohl,ntohs,inet_addr,inet_ntoa)
Socket中常见的几个转换函数(htonl,htons,ntohl,ntohs,inet_addr,inet_ntoa) htonl() htons() ntohl() ntohs()及inet_n ...
- socket中的TCP编程(调用免费聊天的机器人实现自动回复)
socket中的TCP编程(调用免费聊天的机器人实现自动回复) 在无聊时间复习了socket编程,写了这个简易代码!!注意要在联网状态下跑 1:服务器模块: import socket import ...
最新文章
- android layout analyze
- P2P最易遭受的DDoS***以及防御手段
- Android渲染机制和丢帧分析
- {HTML5}JQueryMobile页面跳转参数的传递解决方案
- 字符编码解码整合工具
- mac wmware 无网络_无线网络中常用的技术名词
- 微课--Python使用tkinter和SQLite编写通信录管理程序(21分钟)
- SwitchResX Mac屏幕分辨率调整工具
- ppt字体颜色如何修改
- 2022年G2电站锅炉司炉试题及在线模拟考试
- 电脑远程连接已停止工作 解决方案
- 模块化设计(程序流程图)
- 惠州龙门大米飘香 国稻种芯-中国水稻节:广东乡村振兴样板
- rtx3070ti显卡什么水平 rtx3070ti显卡什么级别 rtx3070ti显卡怎么样
- error pulling image configuration:XXX net/http: TLS handshake timeout
- flutter 返回桌面
- 如何更好使用markdown输出pdf
- 【研讨会现场】广州天嵌科技受邀参加2014年TI9月深圳研讨会
- lt;#37;= %、lt;#37; %、lt;#37;@ %、lt;#37;:%和lt;#37;# %的区别
- 红海厮杀的超融合 泽塔云竟用GPU云开辟一片蓝海