Ping测试程序示例(C/C++)

77 篇文章 15 订阅 ¥59.90 ¥99.00
这是一个使用C/C++编写的简单Ping测试程序示例,通过Socket编程和ICMP协议来模拟发送ICMP回显请求并接收回应,以检查与目标主机的连接性和延迟。程序涉及创建ICMP Socket,构造ICMP报文头,发送和接收Ping请求及回复。
摘要由CSDN通过智能技术生成

Ping测试程序示例(C/C++)

以下是一个简单的Ping测试程序的示例,它使用C/C++编写。该程序可以模拟发送ICMP回显请求(Ping请求)并接收回应(Ping回复),从而测试与目标主机的连接性和延迟。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/ip_icmp.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <sys/time.h>

#define PACKET_SIZE     64
#define MAX_WAIT_TIME   5
#define MAX_NO_PACKETS  3

struct packet
{
    struct icmphdr hdr;
    char msg[PACKET_SIZE - sizeof(struct icmphdr)];
};

int ping(const char
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值