实现双机通信的C语言代码

来源:百度知道 编辑:UC知道 时间:2024/06/16 17:51:41
求可以实现双机通信的C语言代码,只要两台机能PING通就行
用于上课实验,不用太正规太复杂,只要能用就行

代码要求是什么? 基本实现 ping 的功能?

ping 代码

#include <windows.h>
#include <winsock2.h>

#define IP_RECORD_ROUTE 0x7

#define ICMP_ECHO 8
#define ICMP_ECHOREPLY 0
#define ICMP_MIN 8 // minimum 8 byte icmp packet (just header)

#define DEF_PACKET_SIZE 32 // Default packet size
#define MAX_PACKET 60000 // Max ICMP packet size 1024
#define MAX_IP_HDR_SIZE 60 // Max IP header size w/options

typedef struct _iphdr
{
unsigned int h_len:4; // Length of the header
unsigned int version:4; // Version of IP
unsigned char tos; // Type of service
unsigned short total_len; // Total length of the packet
unsigned short ident; // Unique identifier
unsigned short frag_and_flags; // Flags
unsigned char ttl; // Time to live
unsigned char proto; // Protocol (TCP, UDP etc)
unsigned short checksum; // IP checksum

unsigned int sourceIP;