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

Add FreeBSD support, as well as fix a few bugs found while compiling in FreeBSD #123

Merged
merged 4 commits into from
Oct 28, 2018
Merged
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
8 changes: 6 additions & 2 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ TO INSTALL
7. Add page toolkit.html to browser favorites.

Note: 'make' is assumed to be the GNU make command (often available
under the name 'gmake').
under the name 'gmake'). Also, gcc is assumed to be the system
default compiler. On BSD systems, this may be clang. If so,
replace 'gcc' with 'clang' in the top level make.def file.

TO UNINSTALL
------------
Expand All @@ -87,7 +89,9 @@ TO UNINSTALL
3. Remove all package files using "rm -r *".

Note: 'make' is assumed to be the GNU make command (often available
under the name 'gmake').
under the name 'gmake'). Also, gcc is assumed to be the system
default compiler. On BSD systems, this may be clang. If so,
replace 'gcc' with 'clang' in the top level make.def file.

CONTRIBUTORS
------------
Expand Down
2 changes: 1 addition & 1 deletion ether/channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ struct channel channel =

#if defined (__linux__)

#elif defined (__APPLE__) || defined (__OpenBSD__) || defined (__NetBSD__)
#elif defined (__APPLE__) || defined (__OpenBSD__) || defined (__NetBSD__) || defined (__FreeBSD__)

(struct bpf *) (0),

Expand Down
8 changes: 4 additions & 4 deletions ether/channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
* sort out the raw socket mess;
*--------------------------------------------------------------------*/

#if defined (__linux__) || defined (__APPLE__) || defined (__OpenBSD__) || defined (__NetBSD__)
#if defined (__linux__) || defined (__APPLE__) || defined (__OpenBSD__) || defined (__NetBSD__) || defined (__FreeBSD__)
# ifdef WINPCAP
# error "Don't enable winpcap on Linux. It won't work."
# endif
Expand Down Expand Up @@ -117,7 +117,7 @@
#elif defined (__APPLE__)
# define CHANNEL_ETHDEVICE "en0"
# define CHANNEL_BPFDEVICE "/dev/bpf%d"
#elif defined (__OpenBSD__) || defined(__NetBSD__)
#elif defined (__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__)
# define CHANNEL_ETHDEVICE "bce0"
# define CHANNEL_BPFDEVICE "/dev/bpf%d"
#else
Expand Down Expand Up @@ -168,11 +168,11 @@ typedef struct channel

#if defined (__linux__)

#elif defined (__APPLE__) || defined (__OpenBSD__) || defined(__NetBSD__)
#elif defined (__APPLE__) || defined (__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__)

struct bpf
{
signed bpf_length;
unsigned bpf_length;
uint8_t * bpf_buffer;
uint8_t * bpf_bp;
signed bpf_bufused;
Expand Down
2 changes: 1 addition & 1 deletion ether/closechannel.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ signed closechannel (struct channel const * channel)

return (close (channel->fd));

#elif defined (__APPLE__) || (__OpenBSD__) || defined (__NetBSD__)
#elif defined (__APPLE__) || (__OpenBSD__) || defined (__NetBSD__) || defined (__FreeBSD__)

free (channel->bpf->bpf_buffer);
free (channel->bpf);
Expand Down
9 changes: 9 additions & 0 deletions ether/ether.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@
# include <netinet/if_ether.h>
# include <net/bpf.h>
# include <fcntl.h>
#elif defined (__FreeBSD__)
# include <sys/ioctl.h>
# include <sys/types.h>
# include <sys/socket.h>
# include <net/if.h>
# include <net/ethernet.h>
# include <netinet/in.h>
# include <sys/time.h>
# include <net/bpf.h>
#elif defined (WIN32)
# if defined (WINPCAP)
# include <pcap.h>
Expand Down
2 changes: 1 addition & 1 deletion ether/gethwaddr.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ int gethwaddr (void * memory, char const * device)
}
freeifaddrs (ifaddrs);

#elif defined (__OpenBSD__) || defined(__NetBSD__)
#elif defined (__OpenBSD__) || defined(__NetBSD__) || defined (__FreeBSD__)

#include <ifaddrs.h>
#include <net/if_dl.h>
Expand Down
2 changes: 1 addition & 1 deletion ether/getifname.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ char * getifname (signed index)

#if defined (__linux__)

#elif defined (__APPLE__) || defined (__OpenBSD__) || defined (__NetBSD__)
#elif defined (__APPLE__) || defined (__OpenBSD__) || defined (__NetBSD__) || defined (__FreeBSD__)

