Skip to content

Commit

Permalink
Add FreeBSD support. Tested on 8.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Vit committed Dec 3, 2013
1 parent fa2984e commit e53ca34
Show file tree
Hide file tree
Showing 35 changed files with 278 additions and 102 deletions.
4 changes: 2 additions & 2 deletions calltable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
*/


#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <syslog.h>
#include <math.h>
#include <net/if.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <errno.h>
#include <net/if.h>

#ifdef ISCURL
#include <curl/curl.h>
Expand Down
5 changes: 4 additions & 1 deletion cleanspool.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "voipmonitor.h"
#include <algorithm>
#include <errno.h>
#include <dirent.h>
Expand All @@ -17,6 +18,7 @@
#include "tools.h"
#include "cleanspool.h"


using namespace std;


Expand Down Expand Up @@ -1402,4 +1404,5 @@ bool isSetCleanspoolParameters() {
opt_maxpoolaudiodays ||
opt_cleanspool_interval ||
opt_cleanspool_sizeMB);
}
}

3 changes: 2 additions & 1 deletion cleanspool.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ bool check_exists_act_records_in_files();
void clean_obsolete_dirs(const char *path = NULL);
bool isSetCleanspoolParameters();

#endif
#endif

1 change: 0 additions & 1 deletion codec_alaw.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
#include <string.h>
#include "codec_alaw.h"
Expand Down
1 change: 0 additions & 1 deletion codec_alaw.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
#include <string.h>

Expand Down
1 change: 0 additions & 1 deletion codec_ulaw.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
#include <string.h>
#include "codec_alaw.h"
Expand Down
1 change: 0 additions & 1 deletion codec_ulaw.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
#include <string.h>

Expand Down
1 change: 1 addition & 0 deletions filter_mysql.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <syslog.h>
#include <string.h>
#include "voipmonitor.h"

#include "filter_mysql.h"
#include "calltable.h"
Expand Down
1 change: 0 additions & 1 deletion format_ogg.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/*#include "format_wav.h"*/

