diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/libnet_init.c | 20 | ||||
-rw-r--r-- | src/libnet_raw.c | 37 |
2 files changed, 20 insertions, 37 deletions
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) { diff --git a/src/libnet_raw.c b/src/libnet_raw.c index 5195b75..f74d7b0 100644 --- a/src/libnet_raw.c +++ b/src/libnet_raw.c @@ -79,40 +79,6 @@ static int libnet_finish_setup_socket(libnet_t *l) #endif unsigned len; -#ifdef SO_SNDBUF - -/* - * man 7 socket - * - * Sets and gets the maximum socket send buffer in bytes. - * - * Taken from libdnet by Dug Song - */ - len = sizeof(n); - if (getsockopt(l->fd, SOL_SOCKET, SO_SNDBUF, &n, &len) < 0) - { - snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, - "%s(): get SO_SNDBUF failed: %s", - __func__, strerror(errno)); - goto bad; - } - - for (n += 128; n < 1048576; n += 128) - { - if (setsockopt(l->fd, SOL_SOCKET, SO_SNDBUF, &n, len) < 0) - { - if (errno == ENOBUFS) - { - break; - } - snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, - "%s(): set SO_SNDBUF failed: %s", - __func__, strerror(errno)); - goto bad; - } - } -#endif - #ifdef SO_BROADCAST /* * man 7 socket @@ -146,9 +112,6 @@ bad: return (-1); } - - - int libnet_open_raw4(libnet_t *l) { |