Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

syncing the osx changes into the version of hping that antirez posted to github #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
616 changes: 616 additions & 0 deletions HpingForXcode.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "419AF87115707B5200400D11"
BuildableName = "Hping"
BlueprintName = "Hping"
ReferencedContainer = "container:HpingForXcode.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
<Testables>
</Testables>
</TestAction>
<LaunchAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
allowLocationSimulation = "YES">
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES">
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>Hping.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>419AF87115707B5200400D11</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>
92 changes: 92 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# $smu-mark$
# $name: Makefile.in$
# $author: Salvatore Sanfilippo 'antirez'$
# $copyright: Copyright (C) 1999 by Salvatore Sanfilippo$
# $license: This software is under GPL version 2 of license$
# $date: Sun Jul 25 17:56:15 MET DST 1999$
# $rev: 3$

CC= gcc
AR=/usr/bin/ar
RANLIB=/usr/bin/ranlib
CCOPT= -O2 -Wall -DUSE_TCL
DEBUG= -g
#uncomment the following if you need libpcap based build under linux
#(not raccomanded)
COMPILE_TIME=
INSTALL_MANPATH=/usr/local/man
PCAP=-lpcap

ARSOBJ = ars.o apd.o split.o rapd.o

OBJ= main.o getifname.o getlhs.o \
parseoptions.o datafiller.o \
datahandler.o gethostname.o \
binding.o getusec.o opensockraw.o \
logicmp.o waitpacket.o resolve.o \
sendip.o sendicmp.o sendudp.o \
sendtcp.o cksum.o statistics.o \
usage.o version.o antigetopt.o \
sockopt.o listen.o \
sendhcmp.o memstr.o rtt.o \
relid.o sendip_handler.o \
libpcap_stuff.o memlockall.o memunlockall.o \
memlock.o memunlock.o ip_opt_build.o \
display_ipopt.o sendrawip.o signal.o send.o \
strlcpy.o arsglue.o random.o scan.o \
hstring.o script.o interface.o \
adbuf.o hex.o apdutils.o sbignum.o \
sbignum-tables.o $(ARSOBJ)

all: .depend hping3

dep: .depend
.depend:
@echo Making dependences
@$(CC) -MM *.c > .depend

libars.a: $(ARSOBJ)
$(AR) rc $@ $^
$(RANLIB) $@

hping3: byteorder.h $(OBJ)
$(CC) -o hping3 $(CCOPT) $(DEBUG) $(OBJ) -L/usr/local/lib $(PCAP) -ltcl -lm -lpthread
@echo
./hping3 -v
@echo "use \`make strip' to strip hping3 binary"
@echo "use \`make install' to install hping3"

hping3-static: byteorder.h $(OBJ)
$(CC) -static -o hping3-static $(CCOPT) $(DEBUG) $(OBJ) -L/usr/local/lib $(PCAP) -ltcl -lm -lpthread -ldl

byteorder.h:
./configure

.c.o:
$(CC) -c $(CCOPT) $(DEBUG) $(COMPILE_TIME) $<

clean:
rm -rf hping3 *.o libars.a

distclean:
rm -rf hping3 *.o byteorder byteorder.h systype.h Makefile libars.a .depend

install: hping3
cp -f hping3 /usr/sbin/
chmod 755 /usr/sbin/hping3
ln -s /usr/sbin/hping3 /usr/sbin/hping
ln -s /usr/sbin/hping3 /usr/sbin/hping2
@if [ -d ${INSTALL_MANPATH}/man8 ]; then \
cp ./docs/hping3.8 ${INSTALL_MANPATH}/man8; \
chmod 644 ${INSTALL_MANPATH}/man8/hping3.8; \
else \
echo "@@@@@@ WARNING @@@@@@"; \
echo "Can't install the man page: ${INSTALL_MANPATH}/man8 does not exist"; \
fi

strip: hping3
@ls -l ./hping3
strip hping3
@ls -l ./hping3

include .depend
3 changes: 2 additions & 1 deletion adbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ int adbuf_addchar(struct adbuf *b, int c)
if (adbuf_ptr(b) == NULL)
return 1; /* bad buffer in input */
if (b->left >= 2) {
unsigned char *p = b->buf + adbuf_used(b);
//unsigned char *p = b->buf + adbuf_used(b); //pointer targets in initiation differ in signedness
unsigned char *p = (unsigned char *)b->buf + adbuf_used(b);

*p = c;
*(p+1) = '\0';
Expand Down
2 changes: 1 addition & 1 deletion ars.c
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ int ars_bsd_fix(struct ars_packet *pkt, unsigned char *packet, size_t size)
return -ARS_INVALID;
}
ip = (struct ars_iphdr*) packet;
#if defined OSTYPE_FREEBSD || defined OSTYPE_NETBSD || defined OSTYPE_BSDI
#if defined OSTYPE_DARWIN || OSTYPE_FREEBSD || defined OSTYPE_NETBSD || defined OSTYPE_BSDI
ip->tot_len = ntohs(ip->tot_len);
ip->frag_off = ntohs(ip->frag_off);
#endif
Expand Down
3 changes: 2 additions & 1 deletion byteorder.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ int main(int argc, char **argv)
}

if (debug) {
printf("sizeof(unsigned int) = %d\n", sizeof(unsigned int));
//printf("sizeof(unsigned int) = %d\n", sizeof(unsigned int));
printf("sizeof(unsigned int) = %zu\n", sizeof(unsigned int));
printf("unsigned int test = 1;\n");
printf("in memory as: ");
for (j = 0; j < sizeof(unsigned int); j++)
Expand Down
8 changes: 8 additions & 0 deletions byteorder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef __BYTEORDER_H
#define __BYTEORDER_H

#ifndef __LITTLE_ENDIAN_BITFIELD
#define __LITTLE_ENDIAN_BITFIELD
#endif /* __LITTLE_ENDIAN_BITFIELD */

#endif /* __BYTEORDER_H */
2 changes: 1 addition & 1 deletion gentables.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void gen_rcset(int hdr)
if (!p || !i) {
printf("-1, ");
} else {
printf("%2d, ", p-cset);
printf("%2ld, ", p-cset);
}
if (!((i+1) % EFL))
printf("\n");
Expand Down
3 changes: 2 additions & 1 deletion getifname.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,8 @@ int get_output_if(struct sockaddr_in *dest, struct sockaddr_in *ifip)
}

len = sizeof(iface_out);
if (getsockname(sock_rt, (struct sockaddr *)&iface_out, &len) == -1 ) {
//if (getsockname(sock_rt, (struct sockaddr *)&iface_out, &len) == -1 ) { //Pointer targets in passing argument 3 of 'getsockname' differ in signedness
if (getsockname(sock_rt, (struct sockaddr *)&iface_out, (unsigned int*)&len) == -1 ) {
if (opt_debug)
perror("DEBUG: [get_output_if] getsockname");
close(sock_rt);
Expand Down
5 changes: 3 additions & 2 deletions libpcap_stuff.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
#include <string.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <pcap.h>
#include <net/bpf.h>
#include <pcap.h> //pcap.h *must* be included AFTER net/bpf.h

#include "globals.h"

Expand Down Expand Up @@ -51,7 +51,8 @@ int close_pcap()

int pcap_recv(char *packet, unsigned int size)
{
char *p = NULL;
//char *p = NULL; //if p is signed, then you will later be setting its contents to an unsigned value
unsigned char *p = NULL;
int pcapsize;

if (opt_debug)
Expand Down
5 changes: 3 additions & 2 deletions scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,9 @@ static void receiver(struct portinfo *pi, int childpid)
if ((iplen - iphdrlen) < sizeof(icmp)+sizeof(subip)+sizeof(subtcp))
continue;
/* time to copy headers in a safe place */
p = packet+linkhdr_size+iphdrlen;
memcpy(&icmp, p, sizeof(subtcp));
p = (unsigned char *) packet+linkhdr_size+iphdrlen;
//memcpy(&icmp, p, sizeof(subtcp)); //FIXME memcpy will always overflow destination buffer
memmove(&icmp, p, sizeof(&icmp));
p += sizeof(icmp);
memcpy(&subip, p, sizeof(ip));
p += sizeof(ip);
Expand Down
6 changes: 3 additions & 3 deletions script.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
#include <sched.h>

#include <sys/ioctl.h>
#include <pcap.h>
#include <net/bpf.h>
#include <net/bpf.h>
#include <pcap.h> //pcap.h *must* be included AFTER net/bpf.h for osx

#include "release.h"
#include "hping2.h"
Expand Down Expand Up @@ -262,7 +262,7 @@ static int HpingSendRawCmd(ClientData clientData, Tcl_Interp *interp,
#define APD_MAX_LEN (65536*2+4096)
char *GetPacketDescription(char *data, int len, int hexdata)
{
unsigned char *p = (char*)data;
unsigned char *p = (unsigned char*) data;
struct ars_packet pkt;
char *d = malloc(APD_MAX_LEN);
char *ret;
Expand Down
4 changes: 2 additions & 2 deletions sendip.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void send_ip (char* src, char *dst, char *data, unsigned int datalen,
ip->ihl = (IPHDR_SIZE + optlen + 3) >> 2;
ip->tos = ip_tos;

#if defined OSTYPE_FREEBSD || defined OSTYPE_NETBSD || defined OSTYPE_BSDI
#if defined OSTYPE_DARWIN || OSTYPE_FREEBSD || defined OSTYPE_NETBSD || defined OSTYPE_BSDI
/* FreeBSD */
/* NetBSD */
ip->tot_len = packetsize;
Expand All @@ -73,7 +73,7 @@ void send_ip (char* src, char *dst, char *data, unsigned int datalen,
htons((unsigned short) src_id);
}

#if defined OSTYPE_FREEBSD || defined OSTYPE_NETBSD | defined OSTYPE_BSDI
#if defined OSTYPE_DARWIN || OSTYPE_FREEBSD || defined OSTYPE_NETBSD | defined OSTYPE_BSDI
/* FreeBSD */
/* NetBSD */
ip->frag_off |= more_fragments;
Expand Down
6 changes: 6 additions & 0 deletions systype.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef __SYSTYPE_H
#define __SYSTYPE_H

#define OSTYPE_DARWIN

#endif /* SYSTYPE_H */