Numerous little changes to spandsp that haven't been pushed to Freeswitch for a

while. The only big changes are a majorly rewritten V.42 and V.42bis which are
now basically functional.
This commit is contained in:
Steve Underwood committed 2011-07-02 14:45:27 +08:00
1 parent 6f62f39139
commit d30e82e226
68 files changed
+2513 -2114

No files matched your search

+82 -13
View File
@@ -34,14 +34,17 @@
#include <inttypes.h>
#include <stdlib.h>
#include <stdio.h>
#if defined(HAVE_PCAP_H)
#include <pcap.h>
#endif
#include <netinet/in.h>
#include <netinet/udp.h>
#if defined(__HPUX) || defined(__CYGWIN) || defined(__FreeBSD__)
#if defined(__HPUX) || defined(__CYGWIN__) || defined(__FreeBSD__)
#include <netinet/in_systm.h>
#endif
#include <netinet/ip.h>
#ifndef __CYGWIN
#if !defined(__CYGWIN__)
#include <netinet/ip6.h>
#endif
#include <string.h>
@@ -55,7 +58,7 @@
#include "spandsp.h"
#include "pcap_parse.h"
#if defined(__HPUX) || defined(__DARWIN) || defined(__CYGWIN) || defined(__FreeBSD__)
#if defined(__HPUX) || defined(__DARWIN) || defined(__CYGWIN__) || defined(__FreeBSD__)
struct iphdr
{
@@ -90,15 +93,22 @@ typedef struct _ether_hdr
{
char ether_dst[6];
char ether_src[6];
u_int16_t ether_type; /* we only need the type, so we can determine, if the next header is IPv4 or IPv6 */
u_int16_t ether_type;
} ether_hdr;
typedef struct _null_hdr
{
uint32_t pf_type;
} null_hdr;
#if !defined(__CYGWIN__)
typedef struct _ipv6_hdr
{
char dontcare[6];
u_int8_t nxt_header; /* we only need the next header, so we can determine, if the next header is UDP or not */
char dontcare2[33];
} ipv6_hdr;
#endif
char errbuf[PCAP_ERRBUF_SIZE];
@@ -119,9 +129,14 @@ int pcap_scan_pkts(const char *file,
int total_pkts;
uint32_t pktlen;
ether_hdr *ethhdr;
null_hdr *nullhdr;
struct iphdr *iphdr;
#if !defined(__CYGWIN__)
ipv6_hdr *ip6hdr;
#endif
struct udphdr *udphdr;
int datalink;
int packet_type;
total_pkts = 0;
if ((pcap = pcap_open_offline(file, errbuf)) == NULL)
@@ -129,6 +144,15 @@ int pcap_scan_pkts(const char *file,
fprintf(stderr, "Can't open PCAP file '%s'\n", file);
return -1;
}
datalink = pcap_datalink(pcap);
/* DLT_EN10MB seems to apply to all forms of ethernet, not just the 10MB kind. */
if (datalink != DLT_EN10MB && datalink != DLT_NULL)
{
fprintf(stderr, "Unsupported data link type %d\n", datalink);
return -1;
}
printf("Datalink type %d\n", datalink);
pkthdr = NULL;
pktdata = NULL;
#if defined(HAVE_PCAP_NEXT_EX)
@@ -143,14 +167,43 @@ int pcap_scan_pkts(const char *file,
while ((pktdata = (uint8_t *) pcap_next(pcap, pkthdr)) != NULL)
{
#endif
ethhdr = (ether_hdr *) pktdata;
if (ntohs(ethhdr->ether_type) != 0x0800 /* IPv4 */
&&
ntohs(ethhdr->ether_type) != 0x86dd) /* IPv6 */
if (datalink == DLT_EN10MB)
{
ethhdr = (ether_hdr *) pktdata;
packet_type = ntohs(ethhdr->ether_type);
#if !defined(__CYGWIN__)
if (packet_type != 0x0800 /* IPv4 */
&&
packet_type != 0x86DD) /* IPv6 */
#else
if (packet_type != 0x0800) /* IPv4 */
#endif
{
continue;
}
iphdr = (struct iphdr *) ((uint8_t *) ethhdr + sizeof(*ethhdr));
}
else if (datalink == DLT_NULL)
{
nullhdr = (null_hdr *) pktdata;
if (nullhdr->pf_type != PF_INET && nullhdr->pf_type != PF_INET6)
continue;
iphdr = (struct iphdr *) ((uint8_t *) nullhdr + sizeof(*nullhdr));
}
else
{
continue;
}
iphdr = (struct iphdr *) ((uint8_t *) ethhdr + sizeof(*ethhdr));
#if 0
{
int i;
printf("--- %d -", pkthdr->caplen);
for (i = 0; i < pkthdr->caplen; i++)
printf(" %02x", pktdata[i]);
printf("\n");
}
#endif
#if !defined(__CYGWIN__)
if (iphdr && iphdr->version == 6)
{
/* ipv6 */
@@ -161,11 +214,12 @@ int pcap_scan_pkts(const char *file,
udphdr = (struct udphdr *) ((uint8_t *) ip6hdr + sizeof(*ip6hdr));
}
else
#endif
{
/* ipv4 */
if (iphdr->protocol != IPPROTO_UDP)
continue;
#if defined(__DARWIN) || defined(__CYGWIN) || defined(__FreeBSD__)
#if defined(__DARWIN) || defined(__CYGWIN__) || defined(__FreeBSD__)
udphdr = (struct udphdr *) ((uint8_t *) iphdr + (iphdr->ihl << 2) + 4);
pktlen = (uint32_t) ntohs(udphdr->uh_ulen);
#elif defined ( __HPUX)
@@ -176,24 +230,39 @@ int pcap_scan_pkts(const char *file,
pktlen = (uint32_t) ntohs(udphdr->len);
#endif
}
timing_update_handler(user_data, &pkthdr->ts);
if (src_addr && ntohl(iphdr->saddr) != src_addr)
continue;
#if defined(__DARWIN) || defined(__CYGWIN__) || defined(__FreeBSD__)
if (src_port && ntohs(udphdr->uh_sport) != src_port)
#else
if (src_port && ntohs(udphdr->source) != src_port)
#endif
continue;
if (dest_addr && ntohl(iphdr->daddr) != dest_addr)
continue;
#if defined(__DARWIN) || defined(__CYGWIN__) || defined(__FreeBSD__)
if (dest_port && ntohs(udphdr->uh_dport) != dest_port)
#else
if (dest_port && ntohs(udphdr->dest) != dest_port)
#endif
continue;
if (pkthdr->len != pkthdr->caplen)
{
fprintf(stderr, "Truncated packet - total len = %d, captured len = %d\n", pkthdr->len, pkthdr->caplen);
exit(2);
}
body = (const uint8_t *) udphdr;
body += sizeof(udphdr);
body_len = pktlen - sizeof(udphdr);
body += sizeof(struct udphdr);
body_len = pktlen - sizeof(struct udphdr);
packet_handler(user_data, body, body_len);
total_pkts++;
}
fprintf(stderr, "In pcap %s, npkts %d\n", file, total_pkts);
fprintf(stderr, "In pcap %s there were %d accepted packets\n", file, total_pkts);
pcap_close(pcap);
return 0;