commit 6cf0df226aab47a9538e78fc71fb1ff06d242167
parent a19c77c0db292bf24a7e711f33b85ccbadd0b40b
Author: cnlohr <lohr85@gmail.com>
Date: Mon, 23 Sep 2019 01:08:44 -0400
Merge branch 'master' of https://github.com/cnlohr/cnping
Diffstat:
14 files changed, 42 insertions(+), 17 deletions(-)
diff --git a/Makefile b/Makefile
@@ -10,21 +10,20 @@ LDFLAGS:=-s -L/opt/X11/lib/
#MINGW32:=/usr/bin/i686-w64-mingw32-
MINGW32:=i686-w64-mingw32-
-
#If you don't need admin priveleges
ADMINFLAGS:= $(ADMINFLAGS) -DWIN_USE_NO_ADMIN_PING
-cnping.exe : cnping.c CNFGFunctions.c CNFGWinDriver.c os_generic.c ping.c httping.c
- $(MINGW32)windres resources.rc -o resources.o $(ADMINFLAGS)
- $(MINGW32)gcc -g -fno-ident -mwindows -m32 $(CFLAGS) -o $@ $^ -lgdi32 -lws2_32 -D_WIN32_WINNT=0x0600 -DWIN32 -liphlpapi -DMINGW_BUILD resources.o $(ADMINFLAGS)
+cnping.exe : cnping.c rawdraw/CNFGFunctions.c rawdraw/CNFGWinDriver.c rawdraw/os_generic.c ping.c httping.c
+ $(MINGW32)windres resources.rc -o resources.o
+ $(MINGW32)gcc -g -fno-ident -mwindows -m32 $(CFLAGS) resources.o -o $@ $^ -lgdi32 -lws2_32 -s -D_WIN32_WINNT=0x0600 -DWIN32 -liphlpapi -DMINGW_BUILD $(ADMINFLAGS)
-cnping : cnping.o CNFGFunctions.o CNFGXDriver.o os_generic.o ping.o httping.o
+cnping : cnping.o rawdraw/CNFGFunctions.o rawdraw/CNFGXDriver.o rawdraw/os_generic.o ping.o httping.o
gcc $(CFLAGS) -o $@ $^ -lX11 -lm -lpthread $(LDFLAGS)
-cnping_mac : cnping.c CNFGFunctions.c CNFGCocoaCGDriver.m os_generic.c ping.c httping.o
+cnping_mac : cnping.c rawdraw/CNFGFunctions.c rawdraw/CNFGCocoaCGDriver.m rawdraw/os_generic.c ping.c httping.o
gcc -o cnping $^ -x objective-c -framework Cocoa -framework QuartzCore -lm -lpthread
-searchnet : os_generic.o ping.o searchnet.o
+searchnet : rawdraw/os_generic.o ping.o searchnet.o
gcc $(CFLAGS) -o $@ $^ -lpthread
linuxinstall : cnping
@@ -36,4 +35,4 @@ linuxinstall : cnping
clean :
rm -rf *.o *~ cnping cnping.exe cnping_mac searchnet
-
+ rm -rf rawdraw/*.o
diff --git a/cnping.c b/cnping.c
@@ -11,6 +11,10 @@
#endif
#include <windows.h>
#else
+ #ifdef __FreeBSD__
+ #include <sys/types.h>
+ #include <netinet/in.h>
+ #endif
#include <sys/socket.h>
#include <netinet/ip.h>
#include <netinet/ip_icmp.h>
@@ -18,8 +22,8 @@
#include <sys/select.h>
#include <netdb.h>
#endif
-#include "CNFGFunctions.h"
-#include "os_generic.h"
+#include "rawdraw/CNFGFunctions.h"
+#include "rawdraw/os_generic.h"
#include "ping.h"
#include "error_handling.h"
#include "httping.h"
@@ -621,6 +625,8 @@ int main( int argc, const char ** argv )
ShowWindow (GetConsoleWindow(), SW_HIDE);
#endif
+ srand( (uintmax_t)(OGGetAbsoluteTime()*100000) );
+
for( i = 0; i < sizeof( pattern ); i++ )
{
pattern[i] = rand();
diff --git a/cnping.exe b/cnping.exe
Binary files differ.
diff --git a/httping.c b/httping.c
@@ -22,7 +22,7 @@
#include <netdb.h>
#endif
-#include "os_generic.h"
+#include "rawdraw/os_generic.h"
#include "error_handling.h"
#ifndef MSG_NOSIGNAL
diff --git a/ping.c b/ping.c
@@ -9,7 +9,7 @@
#include <stdio.h>
#include <stdlib.h>
#include "ping.h"
-#include "os_generic.h"
+#include "rawdraw/os_generic.h"
#include "error_handling.h"
#ifdef TCC
@@ -149,7 +149,6 @@ void ping(struct sockaddr_in *addr )
//The normal way to do it - only problem is Windows needs admin privs.
-
#ifdef WIN32
#include <winsock2.h>
#define SOL_IP 0
@@ -165,11 +164,14 @@ void ping(struct sockaddr_in *addr )
#include <ws2tcpip.h>
#include <stdint.h>
#else
+ #ifdef __FreeBSD__
+ #include <netinet/in.h>
+ #endif
#include <unistd.h>
#include <sys/socket.h>
#include <resolv.h>
#include <netdb.h>
- #ifdef __APPLE__
+ #if defined(__APPLE__) || defined(__FreeBSD__)
#ifndef SOL_IP
#define SOL_IP IPPROTO_IP
#endif
@@ -205,8 +207,13 @@ struct icmphdr
struct packet
{
+#ifdef __FreeBSD__
+ struct icmp hdr;
+ unsigned char msg[PACKETSIZE-sizeof(struct icmp)];
+#else
struct icmphdr hdr;
unsigned char msg[PACKETSIZE-sizeof(struct icmphdr)];
+#endif
};
int sd;
@@ -265,8 +272,14 @@ void listener()
if( buf[9] != 1 ) continue; //ICMP
if( addr.sin_addr.s_addr != psaddr.sin_addr.s_addr ) continue;
+ // sizeof(packet.hdr) + 20
+#ifdef __FreeBSD__
+ int offset = 48;
+#else
+ int offset = 28;
+#endif
if ( bytes > 0 )
- display(buf + 28, bytes - 28 );
+ display(buf + offset, bytes - offset );
else
{
ERRM("Error: recvfrom failed");
@@ -301,12 +314,19 @@ void ping(struct sockaddr_in *addr )
{
int rsize = load_ping_packet( pckt.msg, sizeof( pckt.msg ) );
memset( &pckt.hdr, 0, sizeof( pckt.hdr ) ); //This needs to be here, but I don't know why, since I think the struct is fully populated.
-
+#ifdef __FreeBSD__
+ pckt.hdr.icmp_code = 0;
+ pckt.hdr.icmp_type = ICMP_ECHO;
+ pckt.hdr.icmp_id = pid;
+ pckt.hdr.icmp_seq = cnt++;
+ pckt.hdr.icmp_cksum = checksum((const unsigned char *)&pckt, sizeof( pckt.hdr ) + rsize );
+#else
pckt.hdr.code = 0;
pckt.hdr.type = ICMP_ECHO;
pckt.hdr.un.echo.id = pid;
pckt.hdr.un.echo.sequence = cnt++;
pckt.hdr.checksum = checksum((const unsigned char *)&pckt, sizeof( pckt.hdr ) + rsize );
+#endif
int sr = sendto(sd, (char*)&pckt, sizeof( pckt.hdr ) + rsize , 0, (struct sockaddr*)addr, sizeof(*addr));
diff --git a/CNFGCocoaCGDriver.m b/rawdraw/CNFGCocoaCGDriver.m
diff --git a/CNFGFunctions.c b/rawdraw/CNFGFunctions.c
diff --git a/CNFGFunctions.h b/rawdraw/CNFGFunctions.h
diff --git a/CNFGRasterizer.h b/rawdraw/CNFGRasterizer.h
diff --git a/CNFGWinDriver.c b/rawdraw/CNFGWinDriver.c
diff --git a/CNFGXDriver.c b/rawdraw/CNFGXDriver.c
diff --git a/os_generic.c b/rawdraw/os_generic.c
diff --git a/os_generic.h b/rawdraw/os_generic.h
diff --git a/searchnet.c b/searchnet.c
@@ -5,7 +5,7 @@
#include <arpa/inet.h>
#include <stdint.h>
#include <stdlib.h>
-#include "os_generic.h"
+#include "rawdraw/os_generic.h"
uint32_t my_random_key;
uint8_t send_id[4];