From 79ff87bd02d21379c33496c1fa50a89312773140 Mon Sep 17 00:00:00 2001 From: Beniamin Sandu Date: Fri, 23 Sep 2022 14:10:07 +0200 Subject: libnet_raw: don't change the TX buffer size for raw sockets Instead of trying to set the max TX buffer size for every raw socket, export this to a separate interface that can be used when needed, called libnet_setfd_max_sndbuf(). Signed-off-by: Beniamin Sandu --- src/libnet_init.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/libnet_init.c') diff --git a/src/libnet_init.c b/src/libnet_init.c index fe5b613..5350aab 100644 --- a/src/libnet_init.c +++ b/src/libnet_init.c @@ -172,6 +172,26 @@ libnet_getfd(libnet_t *l) return (int)(l->fd); } +#ifdef SO_SNDBUF +int +libnet_setfd_max_sndbuf(libnet_t *l, int max_bytes) +{ + if (l == NULL) + return (-1); + + /* Try to set the buffer size to max_bytes */ + if (setsockopt(l->fd, SOL_SOCKET, SO_SNDBUF, &max_bytes, sizeof(max_bytes)) < 0) + { + snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, + "%s(): set SO_SNDBUF failed: %s", + __func__, strerror(errno)); + return (-1); + } + + return (0); +} +#endif /* SO_SNDBUF */ + const char * libnet_getdevice(libnet_t *l) { -- cgit v1.2.1