#elif defined (WINPCAP) || defined (LIBPCAP)

Expand Down
6 changes: 3 additions & 3 deletions ether/hostnics.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
# include <net/if.h>
# include <netpacket/packet.h>
# include <ifaddrs.h>
#elif defined (__APPLE__) || defined (__OpenBSD__) || defined (__NetBSD__)
#elif defined (__APPLE__) || defined (__OpenBSD__) || defined (__NetBSD__) || defined (__FreeBSD__)
# include <sys/types.h>
# include <sys/socket.h>
# include <net/if.h>
Expand Down Expand Up @@ -146,7 +146,7 @@ unsigned hostnics (struct nic nics [], unsigned size)
}
close (fd);

#elif defined (__linux__) || defined (__APPLE__) || defined (__OpenBSD__) || defined (__NetBSD__)
#elif defined (__linux__) || defined (__APPLE__) || defined (__OpenBSD__) || defined (__NetBSD__) || defined (__FreeBSD__)

/*
* generic (POSIX) method for unix-like systems;
Expand Down Expand Up @@ -195,7 +195,7 @@ unsigned hostnics (struct nic nics [], unsigned size)
memcpy (nic->ethernet, LLADDR (sockaddr_ll), sizeof (nic->ethernet));
}

#elif defined (__APPLE__) || defined (__OpenBSD__) || defined (__NetBSD__)
#elif defined (__APPLE__) || defined (__OpenBSD__) || defined (__NetBSD__) || defined (__FreeBSD__)

if (ifaddr->ifa_addr->sa_family == AF_LINK)
{
Expand Down
14 changes: 11 additions & 3 deletions ether/openchannel.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
# include <sys/stat.h>
# include <fcntl.h>
# include <stdlib.h>
#elif defined (__OpenBSD__) || defined (__NetBSD__)
#elif defined (__OpenBSD__) || defined (__NetBSD__) || defined (__FreeBSD__)
# include <sys/ioctl.h>
# include <sys/stat.h>
# include <sys/types.h>
Expand All @@ -87,7 +87,7 @@
#include "../tools/flags.h"
#include "../tools/error.h"

#if defined (__APPLE__) || defined (__OpenBSD__) || defined (__NetBSD__)
#if defined (__APPLE__) || defined (__OpenBSD__) || defined (__NetBSD__) || defined (__FreeBSD__)
# include "../ether/gethwaddr.c"
#endif

Expand Down Expand Up @@ -296,7 +296,7 @@ signed openchannel (struct channel * channel)
}
};

#if defined (__APPLE__) || defined (__OpenBSD__) || defined (__NetBSD__)
#if defined (__APPLE__) || defined (__OpenBSD__) || defined (__NetBSD__) || defined (__FreeBSD__)

struct ifreq ifreq;
struct timeval timeval;
Expand Down Expand Up @@ -367,6 +367,14 @@ signed openchannel (struct channel * channel)
error (0, errno, "Can't hide outgoing frames");
}

#elif defined (__FreeBSD__)

state = BPF_D_IN;
if (ioctl (channel->fd, BIOCSDIRECTION, &state) == -1)
{
error (0, errno, "Can't hide outgoing frames");
}

#else
#error "Abandon all hope"
#endif
Expand Down
2 changes: 1 addition & 1 deletion ether/pcapdevs.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@

#if defined (__linux__)
#elif defined (__APPLE__)
#elif defined (__OpenBSD__) || defined (__NetBSD__)
#elif defined (__OpenBSD__) || defined (__NetBSD__) || defined (__FreeBSD__)
# include <sys/types.h>
# include <sys/socket.h>
# include <net/if.h>
Expand Down
2 changes: 1 addition & 1 deletion ether/readpacket.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ ssize_t readpacket (struct channel const * channel, void * memory, ssize_t exten
}
}

#elif defined (__APPLE__) || defined (__OpenBSD__) || defined (__NetBSD__)
#elif defined (__APPLE__) || defined (__OpenBSD__) || defined (__NetBSD__) || defined (__FreeBSD__)

struct bpf_hdr * bpf_packet;
struct bpf * bpf = channel->bpf;;
Expand Down
2 changes: 1 addition & 1 deletion ether/sendpacket.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ ssize_t sendpacket (struct channel const * channel, void * memory, ssize_t exten

extent = sendto (channel->fd, memory, extent, 0, (struct sockaddr *) (0), (socklen_t) (0));

#elif defined (__APPLE__) || defined (__OpenBSD__) || defined (__NetBSD__)
#elif defined (__APPLE__) || defined (__OpenBSD__) || defined (__NetBSD__) || defined (__FreeBSD__)

extent = write (channel->fd, memory, extent);

Expand Down
4 changes: 2 additions & 2 deletions plc/PLCHostBoot.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ static signed opensocket (char const * socketname)
struct sockaddr_un sockaddr_un =
{

#if defined (__OpenBSD__) || defined (__NetBSD__)
#if defined (__OpenBSD__) || defined (__NetBSD__) || defined (__FreeBSD__)

0,

Expand All @@ -92,7 +92,7 @@ static signed opensocket (char const * socketname)
};
strncpy (sockaddr_un.sun_path, socketname, sizeof (sockaddr_un.sun_path));

#if defined (__OpenBSD__) || defined (__NetBSD__)
#if defined (__OpenBSD__) || defined (__NetBSD__) || defined (__FreeBSD__)

sockaddr_un.sun_len = SUN_LEN (&sockaddr_un);

Expand Down
2 changes: 1 addition & 1 deletion plc/plc.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ struct plc plc =
PLC_FLAGS
};

#if defined (__linux__) || defined (__APPLE__) || defined (__OpenBSD__) || defined (__NetBSD__)
#if defined (__linux__) || defined (__APPLE__) || defined (__OpenBSD__) || defined (__NetBSD__) || defined (__FreeBSD__)
#define RANDOMIZE_COOKIE 1
#endif

Expand Down
2 changes: 1 addition & 1 deletion plc/plcdevs.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ static void enumerate (struct channel * channel, struct nic nic [], unsigned siz

printf (" %d", nic->ifindex);

#elif defined (__linux__) || defined (__OpenBSD__) || defined (__NetBSD__) || defined (__APPLE__)
#elif defined (__linux__) || defined (__OpenBSD__) || defined (__NetBSD__) || defined (__APPLE__) || defined (__FreeBSD__)

printf (" %s", nic->ifname);

Expand Down
4 changes: 2 additions & 2 deletions plc/plchostd.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ static signed opensocket (char const * socketname)
struct sockaddr_un sockaddr_un =
{

#if defined (__OpenBSD__) || defined (__NetBSD__) || defined (__APPLE__)
#if defined (__OpenBSD__) || defined (__NetBSD__) || defined (__APPLE__) || defined (__FreeBSD__)

0,

Expand All @@ -263,7 +263,7 @@ static signed opensocket (char const * socketname)
};
strncpy (sockaddr_un.sun_path, socketname, sizeof (sockaddr_un.sun_path));

#if defined (__OpenBSD__) || defined (__NetBSD__) || defined (__APPLE__)
#if defined (__OpenBSD__) || defined (__NetBSD__) || defined (__APPLE__) || defined (__FreeBSD__)

sockaddr_un.sun_len = SUN_LEN (&sockaddr_un);

Expand Down
4 changes: 2 additions & 2 deletions plc/plchostd2.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ static signed opensocket (char const * socketname)
struct sockaddr_un sockaddr_un =
{

#if defined (__OpenBSD__) || defined (__NetBSD__) || defined (__APPLE__)
#if defined (__OpenBSD__) || defined (__NetBSD__) || defined (__APPLE__) || defined (__FreeBSD__)

0,

Expand All @@ -242,7 +242,7 @@ static signed opensocket (char const * socketname)
};
strncpy (sockaddr_un.sun_path, socketname, sizeof (sockaddr_un.sun_path));

#if defined (__OpenBSD__) || defined (__NetBSD__) || defined (__APPLE__)
#if defined (__OpenBSD__) || defined (__NetBSD__) || defined (__APPLE__) || defined (__FreeBSD__)

sockaddr_un.sun_len = SUN_LEN (&sockaddr_un);

Expand Down
2 changes: 1 addition & 1 deletion serial/int6kbaud.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
# include <termios.h>
#elif defined (__APPLE__)
# include <termios.h>
#elif defined (__OpenBSD__) || defined (__NetBSD__)
#elif defined (__OpenBSD__) || defined (__NetBSD__) || defined (__FreeBSD__)
# include <termios.h>
#else
#error "Unknown Environment"
Expand Down
2 changes: 1 addition & 1 deletion serial/int6kuart.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
# include <net/ethernet.h>
#elif defined (__APPLE__)
# include <net/ethernet.h>
#elif defined (__OpenBSD__) || defined (__NetBSD__)
#elif defined (__OpenBSD__) || defined (__NetBSD__) || defined (__FreeBSD__)
# include <sys/socket.h>
# include <net/if.h>
# include <net/if_arp.h>
Expand Down
2 changes: 1 addition & 1 deletion serial/openport.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
#elif defined (__APPLE__)
# include <termios.h>
# include <net/ethernet.h>
#elif defined (__OpenBSD__) || defined (__NetBSD__)
#elif defined (__OpenBSD__) || defined (__NetBSD__) || defined (__FreeBSD__)
# include <termios.h>
#else
#error "Unknown Environment"
Expand Down
2 changes: 1 addition & 1 deletion serial/ptsctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
# include <termios.h>
#elif defined (__APPLE__)
# include <termios.h>
#elif defined (__OpenBSD__) || defined (__NetBSD__)
#elif defined (__OpenBSD__) || defined (__NetBSD__) || defined (__FreeBSD__)
# include <termios.h>
#elif defined (WIN32)
# include <windows.h>
Expand Down
2 changes: 1 addition & 1 deletion serial/weeder.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
# include <termios.h>
#elif defined (__APPLE__)
# include <termios.h>
#elif defined (__OpenBSD__) || defined (__NetBSD__)
#elif defined (__OpenBSD__) || defined (__NetBSD__) || defined (__FreeBSD__)
# include <termios.h>
#elif defined (WIN32)
# include <windows.h>
Expand Down
5 changes: 4 additions & 1 deletion tools/endian.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@
# include <libkern/OSByteOrder.h>
#elif defined (__OpenBSD__)
# include <sys/types.h>
#elif defined (__FreeBSD__)
# include <sys/types.h>
# include <sys/endian.h>
#elif defined (__NetBSD__)
# include <sys/types.h>
# include <machine/bswap.h>
Expand Down Expand Up @@ -169,7 +172,7 @@ uint64_t __bswap_64 (uint64_t x);
#define __bswap_32(x) swap32(x)
#define __bswap_64(x) swap64(x)

#elif defined (__NetBSD__)
#elif defined (__NetBSD__) || defined(__FreeBSD__)

#define __bswap_16(x) bswap16(x)
#define __bswap_32(x) bswap32(x)
Expand Down
24 changes: 12 additions & 12 deletions tools/flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,24 @@
#define _bits(object) (sizeof (object) << 3)
#define _getbits(map,pos,cnt) (((map)>>((pos)-(cnt)+1))&~(~(0)<<(cnt)))

#define _bitmask(bits) ~(~(0) << bits)
#define _bitmask(bits) (~(~(0) << bits))

#define _setbits(flag,mask) flag |= (mask)
#define _clrbits(flag,mask) flag &= ~(mask)
#define _toggle(flag,mask) flag = ~(flag) & ~(mask)
#define _setbits(flag,mask) (flag |= (mask))
#define _clrbits(flag,mask) (flag &= ~(mask))
#define _toggle(flag,mask) (flag = ~(flag) & ~(mask))

#define _anyset(flag,mask) ((flag) & (mask)) != (0)
#define _anyclr(flag,mask) ((flag) & (mask)) != (mask)
#define _allset(flag,mask) ((flag) & (mask)) == (mask)
#define _allclr(flag,mask) ((flag) & (mask)) == (0)
#define _anyset(flag,mask) (((flag) & (mask)) != (0))
#define _anyclr(flag,mask) (((flag) & (mask)) != (mask))
#define _allset(flag,mask) (((flag) & (mask)) == (mask))
#define _allclr(flag,mask) (((flag) & (mask)) == (0))

// #define _notset(flag,mask) ((flag) & (mask)) == (0)

#define _anybits(flag,mask) ((flag) & (mask)) != (0)
#define _allbits(flag,mask) ((flag) & (mask)) == (mask)
#define _anybits(flag,mask) (((flag) & (mask)) != (0))
#define _allbits(flag,mask) (((flag) & (mask)) == (mask))

#define _clean(flag,mask) ((flag) & ~(mask)) == (0)
#define _dirty(flag,mask) ((flag) & ~(mask)) != (0)
#define _clean(flag,mask) (((flag) & ~(mask)) == (0))
#define _dirty(flag,mask) (((flag) & ~(mask)) != (0))

/*====================================================================*
*
Expand Down
3 changes: 3 additions & 0 deletions tools/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
#elif defined (__OpenBSD__) || defined (__NetBSD__)
#define SIZE_T_SPEC "%zu"
#define OFF_T_SPEC "%lld"
#elif defined(__FreeBSD__)
#define SIZE_T_SPEC "%zu"
#define OFF_T_SPEC "%ld"
#elif defined (__linux__)
#define SIZE_T_SPEC "%zu"
#define OFF_T_SPEC "%ld"
Expand Down