Skip to content

Commit

Permalink
Merge pull request #266 from btriller/bsd-build
Browse files Browse the repository at this point in the history
Build on BSDs/Apple
  • Loading branch information
kYroL01 authored Apr 24, 2023
2 parents b27c7ad + 5fc0d46 commit 47f67cc
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 20 deletions.
5 changes: 5 additions & 0 deletions src/modules/interface/http/interface_http.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ typedef struct interface_http_stats {
uint64_t send_erros_total;
} interface_http_stats_t;

#if defined(__APPLE__)
#define st_atim st_atimespec
#define st_ctim st_ctimespec
#define st_mtim st_mtimespec
#endif

#ifdef USE_IPV6
#include <netinet/ip6.h>
Expand Down
1 change: 0 additions & 1 deletion src/modules/protocol/diameter/parser_diameter.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

#include <string.h>
#include <stdlib.h>
#include <endian.h>
#include <net/ethernet.h>
#include <arpa/inet.h>

Expand Down
1 change: 0 additions & 1 deletion src/modules/protocol/rtcpxr/parser_rtcpxr.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

#include <string.h>
#include <stdlib.h>
#include <endian.h>
#include <net/ethernet.h>
#include <arpa/inet.h>
#include "../../../../include/captagent/api.h"
Expand Down
1 change: 0 additions & 1 deletion src/modules/protocol/sip/protocol_sip.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ typedef struct protocol_sip_stats {

static protocol_sip_stats_t stats;

extern char* usefile;
extern int handler(int value);
extern int set_raw_rtp_filter();

Expand Down
1 change: 0 additions & 1 deletion src/modules/socket/collector/socket_collector.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
extern char *global_config_path;
extern char *global_scripts_path;

extern char *usefile;
extern int handler(int value);

#define MAX_SOCKETS 10
Expand Down
20 changes: 8 additions & 12 deletions src/modules/socket/pcap/socket_pcap.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@
#ifndef __FAVOR_BSD
#define __FAVOR_BSD
#endif
#include <net/ethernet.h>
#include <netinet/in.h>
#include <netinet/if_ether.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <netinet/udp.h>
Expand Down Expand Up @@ -305,7 +304,7 @@ void callback_proto(unsigned char *arg, struct pcap_pkthdr *pkthdr, unsigned cha
}

msg_t _msg;
struct ethhdr* eth = NULL;
struct ether_header* eth = NULL;
struct sll_header* sll = NULL;
struct sll2_header* sll2 = NULL;
struct ip* ip4_pkt = NULL;
Expand Down Expand Up @@ -469,7 +468,7 @@ void callback_proto(unsigned char *arg, struct pcap_pkthdr *pkthdr, unsigned cha
memcpy(&ethaddr, (packet + 12), 2);
memcpy(&mplsaddr, (packet + 16), 2);

if (ntohs((uint16_t)*(&ethaddr)) == VLAN) {
if (ntohs((uint16_t)*(&ethaddr)) == ETHERTYPE_VLAN) {
if (ntohs((uint16_t)*(&mplsaddr)) == MPLS_UNI) {
hdr_offset = 8;
vlan = 1;
Expand All @@ -485,21 +484,18 @@ void callback_proto(unsigned char *arg, struct pcap_pkthdr *pkthdr, unsigned cha
} else if (type_datalink == DLT_LINUX_SLL2) {
sll2 = (struct sll2_header *)(packet + hdr_preset);
} else {
eth = (struct ethhdr *)(packet + hdr_preset);
eth = (struct ether_header *)(packet + hdr_preset);
}

if (eth) {
//snprintf(mac_src, sizeof(mac_src), "%.2X-%.2X-%.2X-%.2X-%.2X-%.2X", eth->ether_shost[0], eth->ether_shost[1], eth->ether_shost[2], eth->ether_shost[3], eth->ether_shost[4], eth->ether_shost[5]);
//snprintf(mac_dst, sizeof(mac_dst), "%.2X-%.2X-%.2X-%.2X-%.2X-%.2X", eth->ether_dhost[0], eth->ether_dhost[1], eth->ether_dhost[2], eth->ether_dhost[3], eth->ether_dhost[4], eth->ether_dhost[5]);
snprintf(mac_src, sizeof(mac_src), "%.2X-%.2X-%.2X-%.2X-%.2X-%.2X",
eth->h_source[0], eth->h_source[1], eth->h_source[2], eth->h_source[3], eth->h_source[4], eth->h_source[5]);
eth->ether_shost[0], eth->ether_shost[1], eth->ether_shost[2], eth->ether_shost[3], eth->ether_shost[4], eth->ether_shost[5]);
snprintf(mac_dst, sizeof(mac_dst), "%.2X-%.2X-%.2X-%.2X-%.2X-%.2X",
eth->h_dest[0], eth->h_dest[1], eth->h_dest[2], eth->h_dest[3], eth->h_dest[4], eth->h_dest[5]);
eth->ether_dhost[0], eth->ether_dhost[1], eth->ether_dhost[2], eth->ether_dhost[3], eth->ether_dhost[4], eth->ether_dhost[5]);

if(vlan == 0 || vlan == 2) {
// IP TYPE = 0x86dd (IPv6) or 0x0800 (IPv4) or (0x8100 VLAN)
//type_ip = ntohs(eth->ether_type);
type_ip = ntohs(eth->h_proto);
type_ip = ntohs(eth->ether_type);
}
}
/* Linux cooked capture (v1 and v2) shows only Source MAC address */
Expand Down Expand Up @@ -1223,7 +1219,7 @@ void* proto_collect(void *arg) {
/* detect link_offset */
switch (type_datalink) {
case DLT_EN10MB:
link_offset = ETHHDR_SIZE;
link_offset = ETHER_HDR_LEN;
break;

case DLT_IEEE802:
Expand Down
3 changes: 0 additions & 3 deletions src/modules/socket/pcap/socket_pcap.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,13 @@

#include <captagent/xmlread.h>

extern char *usefile;
extern int handler(int value);
extern char *global_config_path;
extern char *global_scripts_path;

/* Ethernet type in case of vlan or mpls header */
#define IPV4_SIZE 20
#define ERSPANHDR_SIZE 16
#define VLAN 0x8100
#define MPLS_UNI 0x8847
#define MPLS_MULTI 0x8848
#define ERSPAN 0x88be
Expand Down Expand Up @@ -77,7 +75,6 @@ struct sll2_header {
#endif

/* header offsets */
#define ETHHDR_SIZE 14
#define TOKENRING_SIZE 22
#define PPPHDR_SIZE 4
#define SLIPHDR_SIZE 16
Expand Down
1 change: 0 additions & 1 deletion src/modules/socket/tzsp/socket_tzsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
extern char *global_config_path;
extern char *global_scripts_path;

extern char *usefile;
extern int handler(int value);

#define MAX_SOCKETS 10
Expand Down

0 comments on commit 47f67cc

Please sign in to comment.