Fork me on GitHub
Loading...
Searching...
No Matches
Data Structures | Macros | Typedefs | Functions
text2pcap.c File Reference

Dumping of RTP/RTCP packets to text2pcap or pcap format. More...

#include <errno.h>
#include <sys/time.h>
#include <arpa/inet.h>
#include <endian.h>
#include "text2pcap.h"
#include "debug.h"
#include "utils.h"
Include dependency graph for text2pcap.c:

Data Structures

struct  janus_text2pcap_global_header
 
struct  janus_text2pcap_packet_header
 
struct  janus_text2pcap_ethernet_header
 
struct  janus_text2pcap_ip_header
 
struct  janus_text2pcap_udp_header
 

Macros

#define CASE_STR(name)   case name: return #name
 

Typedefs

typedef struct janus_text2pcap_global_header janus_text2pcap_global_header
 
typedef struct janus_text2pcap_packet_header janus_text2pcap_packet_header
 
typedef struct janus_text2pcap_ethernet_header janus_text2pcap_ethernet_header
 
typedef struct janus_text2pcap_ip_header janus_text2pcap_ip_header
 
typedef struct janus_text2pcap_udp_header janus_text2pcap_udp_header
 

Functions

const char * janus_text2pcap_packet_string (janus_text2pcap_packet type)
 
janus_text2pcapjanus_text2pcap_create (const char *dir, const char *filename, int truncate, gboolean text)
 Create a text2pcap recorder.
 
int janus_text2pcap_dump (janus_text2pcap *instance, janus_text2pcap_packet type, gboolean incoming, char *buf, int len, const char *format,...)
 
int janus_text2pcap_close (janus_text2pcap *instance)
 Close a text2pcap recorder.
 
void janus_text2pcap_free (janus_text2pcap *instance)
 Free a text2pcap instance.
 

Detailed Description

Dumping of RTP/RTCP packets to text2pcap or pcap format.

Author
Lorenzo Miniero loren.nosp@m.zo@m.nosp@m.eetec.nosp@m.ho.c.nosp@m.om

Implementation of a simple helper utility that can be used to dump incoming and outgoing RTP/RTCP packets to pcap or text2pcap format. Saving to pcap natively can be more efficient but will lack some features, as the target will be a legacy (v2.4) .pcap file and not a .pcapng one. When saving to a text file, instead, the resulting file can be passed to the text2pcap application in order to get a .pcap or .pcapng file that can be analyzed via Wireshark or similar applications, e.g.:

/usr/sbin/text2pcap -D -n -l 1 -i 17 -u 1000,2000 -t '%H:%M:%S.' dump.txt dump.pcapng
/usr/sbin/wireshark dump.pcapng

While plugins are free to take advantage of this functionality, it's been specifically added to make debugging from the core easier. Enabling and disabling the dump of RTP/RTCP packets for the media traffic of a specific handle is done via the Admin/Monitor API so check the documentation of that section for more details. Notice that starting a new dump on an existing filename will result in the new packets to be appended.

Note
Motivation and inspiration for this work came from a similar effort recently done in Firefox, and from a discussion related to a blog post on WebRTC hacks, where guidelines are provided with respect to debugging based on pcap files.

Core

Macro Definition Documentation

◆ CASE_STR

#define CASE_STR ( name)    case name: return #name

Typedef Documentation

◆ janus_text2pcap_ethernet_header

typedef struct janus_text2pcap_ethernet_header janus_text2pcap_ethernet_header

◆ janus_text2pcap_global_header

typedef struct janus_text2pcap_global_header janus_text2pcap_global_header

◆ janus_text2pcap_ip_header

typedef struct janus_text2pcap_ip_header janus_text2pcap_ip_header

◆ janus_text2pcap_packet_header

typedef struct janus_text2pcap_packet_header janus_text2pcap_packet_header

◆ janus_text2pcap_udp_header

typedef struct janus_text2pcap_udp_header janus_text2pcap_udp_header

Function Documentation

◆ janus_text2pcap_close()

int janus_text2pcap_close ( janus_text2pcap * instance)

Close a text2pcap recorder.

Parameters
[in]instanceInstance of the janus_text2pcap recorder to close
Returns
0 in case of success, a negative integer otherwise

◆ janus_text2pcap_create()

janus_text2pcap * janus_text2pcap_create ( const char * dir,
const char * filename,
int truncate,
gboolean text )

Create a text2pcap recorder.

Note
If no target directory is provided, the current directory will be used. If no filename is passed, a random filename will be used.
Parameters
[in]dirPath of the directory to save the recording into (will try to create it if it doesn't exist)
[in]filenameFilename to use for the recording
[in]truncateNumber of bytes to truncate each packet at (0 to not truncate at all)
[in]textWhether we'll save as text, or directly to pcap
Returns
A valid janus_text2pcap instance in case of success, NULL otherwise

◆ janus_text2pcap_dump()

int janus_text2pcap_dump ( janus_text2pcap * instance,
janus_text2pcap_packet type,
gboolean incoming,
char * buf,
int len,
const char * format,
... )

◆ janus_text2pcap_free()

void janus_text2pcap_free ( janus_text2pcap * instance)

Free a text2pcap instance.

Parameters
[in]instanceInstance of the janus_text2pcap recorder to free

◆ janus_text2pcap_packet_string()

const char * janus_text2pcap_packet_string ( janus_text2pcap_packet type)