cnping

Minimal Graphical Ping Tool
git clone https://git.sinitax.com/cnlohr/cnping
Log | Files | Refs | Submodules | README | LICENSE | sfeed.txt

commit 3500ed792e0d266d9ef55bba52287746725be65e
parent 7b505848408df6a0d4400d3aaf86cf17b65df305
Author: mrbesen <y.g.2@gmx.de>
Date:   Sun, 11 Sep 2022 18:21:37 +0200

add resolve.c to makefile; fix compile on windows

Diffstat:
MMakefile | 10+++++-----
Mhttping.c | 2+-
Mping.c | 19++++++++++++++++---
Mping.h | 3+--
Mresolve.c | 2+-
Mresolve.h | 1+
6 files changed, 25 insertions(+), 12 deletions(-)

diff --git a/Makefile b/Makefile @@ -23,7 +23,7 @@ ADMINFLAGS:= $(ADMINFLAGS) -DWIN_USE_NO_ADMIN_PING cnping-wingdi.exe : cnping.c ping.c httping.c resources.o $(MINGW32)gcc -g -fno-ident -mwindows -m32 $(CFLAGS) -o $@ $^ -lgdi32 -lws2_32 -s -D_WIN32_WINNT=0x0600 -DWIN32 -liphlpapi -DMINGW_BUILD $(ADMINFLAGS) -cnping.exe : cnping.c ping.c httping.c resources.o +cnping.exe : cnping.c ping.c httping.c resolve.c resources.o $(MINGW32)gcc -g -fno-ident -mwindows -m32 -DCNFGOGL $(CFLAGS) -o $@ $^ -lgdi32 -lws2_32 -s -D_WIN32_WINNT=0x0600 -DWIN32 -liphlpapi -lopengl32 -DMINGW_BUILD $(ADMINFLAGS) resources.o : resources.rc @@ -32,13 +32,13 @@ resources.o : resources.rc # Unix -cnping : cnping.c ping.c httping.c +cnping : cnping.c ping.c httping.c resolve.c $(CC) $(CFLAGS) -o $@ $^ -lX11 -lm -lpthread -lGL $(LDFLAGS) -cnping_ogl : cnping.c ping.c httping.c - $(CC) $(CFLAGS) -o $@ $^ -DCNFGOGL $(CFLAGS) -s -lX11 -lm -lpthread $(LDFLAGS) -lGL +cnping_ogl : cnping.c ping.c httping.c resolve.c + $(CC) $(CFLAGS) -o $@ $^ -DCNFGOGL $(CFLAGS) -lX11 -lm -lpthread $(LDFLAGS) -lGL -cnping_mac : cnping.c ping.c httping.c +cnping_mac : cnping.c ping.c httping.c resolve.c $(CC) -o cnping $^ -x objective-c -framework Cocoa -framework QuartzCore -lm -lpthread -DOSX searchnet : ping.o searchnet.o diff --git a/httping.c b/httping.c @@ -16,7 +16,7 @@ #if defined( WIN32 ) || defined( WINDOWS ) #ifdef TCC #else - #include <winsock2.h> + #include <ws2tcpip.h> #endif #else #include <sys/socket.h> diff --git a/ping.c b/ping.c @@ -50,8 +50,11 @@ socklen_t psaddr_len; static og_sema_t s_disp; static og_sema_t s_ping; -void ping_setup(const char * device) +void ping_setup(const char * strhost, const char * device) { + // resolve host + psaddr_len = sizeof(psaddr); + resolveName((struct sockaddr*) &psaddr, &psaddr_len, strhost); s_disp = OGCreateSema(); s_ping = OGCreateSema(); @@ -93,7 +96,7 @@ static void * pingerthread( void * v ) } repl; DWORD res = IcmpSendEcho( ih, - psaddr.sin_addr.s_addr, ping_payload, rl, + ((struct sockaddr_in*) &psaddr)->sin_addr.s_addr, ping_payload, rl, 0, &repl, sizeof( repl ), timeout_ms ); int err; @@ -120,9 +123,19 @@ static void * pingerthread( void * v ) return 0; } -void ping(struct sockaddr_in *addr ) +void ping(struct sockaddr *addr, socklen_t addr_len ) { int i; + (void) addr; + (void) addr_len; + + if( psaddr.sin6_family != AF_INET ) + { + // ipv6 ICMP Ping is not supported on windows + ERRM( "ERROR: ipv6 ICMP Ping is not supported on windows\n" ); + return; + } + //Launch pinger threads for( i = 0; i < PINGTHREADS; i++ ) { diff --git a/ping.h b/ping.h @@ -4,12 +4,11 @@ #include <stdint.h> #ifdef WIN32 typedef int socklen_t; + struct sockaddr; #else #include <sys/socket.h> #endif -struct sockaddr_in; - unsigned short checksum(const unsigned char *b, uint16_t len); //Callback (when received) diff --git a/resolve.c b/resolve.c @@ -6,7 +6,7 @@ #include "error_handling.h" #ifdef WIN32 - + #include <ws2tcpip.h> #else // !WIN32 #include <arpa/inet.h> // inet_pton (parsing ipv4 and ipv6 notation) diff --git a/resolve.h b/resolve.h @@ -3,6 +3,7 @@ #ifdef WIN32 typedef int socklen_t; + struct sockaddr; #else #include <sys/socket.h> #endif