Skip to content

Commit

Permalink
trafgen: Fix output pcap file name length trimming
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
vkochan authored and tklauser committed Jun 19, 2017
1 parent 78c13b7 commit 6e3a870
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion trafgen.c
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion trafgen_dev.c
Expand Up @@ -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);
Expand All @@ -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;
};

Expand Down

0 comments on commit 6e3a870

Please sign in to comment.