ref: 8d9f9e8c58a7ee75f49e92df1ebd8e5b2ef2f5e3
parent: bcafdc2bb6e17f5d2eda26f54f2bd04cb77362a4
author: Ralph Giles <[email protected]>
date: Fri Aug 31 19:56:24 EDT 2012
Add basic option parsing to opusrtp and a manpage. So far opusrtp only has the --sniff function, but we now require --sniff to activate it, and add --help, --version and a manpage to document what does and doesn't work.
--- /dev/null
+++ b/man/opusrtp.1
@@ -1,0 +1,56 @@
+.\" Process this file with
+.\" groff -man -Tascii opusrtp.1
+.\"
+.TH opusrtp 1 2012-08-31 "Xiph.Org Foundation" "opus-tools"
+
+.SH NAME
+opusrtp \- encapsulate Opus audio in RTP
+
+.SH SYNOPSIS
+.B opusrtp
+[
+.B -hV
+]
+[
+.B --sniff
+]
+
+.SH DESCRIPTION
+
+.B opusrtp
+Demonstration tool for sending and receiving Opus audio data in RTP,
+used for interactive applications on the internet.
+
+Currently the
+.B --sniff
+mode is all that's implemented.
+
+.SH "OPTIONS"
+.IP "-h, --help"
+Print help message
+.IP "-V, --version"
+Display version information
+.IP "--quiet"
+Suppresses program output
+.IP "--sniff"
+Sniff the network for active RTP sessions and save them to .opus
+files. This can be useful for debugging other Opus RTP implementations.
+For this function to work, the program must be run with superuser
+privileges.
+
+.SH AUTHORS
+.br
+Ralph Giles <[email protected]>
+
+.SH BUGS
+
+Only the sniff mode is implemented; the tool should do normal unicast
+and multicast send/receive.
+
+The sniff mode should allow specifying device/host/port/payload type
+to limit capture. All that is hard-coded.
+
+.SH SEE ALSO
+.BR opusdec (1),
+.BR opusenc (1),
+.BR opusinfo (1)
--- a/src/opusrtp.c
+++ b/src/opusrtp.c
@@ -39,6 +39,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
+#include <getopt.h>
#ifdef HAVE_PCAP
#include <pcap.h>
@@ -518,11 +520,64 @@
}
#endif /* HAVE_PCAP */
+void opustools_version(void)
+{
+ printf("opusrtp %s %s\n", PACKAGE, VERSION);
+ printf("Copyright (C) 2012 Xiph.Org Foundation\n");
+}
+
+void usage(char *exe)
+{
+ printf("Usage: %s [--sniff]\n", exe);
+ printf("\n");
+ printf("Receives Opus audio RTP streams.\n");
+ printf("\nGeneral Options:\n");
+ printf(" -h, --help This help\n");
+ printf(" -V, --version Version information\n");
+ printf(" -q, --quiet Suppress status output\n");
+ printf(" --sniff Sniff and record Opus RTP streams\n");
+}
+
int main(int argc, char *argv[])
{
+ int option, i;
+ struct option long_options[] = {
+ {"help", no_argument, NULL, 'h'},
+ {"version", no_argument, NULL, 'V'},
+ {"quiet", no_argument, NULL, 'q'},
+ {"sniff", no_argument, NULL, 0},
+ {0, 0, 0, 0}
+ };
+
+ /* process command line arguments */
+ while ((option = getopt_long(argc, argv, "hVq", long_options, &i)) != -1) {
+ switch (option) {
+ case 0:
+ if (!strcmp(long_options[i].name, "sniff")) {
#ifdef HAVE_PCAP
- sniff("lo");
+ sniff("lo");
+#else
+ fprintf(stderr, "pcap support disabled, sorry.\n");
#endif
+ } else {
+ fprintf(stderr, "Unknown option - try %s --help.\n", argv[0]);
+ return -1;
+ }
+ break;
+ case 'V':
+ opustools_version();
+ return 0;
+ case 'q':
+ break;
+ case 'h':
+ usage(argv[0]);
+ return 0;
+ case '?':
+ default:
+ usage(argv[0]);
+ return 1;
+ }
+ }
return 0;
}