raw socket udp

这是《windows网络编程技术》上的一个范例程序,它就是构建自己的udp包,具体的你自 己看吧   // Module Name: Iphdrinc.c // // Description: //    This is a simple app that demonstrates the usage of the  //    IP_HDRINCL socket option. A raw so
摘要由CSDN通过智能技术生成
这是《windows网络编程技术》上的一个范例程序,它就是构建自己的udp包,具体的你自 
己看吧 
  
// Module Name: Iphdrinc.c 
// 
// Description: 
//    This is a simple app that demonstrates the usage of the  
//    IP_HDRINCL socket option. A raw socket is created of the 
//    UDP protocol where we will build our own IP and UDP header 
//    that we submit to sendto(). 
// 
// Compile: 
//    cl -o Iphdrinc Iphdrinc.c ws2_32.lib 
// 
// Command Line Parameters/Arguments: 
//    iphdrinc [-fp:int] [-fi:str] [-tp:int] [-ti:str] [-n:int]  
//             [-m:str] 
// 
//           -fp:int   From (sender) port number 
//           -fi:IP    From (sender) IP address 
//           -tp:int   To (recipient) port number 
//           -ti:IP    To (recipient) IP address 
//           -n:int    Number of times to send message 
//           -m:str    Message to send 
// 
#pragma pack(1) 
  
#define WIN32_LEAN_AND_MEAN  
  
#include <winsock2.h> 
#include <ws2tcpip.h> 
  
#include <stdio.h> 
#include <stdlib.h> 
  
#define MAX_MESSAGE        4068 
#define MAX_PACKET         4096 
// 
// Setup some default values  
// 
#define DEFAULT_PORT       5150 
#define DEFAULT_IP         "10.0.0.1" 
#define DEFAULT_COUNT      5 
#define DEFAULT_MESSAGE    "This is a test" 
  
// 
// Define the IP header. Make the version and length field one 
// character since we can't declare two 4 bit fields without 
// the compiler aligning them on at least a 1 byte boundary. 
// 
typedef struct ip_hdr 

     unsigned char  ip_verlen;        // IP version & length 
     unsigned char  ip_tos;           // IP type of service 
     unsigned short ip_totallength;   // Total length 
     unsigned short ip_id;            // Unique identifier  
     unsigned short ip_offset;        // Fragment offset field 
     unsigned char  ip_ttl;           // Time to live 
     unsigned char  ip_protocol;      // Protocol(TCP,UDP etc) 
     unsigned short ip_checksum;      // IP checksum 
     unsigned int   ip_srcaddr;       // Source address 
     unsigned int   ip_destaddr;      // Destination address 
} IP_HDR, *PIP_HDR, FAR* LPIP_HDR; 
// 
// Define the UDP header  
// 
typedef struct udp_hdr 

     unsigned short src_portno;       // Source port number 
     unsigned short dst_portno;       // Destination port number 
     unsigned short udp_length;       // UDP packet length 
     unsigned short udp_checksum;     // UDP checksum (optional) 
} UDP_HDR, *PUDP_HDR; 
  
// 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值