Commit 0d6cbfa6 authored by Bruno Randolf's avatar Bruno Randolf

port for Mac OSX

thanks, ingo :)
parent 73957d4c
......@@ -53,9 +53,26 @@ int
open_packet_socket(char* devname, size_t bufsize, int recv_buffer_size)
{
char error[PCAP_ERRBUF_SIZE];
pcap_fp = pcap_open_live(devname, bufsize, 1, PCAP_TIMEOUT, error);
int ret;
pcap_fp = pcap_create(devname, error);
if (pcap_fp == NULL) {
fprintf(stderr, "Couldn't open pcap device: %s\n", error);
fprintf(stderr, "Couldn't create pcap: %s\n", error);
return -1;
}
pcap_set_promisc(pcap_fp, 1);
#if defined(__APPLE__)
if (pcap_can_set_rfmon(pcap_fp))
pcap_set_rfmon(pcap_fp, 1);
else
err(1, "Couldn't activate monitor mode");
#endif
ret = pcap_activate(pcap_fp);
if (ret < 0) {
fprintf(stderr, "Can't activate pcap: %d\n", ret);
return -1;
}
......
......@@ -25,6 +25,35 @@
#include "wext.h"
#if defined(__APPLE__)
int
change_channel(int idx)
{
return 0;
}
int
auto_change_channel(int mon)
{
return 0;
}
int
find_channel_index(int c)
{
return -1;
}
void
get_current_channel(int mon)
{
}
#else
static struct timeval last_channelchange;
extern int mon; /* monitoring socket */
......@@ -74,19 +103,6 @@ auto_change_channel(int mon)
}
void
init_channels(void)
{
int i;
for (i = 0; i < conf.num_channels && i < MAX_CHANNELS; i++) {
INIT_LIST_HEAD(&spectrum[i].nodes);
ewma_init(&spectrum[i].signal_avg, 1024, 8);
ewma_init(&spectrum[i].durations_avg, 1024, 8);
}
}
int
find_channel_index(int c)
{
......@@ -115,3 +131,18 @@ get_current_channel(int mon)
conf.current_channel = ch;
DEBUG("***%d\n", conf.current_channel);
}
#endif
void
init_channels(void)
{
int i;
for (i = 0; i < conf.num_channels && i < MAX_CHANNELS; i++) {
INIT_LIST_HEAD(&spectrum[i].nodes);
ewma_init(&spectrum[i].signal_avg, 1024, 8);
ewma_init(&spectrum[i].durations_avg, 1024, 8);
}
}
......@@ -20,6 +20,8 @@
#ifndef _MAIN_H_
#define _MAIN_H_
#include <sys/time.h>
#include "list.h"
#include "average.h"
......
......@@ -22,6 +22,7 @@
#include <sys/socket.h>
#include <net/if_arp.h>
#include <netinet/ip.h>
#define __FAVOR_BSD
#include <netinet/udp.h>
#include "prism_header.h"
......@@ -62,8 +63,7 @@ parse_packet(unsigned char* buf, int len, struct packet_info* p)
return 0;
}
if (conf.arphrd == ARPHRD_IEEE80211 ||
conf.arphrd == ARPHRD_IEEE80211_PRISM ||
if (conf.arphrd == ARPHRD_IEEE80211_PRISM ||
conf.arphrd == ARPHRD_IEEE80211_RADIOTAP) {
DEBUG("before parse 80211 len: %d\n", len);
len = parse_80211_header(&buf, len, p);
......@@ -559,23 +559,23 @@ parse_llc(unsigned char ** buf, int len, struct packet_info* p)
static int
parse_ip_header(unsigned char** buf, int len, struct packet_info* p)
{
struct iphdr* ih;
struct ip* ih;
DEBUG("* parse IP\n");
if (len < sizeof(struct iphdr))
if (len < sizeof(struct ip))
return -1;
ih = (struct iphdr*)*buf;
ih = (struct ip*)*buf;
DEBUG("*** IP SRC: %s\n", ip_sprintf(ih->saddr));
DEBUG("*** IP DST: %s\n", ip_sprintf(ih->daddr));
p->ip_src = ih->saddr;
p->ip_dst = ih->daddr;
DEBUG("*** IP SRC: %s\n", ip_sprintf(ih->ip_src.s_addr));
DEBUG("*** IP DST: %s\n", ip_sprintf(ih->ip_dst.s_addr));
p->ip_src = ih->ip_src.s_addr;
p->ip_dst = ih->ip_dst.s_addr;
p->pkt_types |= PKT_TYPE_IP;
DEBUG("IP proto: %d\n", ih->protocol);
switch (ih->protocol) {
DEBUG("IP proto: %d\n", ih->ip_p);
switch (ih->ip_p) {
case IPPROTO_UDP: p->pkt_types |= PKT_TYPE_UDP; break;
/* all others set the type and return. no more parsing */
case IPPROTO_ICMP: p->pkt_types |= PKT_TYPE_ICMP; return 0;
......@@ -583,8 +583,8 @@ parse_ip_header(unsigned char** buf, int len, struct packet_info* p)
}
*buf = *buf + ih->ihl * 4;
return len - ih->ihl * 4;
*buf = *buf + ih->ip_hl * 4;
return len - ih->ip_hl * 4;
}
......@@ -598,9 +598,9 @@ parse_udp_header(unsigned char** buf, int len, struct packet_info* p)
uh = (struct udphdr*)*buf;
DEBUG("UPD dest port: %d\n", ntohs(uh->dest));
DEBUG("UPD dest port: %d\n", ntohs(uh->uh_dport));
p->tcpudp_port = ntohs(uh->dest);
p->tcpudp_port = ntohs(uh->uh_dport);
*buf = *buf + 8;
len = len - 8;
......
......@@ -21,8 +21,21 @@
#define _UTIL_H_
#include <stdio.h>
#ifdef _ALLBSD_SOURCE
#include <machine/endian.h>
#elif __linux__
#include <endian.h>
#endif
#if defined(__APPLE__)
#include <libkern/OSByteOrder.h>
#define bswap_16 OSSwapInt16
#define bswap_32 OSSwapInt32
#define bswap_64 OSSwapInt64
#else
#include <byteswap.h>
#endif
#if DO_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
......
......@@ -27,6 +27,35 @@
#include "wext.h"
#include "util.h"
#if defined(__APPLE__)
int
wext_set_freq(int fd, const char* devname, int freq)
{
return 0;
}
int
wext_get_freq(int fd, const char* devname)
{
return 0;
}
int
wext_get_channels(int fd, const char* devname,
struct chan_freq channels[MAX_CHANNELS])
{
return 0;
}
#else
int
wext_set_freq(int fd, const char* devname, int freq)
{
......@@ -104,3 +133,5 @@ wext_get_channels(int fd, const char* devname,
}
return range.num_frequency;
}
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment