iedemam has uploaded this change for review.

View Change

meas_json: add command line option to specify binding ip

Change-Id: I3baa80c95b373e3f9483a2778bd195ff99bbdec0
---
M src/utils/meas_json.c
1 file changed, 71 insertions(+), 1 deletion(-)

git pull ssh://gerrit.osmocom.org:29418/osmo-bsc refs/changes/24/40224/1
diff --git a/src/utils/meas_json.c b/src/utils/meas_json.c
index 953b114..7184a4d 100644
--- a/src/utils/meas_json.c
+++ b/src/utils/meas_json.c
@@ -31,6 +31,8 @@

#include <netinet/in.h>

+#include <getopt.h>
+
#include <osmocom/core/socket.h>
#include <osmocom/core/msgb.h>
#include <osmocom/core/select.h>
@@ -41,6 +43,9 @@
#include <osmocom/bsc/gsm_data.h>
#include <osmocom/bsc/meas_feed.h>

+/* binding IP */
+static char *bind_ip = NULL;
+
static void print_meas_rep_uni_json(struct gsm_meas_rep_unidir *mru)
{
printf("\"RXL-FULL\":%d, \"RXL-SUB\":%d, ",
@@ -172,6 +177,68 @@
return 0;
}

+static void print_help(void)
+{
+ printf(" -h --help. This help text.\n");
+ printf(" -b --bind-ip. The IP to bind to.\n");
+}
+
+static void print_usage(void)
+{
+ printf("Usage: meas_json [options]\n");
+}
+
+static void handle_options(int argc, char** argv)
+{
+ int options_mask = 0;
+
+ /* disable explicit missing arguments error output from getopt_long */
+ opterr = 0;
+
+ while (1) {
+ int option_index = 0, c;
+ static struct option long_options[] = {
+ {"help", 0, 0, 'h'},
+ {"bind-ip", 0, 0, 'b'},
+ {0, 0, 0, 0}
+ };
+
+ c = getopt_long(argc, argv, "hb:",
+ long_options, &option_index);
+ if (c == -1)
+ break;
+
+ switch (c) {
+ case 'h':
+ print_usage();
+ print_help();
+ exit(0);
+ case 'b':
+ bind_ip = optarg;
+ break;
+ case '?':
+ if (optopt) {
+ printf("ERROR: missing mandatory argument "
+ "for `%s' option\n", argv[optind-1]);
+ } else {
+ printf("ERROR: unknown option `%s'\n",
+ argv[optind-1]);
+ }
+ print_usage();
+ print_help();
+ exit(EXIT_FAILURE);
+ break;
+ default:
+ /* ignore */
+ break;
+ }
+ }
+ if (argc > optind) {
+ fprintf(stderr, "Unsupported positional arguments on command line\n");
+ exit(2);
+ }
+}
+
/* default categories */
static struct log_info_cat default_categories[] = {
};
@@ -187,11 +254,14 @@
void *tall_ctx = talloc_named_const(NULL, 0, "meas_json");
osmo_init_logging2(tall_ctx, &meas_json_log_info);

+ bind_ip = NULL;
+ handle_options(argc, argv);
+
int rc;
struct osmo_fd udp_ofd;

udp_ofd.cb = udp_fd_cb;
- rc = osmo_sock_init_ofd(&udp_ofd, AF_INET, SOCK_DGRAM, IPPROTO_UDP, NULL, 8888, OSMO_SOCK_F_BIND);
+ rc = osmo_sock_init_ofd(&udp_ofd, AF_INET, SOCK_DGRAM, IPPROTO_UDP, bind_ip, 8888, OSMO_SOCK_F_BIND);
if (rc < 0)
exit(1);


To view, visit change 40224. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: newchange
Gerrit-Project: osmo-bsc
Gerrit-Branch: master
Gerrit-Change-Id: I3baa80c95b373e3f9483a2778bd195ff99bbdec0
Gerrit-Change-Number: 40224
Gerrit-PatchSet: 1
Gerrit-Owner: iedemam <michael@kapsulate.com>