资源简介
如何自己封装IP头用raw socket来实现ip报文的发送
代码片段和文件信息
//raw tcp packet crafter
#include “stdio.h“
#include “winsock2.h“
#include “ws2tcpip.h“ //IP_HDRINCL is here
#include “conio.h“
#pragma comment(lib“ws2_32.lib“) //winsock 2.2 library
typedef struct ip_hdr
{
unsigned char ip_header_len:4; // 4-bit header length (in 32-bit words) normally=5 (Means 20 Bytes may be 24 also)
unsigned char ip_version :4; // 4-bit IPv4 version
unsigned char ip_tos; // IP type of service
unsigned short ip_total_length; // Total length
unsigned short ip_id; // Unique identifier
unsigned char ip_frag_offset :5; // Fragment offset field
unsigned char ip_more_fragment :1;
unsigned char ip_dont_fragment :1;
unsigned char ip_reserved_zero :1;
unsigned char ip_frag_offset1; //fragment offset
unsigned char ip_ttl; // Time to live
unsigned char ip_protocol; // Protocol(TCPUDP etc)
unsigned short ip_checksum; // IP checksum
unsigned int ip_srcaddr; // Source address
unsigned int ip_destaddr; // Source address
} IPV4_HDR *PIPV4_HDR FAR * LPIPV4_HDR;
// TCP header
typedef struct tcp_header
{
unsigned short source_port; // source port
unsigned short dest_port; // destination port
unsigned int sequence; // sequence number - 32 bits
unsigned int acknowledge; // acknowledgement number - 32 bits
unsigned char ns :1; //Nonce Sum Flag Added in RFC 3540.
unsigned char reserved_part1:3; //according to rfc
unsigned char data_offset:4; /*The number of 32-bit words in the TCP header.
This indicates where the data begins.
The length of the TCP header is always a multiple
of 32 bits.*/
unsigned char fin :1; //Finish Flag
unsigned char syn :1; //Synchronise Flag
unsigned char rst :1; //Reset Flag
unsigned char psh :1; //Push Flag
unsigned char ack :1; //Acknowledgement Flag
unsigned char urg :1; //Urgent Flag
unsigned char ecn :1; //ECN-Echo Flag
unsigned char cwr :1; //Congestion Window Reduced Flag
////////////////////////////////
unsigned short window; // window
unsigned short checksum; // checksum
unsigned short urgent_pointer; // urgent pointer
} TCP_HDR *PTCP_HDR FAR * LPTCP_HDR TCPHeader TCP_HEADER;
int main()
{
char host[100]buf[1000]*data=NULLsource_ip[20]; //buf is the complete packet
SOCKET s;
int k=1;
IPV4_HDR *v4hdr=NULL;
TCP_HDR *tcphdr=NULL;
int payload=512 optval;
SOCKADDR_IN dest;
hostent *server;
//Initialise Winsock
WSADATA wsock;
printf(“\nInitialising Winsock...“);
if (WSAStartup(MAKEWORD(22)&wsock) != 0)
{
fprintf(stderr“WSAStartup() failed“);
exit(EXIT_FAILURE);
}
printf(“Initialised successfully.“);
////////////////////////////////////////////////
//Crea
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 5540 2007-01-03 16:15 main.cpp
文件 4282 2006-09-29 21:39 tcpraw.dsp
文件 537 2006-09-29 20:30 tcpraw.dsw
相关资源
- Socket多线程.rar
- WebSocket 测试工具自制
- tcp/ip sockets in c 源码
- Qt 网络通信源码
- 网络抢答系统CompetitionResponder(原创)
- 手机采集摄像头视频socket实时传播
- Wince下socket实现的HTTP类,支持POST和
- tcl入门教程(包括常用的socket多线程
- Detecting Near-Duplicates for Web Crawling
- socket服务端和客户端互相发送消息、
- delphi7 使用socket实现websocket
- SOCKET TCP 文件传输 客户端 服务器端
- WebSocketDemo
- 基于socket的聊天程序报告
- 使用coreldraw编制专题地图集
- WebSocket+Tomcat8实现-Web版即时聊天室
- springboot工程基于netty-socketio的 web推送
- websocket使用(spring mvc)
- qt TCP网络编程与聊天室的实现
- LoadRunner_Winsocket协议知识总结(修正版
- Socket网络编程进阶与实战慕课网课程
- 高性能的socket通讯服务器完成端口模
- Socket网络编程进阶与实战视频-百度云
- 用WindowsSocket实现局域网上的语音实时
- socket连接传送数据,控制家电led
- tcl socket 编程
- socket tcp 转发工具
- WSAAsyncSelect模型
- WebSocket Demo
- 亿图Edraw Max 8.4 mac中文版(已激活破解
评论
共有 条评论