Code Monkey home page Code Monkey logo

ping-1's Introduction

+--------------+
 ping 程序说明 
+--------------+

ping 是常用的一个网络连通性检测的工具

ping 的原理是通过 ICMP 协议发送“回显请求报文”,并获取对方主机的应答,来判断网络连通状态

在 windows 和 linux 的命令行或控制台,都可以直接使用 ping 命令
但是在 C 语言中要使用 ping 却没有现成的库函数或者 API

本程序通过 C 语言实现了 ping 的功能,代码可以在 VC++, msys2 gcc, linux gcc 下编译通过


接口说明
--------

typedef void (*PFN_PING_CALLBACK)(void *cbctx, char *ip, int bytes, int ttl, int time, int seq);
回调函数,接收到对方主机的 ping 应答后会调用此回调函数

void* ping_init(int interval, int timeout, PFN_PING_CALLBACK callback, void *cbctx);
初始化并返回一个 context 指针(以下的接口都需要传入这个指针,不赘述)
interval 指定 ping 发送报文的周期,以 ms 为单位
timeout  指定一个超时,如果在这个超时时间内没有收到应答,ping_isok 将返回 0 表示跟对方主机断开
callback 和 cbctx 为回调函数指针和回调的 context

void ping_exit(void *ctx); // 反初始化

void ping_run(void *ctx, char *ip, int start);
执行 ping 操作,ip 为要 ping 的主机 ip 地址,start 为 1 表示开始,0 表示停止 ping

int ping_isok(void *ctx);
判断跟对方主机是否连通


[email protected]
2021-5-6





ping-1's People

Contributors

rockcarry avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.