[MERGED] osmo-bsc[master]: ipaccess-config: Improve handling of last parameter

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Tue Mar 13 08:40:06 UTC 2018


Harald Welte has submitted this change and it was merged.

Change subject: ipaccess-config: Improve handling of last parameter
......................................................................


ipaccess-config: Improve handling of last parameter

Check exact number of parameters to avoid explicit void params ("") to
be used as BTS IP by an incorrect caller.
Exit successfully if firmware analysis is requested and there's no BTS
IP provided (meaning no BTS set up is required).
Save BTS IP into bts_ip variable as using optind is tricky.
Use new bts_ip variable to print the IP of the BTS we are trying to
connect to.

Change-Id: I8071aaf2be217207261ad698f87344f7ca15ccc4
---
M src/ipaccess/ipaccess-config.c
1 file changed, 11 insertions(+), 8 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/src/ipaccess/ipaccess-config.c b/src/ipaccess/ipaccess-config.c
index 8f527cd..b83846d 100644
--- a/src/ipaccess/ipaccess-config.c
+++ b/src/ipaccess/ipaccess-config.c
@@ -858,6 +858,7 @@
 {
 	struct gsm_bts *bts;
 	struct sockaddr_in sin;
+	char *bts_ip;
 	int rc, option_index = 0, stream_id = 0xff;
 
 	tall_ctx_config = talloc_named_const(NULL, 0, "ipaccess-config");
@@ -982,15 +983,17 @@
 		}
 	};
 
-	if (firmware_analysis)
+	if (firmware_analysis) {
 		analyze_firmware(firmware_analysis);
-
-	if (optind >= argc) {
-		/* only warn if we have not done anything else */
-		if (!firmware_analysis)
-			fprintf(stderr, "you have to specify the IP address of the BTS. Use --help for more information\n");
+		if (argc == optind) /* Nothing more to do, exit successfully */
+			exit(EXIT_SUCCESS);
+	}
+	if (argc - optind != 1) {
+		fprintf(stderr, "you have to specify the IP address of the BTS. Use --help for more information\n");
 		exit(2);
 	}
+	bts_ip = argv[optind++];
+
 	libosmo_abis_init(tall_ctx_config);
 
 	bsc_gsmnet = bsc_network_init(tall_bsc_ctx);
@@ -1010,11 +1013,11 @@
 
 	ipac_nwl_init();
 
-	printf("Trying to connect to ip.access BTS ...\n");
+	printf("Trying to connect to ip.access BTS %s...\n", bts_ip);
 
 	memset(&sin, 0, sizeof(sin));
 	sin.sin_family = AF_INET;
-	inet_aton(argv[optind], &sin.sin_addr);
+	inet_aton(bts_ip, &sin.sin_addr);
 	rc = ia_config_connect(bts, &sin);
 	if (rc < 0) {
 		perror("Error connecting to the BTS");

-- 
To view, visit https://gerrit.osmocom.org/7262
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I8071aaf2be217207261ad698f87344f7ca15ccc4
Gerrit-PatchSet: 2
Gerrit-Project: osmo-bsc
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol <pespin at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder



More information about the gerrit-log mailing list