mirror of
https://github.com/linux-msm/diag.git
synced 2026-02-25 13:11:48 -08:00
diag: Add command line argument processing
Use getopt to read user command line supplied arguments and allow for configuration of host socket address and port with -s option. Signed-off-by: Eyal Ilsar <eilsar@codeaurora.org> [bjorn: dropped debug mask flag and update commit message] Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
This commit is contained in:
committed by
Bjorn Andersson
parent
bd547fc50e
commit
cc92906b3b
40
diag.c
40
diag.c
@@ -1,4 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016-2017, The Linux Foundation. All rights reserved.
|
||||
* Copyright (c) 2016, Linaro Ltd.
|
||||
* All rights reserved.
|
||||
*
|
||||
@@ -38,6 +39,7 @@
|
||||
#include <fcntl.h>
|
||||
#include <libudev.h>
|
||||
#include <netdb.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -334,15 +336,51 @@ static int diag_sock_recv(int fd, void *data)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void usage(void)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"User space application for diag interface\n"
|
||||
"\n"
|
||||
"usage: diag [-hs]\n"
|
||||
"\n"
|
||||
"options:\n"
|
||||
" -h show this usage\n"
|
||||
" -s <socket address[:port]>\n"
|
||||
);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
struct diag_client *qxdm;
|
||||
char *host_address = "";
|
||||
int host_port = DEFAULT_SOCKET_PORT;
|
||||
char *token;
|
||||
int ret;
|
||||
int c;
|
||||
|
||||
for (;;) {
|
||||
c = getopt(argc, argv, "hs:");
|
||||
if (c < 0)
|
||||
break;
|
||||
switch (c) {
|
||||
case 's':
|
||||
host_address = strtok(strdup(optarg), ":");
|
||||
token = strtok(NULL, "");
|
||||
if (token)
|
||||
host_port = atoi(token);
|
||||
break;
|
||||
default:
|
||||
case 'h':
|
||||
usage();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
qxdm = malloc(sizeof(*qxdm));
|
||||
memset(qxdm, 0, sizeof(*qxdm));
|
||||
|
||||
ret = diag_sock_connect("10.0.1.45", 2500);
|
||||
ret = diag_sock_connect(host_address, host_port);
|
||||
if (ret < 0)
|
||||
err(1, "failed to connect to qxdm");
|
||||
qxdm->fd = ret;
|
||||
|
||||
3
diag.h
3
diag.h
@@ -1,4 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016-2017, The Linux Foundation. All rights reserved.
|
||||
* Copyright (c) 2016, Linaro Ltd.
|
||||
* All rights reserved.
|
||||
*
|
||||
@@ -33,6 +34,8 @@
|
||||
|
||||
#include "list.h"
|
||||
|
||||
#define DEFAULT_SOCKET_PORT 2500
|
||||
|
||||
#define BIT(x) (1 << (x))
|
||||
|
||||
#define DIAG_FEATURE_FEATURE_MASK_SUPPORT BIT(0)
|
||||
|
||||
Reference in New Issue
Block a user