diff options
author | Bui Nguyen Quoc Thanh <49302843+thanhbnq@users.noreply.github.com> | 2022-10-26 15:14:49 +0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-26 10:14:49 +0200 |
commit | 71b131daf2c13477470289cc8faef319e2ff5f2f (patch) | |
tree | f7669a8db4bbf363989b3882c5ef64f53764cfef /src/console | |
parent | 948ed9928d933bbbfbb704ab0cc2296cb4333055 (diff) | |
download | DLT-daemon-71b131daf2c13477470289cc8faef319e2ff5f2f.tar.gz |
dlt-receive: set host interface and allow multiple udp multicast addresses (#420)
* dlt-receive: Allow listening to multiple udp multicast addresses
Multiple udp multicast addresses can now be specified, e.g:
dlt-receive -u 224.255.1.1 225.255.1.1
Signed-off-by: Alexander Irion <alexander_irion@mentor.com>
* dlt-receive: Add option to set host interface address
Signed-off-by: Alexander Irion <alexander_irion@mentor.com>
Signed-off-by: Alexander Irion <alexander.irion@partner.bmw.de>
Co-authored-by: Alexander Irion <alexander_irion@mentor.com>
Diffstat (limited to 'src/console')
-rw-r--r-- | src/console/dlt-receive.c | 57 |
1 files changed, 38 insertions, 19 deletions
diff --git a/src/console/dlt-receive.c b/src/console/dlt-receive.c index c985447..dec4713 100644 --- a/src/console/dlt-receive.c +++ b/src/console/dlt-receive.c @@ -135,6 +135,7 @@ typedef struct { DltFile file; DltFilter filter; int port; + char *ifaddr; } DltReceiveData; /** @@ -161,6 +162,7 @@ void usage() printf(" -R Enable resync serial header\n"); printf(" -y Serial device mode\n"); printf(" -u UDP multicast mode\n"); + printf(" -i addr Host interface address\n"); printf(" -b baudrate Serial device baudrate (Default: 115200)\n"); printf(" -e ecuid Set ECU ID (Default: RECV)\n"); printf(" -o filename Output messages in new DLT file\n"); @@ -314,28 +316,13 @@ void dlt_receive_close_output_file(DltReceiveData *dltdata) int main(int argc, char *argv[]) { DltReceiveData dltdata; + memset(&dltdata, 0, sizeof(dltdata)); int c; int index; /* Initialize dltdata */ - dltdata.aflag = 0; - dltdata.sflag = 0; - dltdata.xflag = 0; - dltdata.mflag = 0; - dltdata.vflag = 0; - dltdata.yflag = 0; - dltdata.uflag = 0; - dltdata.ovalue = 0; - dltdata.ovaluebase = 0; - dltdata.fvalue = 0; - dltdata.jvalue = 0; - dltdata.evalue = 0; - dltdata.bvalue = 0; - dltdata.sendSerialHeaderFlag = 0; - dltdata.resyncSerialHeaderFlag = 0; dltdata.climit = -1; /* default: -1 = unlimited */ dltdata.ohandle = -1; - dltdata.totalbytes = 0; dltdata.part_num = -1; dltdata.port = 3490; @@ -354,7 +341,7 @@ int main(int argc, char *argv[]) /* Fetch command line arguments */ opterr = 0; - while ((c = getopt (argc, argv, "vashSRyuxmf:j:o:e:b:c:p:")) != -1) + while ((c = getopt (argc, argv, "vashSRyuxmf:j:o:e:b:c:p:i:")) != -1) switch (c) { case 'v': { @@ -406,6 +393,11 @@ int main(int argc, char *argv[]) dltdata.uflag = 1; break; } + case 'i': + { + dltdata.ifaddr = optarg; + break; + } case 'f': { dltdata.fvalue = optarg; @@ -506,11 +498,31 @@ int main(int argc, char *argv[]) if (dltclient.mode == DLT_CLIENT_MODE_TCP || dltclient.mode == DLT_CLIENT_MODE_UDP_MULTICAST) { dltclient.port = dltdata.port; - for (index = optind; index < argc; index++) - if (dlt_client_set_server_ip(&dltclient, argv[index]) == -1) { + + unsigned int servIPLength = 1; // Counting the terminating 0 byte + for (index = optind; index < argc; index++) { + servIPLength += strlen(argv[index]); + if (index > optind) { + servIPLength++; // For the comma delimiter + } + } + if (servIPLength > 1) { + char* servIPString = malloc(servIPLength); + strcpy(servIPString, argv[optind]); + + for (index = optind + 1; index < argc; index++) { + strcat(servIPString, ","); + strcat(servIPString, argv[index]); + } + + int retval = dlt_client_set_server_ip(&dltclient, servIPString); + free(servIPString); + + if (retval == -1) { fprintf(stderr, "set server ip didn't succeed\n"); return -1; } + } if (dltclient.servIP == 0) { /* no hostname selected, show usage and terminate */ @@ -519,6 +531,13 @@ int main(int argc, char *argv[]) dlt_client_cleanup(&dltclient, dltdata.vflag); return -1; } + + if (dltdata.ifaddr != 0) { + if (dlt_client_set_host_if_address(&dltclient, dltdata.ifaddr) != DLT_RETURN_OK) { + fprintf(stderr, "set host interface address didn't succeed\n"); + return -1; + } + } } else { for (index = optind; index < argc; index++) |