77 lines
2.7 KiB
Text
77 lines
2.7 KiB
Text
Index: src/interfaces.c
|
|
--- src/interfaces.c.orig
|
|
+++ src/interfaces.c
|
|
@@ -28,7 +28,7 @@
|
|
#include <sys/socket.h>
|
|
#include <sys/types.h>
|
|
#include <ifaddrs.h>
|
|
-#if defined(__FreeBSD__) || defined(__APPLE__)
|
|
+#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__OpenBSD__)
|
|
#include <netinet/in.h>
|
|
#endif
|
|
#include <netinet/ip.h>
|
|
@@ -37,6 +37,11 @@
|
|
#include <net/ethernet.h>
|
|
#define ETH_FRAME_LEN (ETHER_MAX_LEN - ETHER_CRC_LEN)
|
|
#define ETH_ALEN ETHER_ADDR_LEN
|
|
+#elif defined(__OpenBSD__)
|
|
+#include <net/if.h>
|
|
+#include <netinet/if_ether.h>
|
|
+#define ETH_FRAME_LEN (ETHER_MAX_LEN - ETHER_CRC_LEN)
|
|
+#define ETH_ALEN ETHER_ADDR_LEN
|
|
#else
|
|
#include <netinet/ether.h>
|
|
#endif
|
|
@@ -298,7 +303,7 @@ int net_send_udp(const int fd, struct net_interface *i
|
|
*/
|
|
static unsigned char stackbuf[ETH_FRAME_LEN];
|
|
void* buffer = (void*)&stackbuf;
|
|
-#if defined(__FreeBSD__) || defined(__APPLE__)
|
|
+#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__OpenBSD__)
|
|
struct ether_header *eh = (struct ether_header *)buffer;
|
|
struct ip *ip = (struct ip *)(buffer + 14);
|
|
#else
|
|
@@ -325,7 +330,7 @@ int net_send_udp(const int fd, struct net_interface *i
|
|
}
|
|
|
|
/* Init ethernet header */
|
|
-#if defined(__FreeBSD__) || defined(__APPLE__)
|
|
+#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__OpenBSD__)
|
|
memcpy(eh->ether_shost, sourcemac, ETH_ALEN);
|
|
memcpy(eh->ether_dhost, destmac, ETH_ALEN);
|
|
eh->ether_type = htons(ETHERTYPE_IP);
|
|
@@ -350,7 +355,7 @@ int net_send_udp(const int fd, struct net_interface *i
|
|
#endif
|
|
|
|
/* Init IP Header */
|
|
-#if defined(__FreeBSD__) || defined(__APPLE__)
|
|
+#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__OpenBSD__)
|
|
ip->ip_v = 4;
|
|
ip->ip_hl = 5;
|
|
ip->ip_tos = 0x10;
|
|
@@ -377,14 +382,14 @@ int net_send_udp(const int fd, struct net_interface *i
|
|
#endif
|
|
|
|
/* Calculate checksum for IP header */
|
|
-#if defined(__FreeBSD__) || defined(__APPLE__)
|
|
+#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__OpenBSD__)
|
|
ip->ip_sum = in_cksum((unsigned short *)ip, sizeof(struct ip));
|
|
#else
|
|
ip->check = in_cksum((unsigned short *)ip, sizeof(struct iphdr));
|
|
#endif
|
|
|
|
/* Init UDP Header */
|
|
-#if defined(__FreeBSD__) || defined(__APPLE__)
|
|
+#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__OpenBSD__)
|
|
udp->uh_sport = htons(sourceport);
|
|
udp->uh_dport = htons(destport);
|
|
udp->uh_ulen = htons(sizeof(struct udphdr) + datalen);
|
|
@@ -400,7 +405,7 @@ int net_send_udp(const int fd, struct net_interface *i
|
|
memcpy(rest, data, datalen);
|
|
|
|
/* Add UDP checksum */
|
|
-#if defined(__FreeBSD__) || defined(__APPLE__)
|
|
+#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__OpenBSD__)
|
|
udp->uh_sum = udp_sum_calc((unsigned char *)&(ip->ip_src.s_addr),
|
|
(unsigned char *)&(ip->ip_dst.s_addr),
|
|
(unsigned char *)udp,
|