如何用C语言函数指针实现C语言弹性编码,TCP/IP协议中的经典例子
来源:互联网 发布:h5页面制作工具 知乎 编辑:程序博客网 时间:2024/06/04 21:09
The first define a protocolstructure and it can cover TCP, UDP and RAWIP protocol
struct inet_protosw {
struct list_head list;
unsigned short type;
int protocol;
struct proto *prot;
const struct proto_ops --*ops;
int capability;
char no_check;
unsignedchar flags;
};
The second, define a protocolarray to store different protocol
/usr/src/linux/net/ipv4/af_inet.c
static struct inet_protosw inetsw_array[] =
{
{
.type = SOCK_STREAM,
.protocol = IPPROTO_TCP,
.prot =&tcp_prot, //与协议类型相关的操作集
.ops =&inet_stream_ops, //与服务类型相关的操作集
.capability = -1,
.no_check = 0,
.flags = INET_PROTOSW_PERMANENT |INET_PROTOSW_ICSK,
},
{
.type = SOCK_DGRAM,
.protocol = IPPROTO_UDP,
.prot = &udp_prot,
.ops = &inet_dgram_ops,
.capability = -1,
.no_check = UDP_CSUM_DEFAULT,
.flags = INET_PROTOSW_PERMANENT,
},
{
.type = SOCK_RAW,
.protocol = IPPROTO_IP, /* wild card */
.prot = &raw_prot,
.ops = &inet_sockraw_ops,
.capability = CAP_NET_RAW,
.no_check = UDP_CSUM_DEFAULT,
.flags = INET_PROTOSW_REUSE,
}
};
The third, when we specify a protocol tocommunicate, we can chose right protocol in this array, and use this interfacedin socket layer.
In testmac system, we also do it same, wedefine a structure to store different function between 9131 and 8157, before weinit system, we run command
Cat /proc/cpuinfo, get platform information
root@bsc913x:~# cat /proc/cpuinfo
processor :0
cpu : e500v2
clock : 1000.000000MHz
revision : 5.1 (pvr 8021 2251)
bogomips : 125.00
timebase : 62500000
platform : BSC9131 RDB
model : fsl,bsc9131rdb
Memory : 880 MB
And init those function in structure, use thisstructure in below code.
- 如何用C语言函数指针实现C语言弹性编码,TCP/IP协议中的经典例子
- 如何用C语言实现类似C++中的多态
- 如何用c语言实现多态
- 如何用C语言实现面向对象
- 如何用C语言实现三子棋游戏
- Socket tcp/ip 例子 C语言 LINUX
- C语言如何用OpenGL
- C语言如何用OpenGL
- c语言 如何用指针来处理字符串?
- C语言中如何用指针变量指向多维数组
- c语言中的函数指针
- C语言中的函数指针
- C语言中的函数指针
- C语言中的函数指针
- C语言中的函数指针
- C语言中的函数指针
- c语言中的函数指针
- C语言中的函数指针
- [开心学php100天]第三天:不羁的PHP文件操作
- C++笔试题
- 堆和栈的区别,顺便介绍一下:全局区(静态区)、文字常量区、程序代码区
- DWZ ajax提交表单后重定向整个页面
- android4.2上获取应用程序大小的变更点
- 如何用C语言函数指针实现C语言弹性编码,TCP/IP协议中的经典例子
- [开心学php100天]第四天:完爆php魔力函数
- poj 1118
- gdb调试加参数的程序
- HTML页面跳转的方法总汇
- 电机控制PWM(MCPWM)
- 电路设计中的八大误区
- rst2pdf处理中文文档
- ERR_PTR,PTR_ERR还有IS_ERR函数详解