summaryrefslogtreecommitdiff
path: root/pjlib-util/include
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2008-02-01 14:59:19 +0000
committerBenny Prijono <bennylp@teluu.com>2008-02-01 14:59:19 +0000
commit2c40b8a0f65babd72f03113040da9ee6d69e8372 (patch)
treed81aa1e84061a618cbd86db65ba6774fa157f0ce /pjlib-util/include
parent76cb47831c9da447e70b1338e406b6f817c70945 (diff)
Ticket #465: utility to read PCAP file and sample application to read RTP files from PCAP file, decode the payload, and write the PCM output to WAV file
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@1765 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjlib-util/include')
-rw-r--r--pjlib-util/include/pjlib-util.h2
-rw-r--r--pjlib-util/include/pjlib-util/pcap.h178
2 files changed, 180 insertions, 0 deletions
diff --git a/pjlib-util/include/pjlib-util.h b/pjlib-util/include/pjlib-util.h
index fcafcf1e..728d8fee 100644
--- a/pjlib-util/include/pjlib-util.h
+++ b/pjlib-util/include/pjlib-util.h
@@ -53,5 +53,7 @@
/* Old STUN */
#include <pjlib-util/stun_simple.h>
+/* PCAP */
+#include <pjlib-util/pcap.h>
#endif /* __PJLIB_UTIL_H__ */
diff --git a/pjlib-util/include/pjlib-util/pcap.h b/pjlib-util/include/pjlib-util/pcap.h
new file mode 100644
index 00000000..e27f5709
--- /dev/null
+++ b/pjlib-util/include/pjlib-util/pcap.h
@@ -0,0 +1,178 @@
+/* $Id$ */
+/*
+ * Copyright (C)2003-2007 Benny Prijono <benny@prijono.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+#ifndef __PJLIB_UTIL_PCAP_H__
+#define __PJLIB_UTIL_PCAP_H__
+
+/**
+ * @file pcap.h
+ * @brief Simple PCAP file reader
+ */
+
+#include <pj/types.h>
+
+PJ_BEGIN_DECL
+
+/**
+ * @defgroup PJ_PCAP Simple PCAP file reader
+ * @ingroup PJLIB_UTIL
+ * @{
+ * This module describes simple utility to read PCAP file. It is not intended
+ * to support all PCAP features (that's what libpcap is for!), but it can
+ * be useful for example to playback or stream PCAP contents.
+ */
+
+/**
+ * Enumeration to describe supported data link types.
+ */
+typedef enum pj_pcap_link_type
+{
+ /** Ethernet data link */
+ PJ_PCAP_LINK_TYPE_ETH = 1
+
+} pj_pcap_link_type;
+
+
+/**
+ * Enumeration to describe supported protocol types.
+ */
+typedef enum pj_pcap_proto_type
+{
+ /** UDP protocol */
+ PJ_PCAP_PROTO_TYPE_UDP = 17
+
+} pj_pcap_proto_type;
+
+
+/**
+ * This structure describes the filter to be used when reading packets from
+ * a PCAP file. The filter is used to select what packets can be returned
+ * to a read operation.
+ */
+typedef struct pj_pcap_filter
+{
+ /**
+ * Select data link type, or zero to include any supported data links.
+ */
+ pj_pcap_link_type link;
+
+ /**
+ * Select protocol, or zero to include all supported protocols.
+ */
+ pj_pcap_proto_type proto;
+
+ /**
+ * Specify source IP address of the packets, or zero to include packets
+ * from any IP addresses. Note that IP address here must be in
+ * network byte order.
+ */
+ pj_uint32_t ip_src;
+
+ /**
+ * Specify destination IP address of the packets, or zero to include packets
+ * destined to any IP addresses. Note that IP address here must be in
+ * network byte order.
+ */
+ pj_uint32_t ip_dst;
+
+ /**
+ * Specify source port of the packets, or zero to include packets with
+ * any source port number. Note that the port number must be in network
+ * byte order.
+ */
+ pj_uint16_t src_port;
+
+ /**
+ * Specify destination port of the packets, or zero to include packets with
+ * any destination port number. Note that the port number must be in network
+ * byte order.
+ */
+ pj_uint16_t dst_port;
+
+} pj_pcap_filter;
+
+
+/** Opaque declaration for PCAP file */
+typedef struct pj_pcap_file pj_pcap_file;
+
+
+/**
+ * Initialize filter with default values. The default value is to allow
+ * any packets.
+ *
+ * @param filter Filter to be initialized.
+ */
+PJ_DECL(void) pj_pcap_filter_default(pj_pcap_filter *filter);
+
+/**
+ * Open PCAP file.
+ *
+ * @param pool Pool to allocate memory.
+ * @param path File/path name.
+ * @param p_file Pointer to receive PCAP file handle.
+ *
+ * @return PJ_SUCCESS if file can be opened successfully.
+ */
+PJ_DECL(pj_status_t) pj_pcap_open(pj_pool_t *pool,
+ const char *path,
+ pj_pcap_file **p_file);
+
+/**
+ * Close PCAP file.
+ *
+ * @param file PCAP file handle.
+ *
+ * @return PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pj_pcap_close(pj_pcap_file *file);
+
+/**
+ * Configure filter for reading the file.
+ *
+ * @param file PCAP file handle.
+ * @param filter The filter.
+ *
+ * @return PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pj_pcap_set_filter(pj_pcap_file *file,
+ const pj_pcap_filter *filter);
+
+/**
+ * Read UDP payload from the next packet in the PCAP file.
+ *
+ * @param file PCAP file handle.
+ * @param udp_payload Buffer to receive the UDP payload.
+ * @param udp_payload_size On input, specify the size of the buffer.
+ * On output, it will be filled with the actual size
+ * of the payload as read from the packet.
+ *
+ * @return PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pj_pcap_read_udp(pj_pcap_file *file,
+ pj_uint8_t *udp_payload,
+ pj_size_t *udp_payload_size);
+
+
+/**
+ * @}
+ */
+
+PJ_END_DECL
+
+#endif /* __PJLIB_UTIL_PCAP_H__ */
+