tcp/ip通信中tcp头部结构tcphdrp->check校验计算
通过raw socket修改通信数据后,可通过函数
set_tcp_checksum1(iph);
重新校验计算iph->check值
在http://www.cnblogs.com/dpf-10/p/7899237.html查看实际应用
static u_int16_t checksum(u_int32_t init, u_int8_t *addr, size_t count){
    /* Compute Internet Checksum for "count" bytes * beginning at location "addr". */
    u_int32_t sum = init; 
    while( count >  ) {
        /* This is the inner loop */
        sum += ntohs(* (u_int16_t*) addr);
        addr += ;
        count -= ;
    } /* Add left-over byte, if any */
    if( count >  )
        sum += ntohs(* (u_int8_t*) addr); /* Fold 32-bit sum to 16 bits */
    while (sum>>)
    sum = (sum & 0xffff) + (sum >> );
    return (u_int16_t)~sum;
}
static u_int16_t tcp_checksum2(struct iphdr* iphdrp, struct tcphdr* tcphdrp){
    size_t tcplen = ntohs(iphdrp->tot_len) - (iphdrp->ihl<<);
    u_int32_t cksum = ;
    cksum += ntohs((iphdrp->saddr >> ) & 0x0000ffff);
    cksum += ntohs(iphdrp->saddr & 0x0000ffff);
    cksum += ntohs((iphdrp->daddr >> ) & 0x0000ffff);
    cksum += ntohs(iphdrp->daddr & 0x0000ffff);
    cksum += iphdrp->protocol & 0x00ff;
    cksum += tcplen;
    return checksum(cksum, (u_int8_t*)tcphdrp, tcplen);
} 
static u_int16_t tcp_checksum1(struct iphdr* iphdrp){
    struct tcphdr *tcphdrp = (struct tcphdr*)((u_int8_t*)iphdrp + (iphdrp->ihl<<));
    return tcp_checksum2(iphdrp, tcphdrp);
}
static void set_tcp_checksum2(struct iphdr* iphdrp, struct tcphdr* tcphdrp){
    tcphdrp->check = ;
    tcphdrp->check = htons(tcp_checksum2(iphdrp, tcphdrp));
}
static void set_tcp_checksum1(struct iphdr* iphdrp){
    struct tcphdr *tcphdrp = (struct tcphdr*)((u_int8_t*)iphdrp + (iphdrp->ihl<<));
    set_tcp_checksum2(iphdrp, tcphdrp);
}
tcp/ip通信中tcp头部结构tcphdrp->check校验计算的更多相关文章
- tcp/ip通信中udp头部结构udphdrp->check校验计算
		通过raw socket修改通信数据后,可通过函数 set_udp_checksum1 重新校验计算iph->check值 在http://www.cnblogs.com/dpf-10/p/78 ... 
- 【转】TCP/IP协议中TCP和UDP的区别
		TCP协议与UDP协议的区别 首先咱们弄清楚,TCP协议和UCP协议与TCP/IP协议的联系,很多人犯糊涂了,一直都是说TCP/IP协议与UDP协议的区别,我觉得这是没有从本质上弄清楚网络通信! ... 
- tcp/ip通信中ip头部结构iph->check校验计算
		通过raw socket修改通信数据后,可通过该函数重新校验计算iph->check值 在http://www.cnblogs.com/dpf-10/p/7899237.html查看实际调用 s ... 
- [转]使用wireshark分析TCP/IP协议中TCP包头的格式
		本文简单介绍了TCP面向连接理论知识,详细讲述了TCP报文各个字段含义,并从Wireshark俘获分组中选取TCP连接建立相关报文段进行分析. 一.概述 TCP是面向连接的可靠传输协议,两个进程互发数 ... 
- linux OSI七层模型、TCP/IP协议栈及每层结构大揭秘
		学习Linux,就算是像小编我这样的小萌新,也知道OSI模型.什么?!你不知道!!! 好吧,这篇秘籍拿走,不谢~~~ 一.两个协议 (1)OSI 协议模型(7层)国际协议 PDU:协议数据单元对 ... 
- 第4章 TCP/IP通信案例:访问Internet上的Web服务器
		第4章 TCP/IP通信案例:访问Internet上的Web服务器 4.2 部署代理服务器 书中为了演示访问Internet上的Web服务器的全过程,使用了squid代理服务器程序模拟了一个代理服务器 ... 
- tcp/ip通信第5期之服务器端程序
		/* 此程序是tcp/ip通信服务器端程序,测试运行在redhat5上 重构readline函数,解决粘包问题——利用“\n”识别一个消息边界 */ #include<stdio.h> # ... 
- tcp/ip通信第5期之客户机端程序
		/*此程序是tcp/ip通信的客户机端程序, 测试运行在redhat6系统上 重构readline函数,解决粘包问题——利用“\n”识别一个消息边界 */ #include<stdio.h> ... 
- TCP之三:TCP/IP协议中backlog参数(队列参数)
		目录: <TCP洪水攻击(SYN Flood)的诊断和处理> <TCP/IP协议中backlog参数> TCP建立连接是要进行三次握手,但是否完成三次握手后,服务器就处理(ac ... 
随机推荐
- hdu 4968 最大最小gpa
			http://acm.hdu.edu.cn/showproblem.php?pid=4968 给定平均分和科目数量,要求保证及格的前提下,求平均绩点的最大值和最小值. dp[i][j]表示i个科目,总 ... 
- java 图片压缩 缩放
			废话不多说,直接上代码,静态方法可直接调用,中间用流来处理的 /** * 图片缩放(未考虑多种图片格式和等比例缩放) * @param filePath 图片路径 * @param height 高度 ... 
- gcc 6.0编译opencv出错
			在编译opencv3.2时候,出现下面错误: cmake -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=/usr/local -DBUILD_NE ... 
- ASP .Net C# ---Excel导入导出方法
			导入导出的方法以及引用,可以自行创建一个帮助类 using System;using NPOI.SS.UserModel;using NPOI.XSSF.UserModel;using NPOI.HS ... 
- Speech Synthesis
			<Window x:Class="Synthesizer.MainWindow" xmlns="http://schemas.microsoft.com/winfx ... 
- Git-根据tag创建分支
			有时候需要根据tag创建分支. 现在主分支上有一个tag为vtest.1.0.FINAL,主分支的名字为master. 1.执行:git origin fetch 获得最新. 2.通过:git bra ... 
- Javascript如何避免连续调用中取到不存在的属性而导致报TypeError错?
			背景: 在最近的 NODEJS 项目中,涉及到数据库的查询,回调函数里返回了查询结果,我这样做处理然后返回给前端: return results.collect_coupon[0].count 但是这 ... 
- css 的 conic-gradient 学习
			偶然间在微信公众号奇舞周刊上看到了这篇文章<CSS Painting API>,算是对 conic-gradient的初次见面. 后来有空的时候,百度搜了一下,看了这篇文章<CSS神 ... 
- Java - 获取帮助信息
			在线开发文档 Java SE 8 Java SE 8 Developer Guides Java SE 8 API Specification Java API Specifications 离线开发 ... 
- Task异步编程,刨根到底
			1. 编译器到底对await做了什么 await 一个异步操作的时候,实际上编译器会创建一个状态机,这个状态机包含了调用者的上下文变量,状态机使用yield迭代器实现,状态机由clr调度,每次运行都会 ... 
