mirror of
https://bitbucket.org/ohhara/ohmulticastvideoscanner.git
synced 2025-06-12 02:16:20 +00:00
Add cmd arg parser.
This commit is contained in:
parent
560f3314dc
commit
e2927aac55
2
Makefile
2
Makefile
@ -1,4 +1,5 @@
|
||||
DEBUG = y
|
||||
OMVS_VERSION = 0.1
|
||||
|
||||
TARGET = omvs
|
||||
OBJS = \
|
||||
@ -9,6 +10,7 @@ RM = rm -rf
|
||||
PKGS = gstreamer-1.0
|
||||
CFLAGS = -I. `pkg-config --cflags $(PKGS)` `pcap-config --cflags`
|
||||
CFLAGS += -std=gnu99 -W -Wall -Wno-unused-result -pedantic
|
||||
CFLAGS += -DOMVS_VERSION=\"$(OMVS_VERSION)\"
|
||||
LDFLAGS = `pkg-config --libs $(PKGS)` `pcap-config --libs`
|
||||
|
||||
ifeq ($(DEBUG),y)
|
||||
|
76
omvs_main.c
76
omvs_main.c
@ -1,9 +1,77 @@
|
||||
#include <pcap.h>
|
||||
#include <gst/gst.h>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
static gchar *_omvs_net_dev;
|
||||
static gchar *_omvs_output = "omvs_out.txt";
|
||||
static gint _omvs_jobs = 1;
|
||||
static gint _omvs_sleep = 1000;
|
||||
static gint _omvs_timeout = 10000;
|
||||
|
||||
return 0;
|
||||
static GOptionEntry _omvs_entries[] =
|
||||
{
|
||||
{ "interface", 'i', 0, G_OPTION_ARG_STRING, &_omvs_net_dev,
|
||||
"Network device interface", "dev" },
|
||||
{ "jobs", 'j', 0, G_OPTION_ARG_INT, &_omvs_jobs,
|
||||
"Number of jobs", "jobs" },
|
||||
{ "output", 'o', 0, G_OPTION_ARG_FILENAME, &_omvs_output,
|
||||
"Output filename", "filename" },
|
||||
{ "sleep", 's', 0, G_OPTION_ARG_INT, &_omvs_sleep,
|
||||
"Sleep time(milliseconds) between scans", "ms" },
|
||||
{ "timeout", 't', 0, G_OPTION_ARG_INT, &_omvs_timeout,
|
||||
"Timeout time(milliseconds) in each scan", "ms" },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
typedef struct _OMVSPort {
|
||||
gint port;
|
||||
gint type;
|
||||
} OMVSPort;
|
||||
|
||||
typedef struct _OMVSIPAddr {
|
||||
guint32 addr;
|
||||
OMVSPort *ports;
|
||||
gint num_ports;
|
||||
} OMVSIPAddr;
|
||||
|
||||
typedef struct _OMVSScanner {
|
||||
OMVSIPAddr *ipaddrs;
|
||||
gint num_ipaddrs;
|
||||
gint scan_ipaddr_idx;
|
||||
gint scan_port_idx;
|
||||
} OMVSScanner;
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
GError *error = NULL;
|
||||
GOptionContext *context;
|
||||
int ret = 0;
|
||||
|
||||
context = g_option_context_new("<multicast ip address or net ... [#N]>");
|
||||
g_option_context_set_summary(context,
|
||||
"omvs scans to find free video streaming multicast ip addresses."
|
||||
);
|
||||
g_option_context_set_description(context,
|
||||
"Oh! Multicast Video Scanner " OMVS_VERSION " is"
|
||||
" Written by Taeho Oh <ohhara@postech.edu>.\n"
|
||||
"http://ohhara.sarang.net");
|
||||
g_option_context_add_main_entries(context, _omvs_entries, NULL);
|
||||
g_option_context_add_group(context, gst_init_get_option_group());
|
||||
if (!g_option_context_parse(context, &argc, &argv, &error)) {
|
||||
g_print("option parsing failed: %s\n", error->message);
|
||||
ret = -1;
|
||||
goto finish_return;
|
||||
}
|
||||
|
||||
if (argc < 2) {
|
||||
gchar *help_msg;
|
||||
help_msg = g_option_context_get_help(context, TRUE, NULL);
|
||||
g_print("%s", help_msg);
|
||||
g_free(help_msg);
|
||||
ret = -2;
|
||||
goto finish_return;
|
||||
}
|
||||
|
||||
finish_return:
|
||||
g_option_context_free(context);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user