aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPau Espin Pedrol <pespin@sysmocom.de>2018-03-12 20:11:28 +0100
committerHarald Welte <laforge@gnumonks.org>2018-03-13 08:40:03 +0000
commitb4d39eb67e320a862d4a44a98cf5febd347ce6d9 (patch)
tree91d34b8ecb31890809ff92c0a20ef9096d289563
parentc80b8763443c46dd5f02b3606bacdb6037362e6b (diff)
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
-rw-r--r--src/ipaccess/ipaccess-config.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/ipaccess/ipaccess-config.c b/src/ipaccess/ipaccess-config.c
index 8f527cd4a..b83846d32 100644
--- a/src/ipaccess/ipaccess-config.c
+++ b/src/ipaccess/ipaccess-config.c
@@ -858,6 +858,7 @@ int main(int argc, char **argv)
{
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 @@ int main(int argc, char **argv)
}
};
- 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 @@ int main(int argc, char **argv)
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");