#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
Expand Down
1 change: 0 additions & 1 deletion format_wav.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
Expand Down
12 changes: 6 additions & 6 deletions generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ Generator::Generator(const char *src, const char *dst) {
int
Generator::send(char *data, int datalen) {

struct iphdr *iphdr;
struct iphdr2 *iphdr;

iphdr = (struct iphdr *)generator_packet;
iphdr = (struct iphdr2 *)generator_packet;
memset(iphdr, 0, sizeof(iphdr));
iphdr->version = 4;
iphdr->tos = 0;
Expand All @@ -85,17 +85,17 @@ Generator::send(char *data, int datalen) {
iphdr->ttl = 120;
iphdr->protocol = 17;
iphdr->check = 0;
iphdr->tot_len = htons(sizeof(struct iphdr) + datalen);
iphdr->tot_len = htons(sizeof(struct iphdr2) + datalen);
iphdr->ihl = 5;
iphdr->check = 0;
iphdr->saddr = src_addr.sin_addr.s_addr;
iphdr->daddr = dest_addr.sin_addr.s_addr;
memcpy(generator_packet + sizeof(struct iphdr), data, datalen);
memcpy(generator_packet + sizeof(struct iphdr2), data, datalen);

int res;
if((res = sendto(sockraw, generator_packet, datalen + sizeof(struct iphdr), 0, (struct sockaddr *)&dest_addr, sizeof(struct sockaddr))) == -1)
if((res = sendto(sockraw, generator_packet, datalen + sizeof(struct iphdr2), 0, (struct sockaddr *)&dest_addr, sizeof(struct sockaddr))) == -1)
{
printf("msglen[%lu]\n", datalen + sizeof(struct iphdr));
printf("msglen[%lu]\n", datalen + sizeof(struct iphdr2));
perror("sendto");
}
return res;
Expand Down
8 changes: 8 additions & 0 deletions generator.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef GENERATOR_H
#define GENERATOR_H

#include "voipmonitor.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
Expand All @@ -12,7 +13,11 @@
#include <fcntl.h>
#include <netinet/in.h>
#include <arpa/inet.h>

#ifndef FREEBSD
#include <netinet/ether.h>
#endif

#include <sys/times.h>
#include <sys/param.h>
#include <sys/signal.h>
Expand All @@ -21,6 +26,8 @@
#include <errno.h>
#include <netinet/udp.h>
#include <netinet/ip_icmp.h>

#ifndef FREEBSD
#include <features.h> /* for the glibc version number */
#if __GLIBC__ >= 2 && __GLIBC_MINOR >= 1
#include <netpacket/packet.h>
Expand All @@ -30,6 +37,7 @@
#include <linux/if_packet.h>
#include <linux/if_ether.h> /* The L2 protocols */
#endif
#endif

using namespace std;

Expand Down
6 changes: 3 additions & 3 deletions ipaccount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ and insert them into Call class.
#include <getopt.h>
#include <time.h>
#include <signal.h>
#include <endian.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <net/ethernet.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <syslog.h>
Expand Down Expand Up @@ -363,7 +363,7 @@ void ipacc_add_octets(time_t timestamp, unsigned int saddr, unsigned int daddr,

void ipaccount(time_t timestamp, struct iphdr2 *header_ip, int packetlen, int voippacket){
struct udphdr2 *header_udp;
struct tcphdr *header_tcp;
struct tcphdr2 *header_tcp;

if (header_ip->protocol == IPPROTO_UDP) {
// prepare packet pointers
Expand All @@ -377,7 +377,7 @@ void ipaccount(time_t timestamp, struct iphdr2 *header_ip, int packetlen, int vo
ipacc_add_octets(timestamp, header_ip->saddr, header_ip->daddr, 0, IPPROTO_TCP, packetlen, voippacket);
}
} else if (header_ip->protocol == IPPROTO_TCP) {
header_tcp = (struct tcphdr *) ((char *) header_ip + sizeof(*header_ip));
header_tcp = (struct tcphdr2 *) ((char *) header_ip + sizeof(*header_ip));

if(ipaccountportmatrix[htons(header_tcp->source)]) {
ipacc_add_octets(timestamp, header_ip->saddr, header_ip->daddr, htons(header_tcp->source), IPPROTO_TCP, packetlen, voippacket);
Expand Down
6 changes: 0 additions & 6 deletions jitterbuffer/asterisk/lock.h
Original file line number Diff line number Diff line change
Expand Up @@ -873,9 +873,6 @@ static inline int __ast_rwlock_init(const char *filename, int lineno, const char
#endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
pthread_rwlockattr_init(&attr);

#ifdef HAVE_PTHREAD_RWLOCK_PREFER_WRITER_NP
pthread_rwlockattr_setkind_np(&attr, PTHREAD_RWLOCK_PREFER_WRITER_NP);
#endif

res = pthread_rwlock_init(prwlock, &attr);
pthread_rwlockattr_destroy(&attr);
Expand Down Expand Up @@ -1170,9 +1167,6 @@ static inline int ast_rwlock_init(ast_rwlock_t *prwlock)

pthread_rwlockattr_init(&attr);

#ifdef HAVE_PTHREAD_RWLOCK_PREFER_WRITER_NP
pthread_rwlockattr_setkind_np(&attr, PTHREAD_RWLOCK_PREFER_WRITER_NP);
#endif

res = pthread_rwlock_init(prwlock, &attr);
pthread_rwlockattr_destroy(&attr);
Expand Down
2 changes: 1 addition & 1 deletion jitterbuffer/jitterbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ enum jb_return_code jb_put(jitterbuf *jb, void *data, const enum jb_frame_type t
* IAX integrations, I'm sending retransmitted control frames with their awkward timestamps through */
if (history_put(jb,ts,now,ms)) {
jb->info.frames_dropped++;
jb_dbg2("history_put > 0 | %u %u %u\n", ts, now, ms);
jb_dbg2("history_put > 0 | %lu %lu %lu\n", ts, now, ms);
return JB_DROP;
}
}
Expand Down
10 changes: 0 additions & 10 deletions jitterbuffer/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -1152,16 +1152,6 @@ int ast_dynamic_str_thread_build_va(struct ast_dynamic_str **buf, size_t max_len
return res;
}

void ast_enable_packet_fragmentation(int sock)
{
#if defined(HAVE_IP_MTU_DISCOVER)
int val = IP_PMTUDISC_DONT;

if (setsockopt(sock, IPPROTO_IP, IP_MTU_DISCOVER, &val, sizeof(val)))
printf("Unable to disable PMTU discovery. Large UDP packets may fail to be delivered when sent from this socket.\n");
#endif /* HAVE_IP_MTU_DISCOVER */
}

int ast_utils_init(void)
{
base64_init();
Expand Down
38 changes: 20 additions & 18 deletions mirrorip.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/*Writing some small packet generator
*/

#include "voipmonitor.h"
#include "mirrorip.h"
#include "sniff.h"

void
MirrorIP::socket_broadcast(int sd)
Expand Down Expand Up @@ -55,28 +57,28 @@ MirrorIP::MirrorIP(const char *src, const char *dst) {
int
MirrorIP::send(char *data, int datalen) {

struct iphdr *iphdr;
struct iphdr2 *ip_hdr;

iphdr = (struct iphdr *)mirror_packet;
memset(iphdr, 0, sizeof(*iphdr));
iphdr->version = 4;
iphdr->tos = 0;
iphdr->id = htons(100);
iphdr->frag_off = 0;
iphdr->ttl = 120;
iphdr->protocol = 4;
iphdr->check = 0;
iphdr->tot_len = htons(sizeof(struct iphdr) + datalen);
iphdr->ihl = 5;
iphdr->check = 0;
iphdr->saddr = src_addr.sin_addr.s_addr;
iphdr->daddr = dest_addr.sin_addr.s_addr;
memcpy(mirror_packet + sizeof(struct iphdr), data, datalen);
ip_hdr = (struct iphdr2 *)mirror_packet;
memset(ip_hdr, 0, sizeof(struct iphdr2));
ip_hdr->version = 4;
ip_hdr->tos = 0;
ip_hdr->id = htons(100);
ip_hdr->frag_off = 0;
ip_hdr->ttl = 120;
ip_hdr->protocol = 4;
ip_hdr->check = 0;
ip_hdr->tot_len = htons(sizeof(struct iphdr2) + datalen);
ip_hdr->ihl = 5;
ip_hdr->check = 0;
ip_hdr->saddr = src_addr.sin_addr.s_addr;
ip_hdr->daddr = dest_addr.sin_addr.s_addr;
memcpy(mirror_packet + sizeof(struct iphdr2), data, datalen);

int res;
if((res = sendto(sockraw, mirror_packet, datalen + sizeof(struct iphdr), 0, (struct sockaddr *)&dest_addr, sizeof(struct sockaddr))) == -1)
if((res = sendto(sockraw, mirror_packet, datalen + sizeof(struct iphdr2), 0, (struct sockaddr *)&dest_addr, sizeof(struct sockaddr))) == -1)
{
printf("msglen[%lu]\n", datalen + sizeof(struct iphdr));
printf("msglen[%lu]\n", datalen + sizeof(struct iphdr2));
perror("sendto");
}
return res;
Expand Down
12 changes: 11 additions & 1 deletion mirrorip.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef MIRRORIP_H
#define MIRRORIP_H

#include "voipmonitor.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
Expand All @@ -12,7 +13,11 @@
#include <fcntl.h>
#include <netinet/in.h>
#include <arpa/inet.h>

#ifndef FREEBSD
#include <netinet/ether.h>
#endif

#include <sys/times.h>
#include <sys/param.h>
#include <sys/signal.h>
Expand All @@ -21,15 +26,20 @@
#include <errno.h>
#include <netinet/udp.h>
#include <netinet/ip_icmp.h>



#if 0
#include <features.h> /* for the glibc version number */
#if __GLIBC__ >= 2 && __GLIBC_MINOR >= 1
#if (__GLIBC__ >= 2 && __GLIBC_MINOR >= 1 ) || (defined( __FreeBSD__ ) || defined ( __NetBSD__ ))
#include <netpacket/packet.h>
#include <net/ethernet.h> /* the L2 protocols */
#else
#include <asm/types.h>
#include <linux/if_packet.h>
#include <linux/if_ether.h> /* The L2 protocols */
#endif
#endif

using namespace std;

Expand Down
Loading

0 comments on commit e53ca34

Please sign in to comment.