diff options
author | Vadim Kochan <vadim4j@gmail.com> | 2017-06-12 23:55:37 +0300 |
---|---|---|
committer | Tobias Klauser <tklauser@distanz.ch> | 2017-06-19 11:05:42 +0200 |
commit | 6e3a87093dfcd8b4b62685e67b565d842c631da1 (patch) | |
tree | 5b6b1c93d8ed4bc8c2804ccccedfd5dac584378a | |
parent | 78c13b71e196a107eaa4ec00bb40b062929a6a88 (diff) |
trafgen: Fix output pcap file name length trimming
Trim output name to IFNAMSIZ only if the output is a networking device,
otherwise the following error occured if output name is greater then
IFNAMSIZ:
$ trafgen -n 1 '{ udp() }' -o /tmp/xxxxxxxxxxxxxx.pcap
No networking device or pcap file: /tmp/xxxxxxxxxx
Failed to open output device
Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
-rw-r--r-- | trafgen.c | 2 | ||||
-rw-r--r-- | trafgen_dev.c | 3 |
2 files changed, 3 insertions, 2 deletions
@@ -1084,7 +1084,7 @@ int main(int argc, char **argv) break; case 'd': case 'o': - ctx.device = xstrndup(optarg, IFNAMSIZ); + ctx.device = xstrdup(optarg); break; case 'H': prio_high = true; diff --git a/trafgen_dev.c b/trafgen_dev.c index cd99a0c..80e7481 100644 --- a/trafgen_dev.c +++ b/trafgen_dev.c @@ -174,8 +174,10 @@ struct dev_io *dev_io_open(const char *name, enum dev_io_mode_t mode) struct dev_io *dev = xzmalloc(sizeof(struct dev_io)); if (strstr(name, ".pcap")) { + dev->name = xstrdup(name); dev->ops = &dev_pcap_ops; } else if (device_mtu(name) > 0) { + dev->name = xstrndup(name, IFNAMSIZ); dev->ops = &dev_net_ops; } else { fprintf(stderr, "No networking device or pcap file: %s\n", name); @@ -189,7 +191,6 @@ struct dev_io *dev_io_open(const char *name, enum dev_io_mode_t mode) } } - dev->name = xstrdup(name); return dev; }; |