diff -rbu Libnet-1.1.1-RC-005-with-sandr8-patches/include/libnet/libnet-functions.h Libnet-1.1.1-RC-005-with-sandr8-patches-no_socket_buffer/include/libnet/libnet-functions.h
--- Libnet-1.1.1-RC-005-with-sandr8-patches/include/libnet/libnet-functions.h 2003-07-10 22:05:54.000000000 +0200
+++ Libnet-1.1.1-RC-005-with-sandr8-patches-no_socket_buffer/include/libnet/libnet-functions.h 2003-07-12 12:56:15.000000000 +0200
@@ -98,6 +98,12 @@
);
+int /* -1 on failure, buffer size on success */
+libnet_toggle_buffered_output(
+ libnet_t *, /* libnet context pointer */
+ long /* desired buffer size, LIBNET_NO_BUFFER for direct injection, LIBNET_ORIGINAL_BUFFER to set again the default value */
+ );
+
/*
* libnet_getdevice
*
diff -rbu Libnet-1.1.1-RC-005-with-sandr8-patches/include/libnet/libnet-structures.h Libnet-1.1.1-RC-005-with-sandr8-patches-no_socket_buffer/include/libnet/libnet-structures.h
--- Libnet-1.1.1-RC-005-with-sandr8-patches/include/libnet/libnet-structures.h 2003-06-13 05:22:02.000000000 +0200
+++ Libnet-1.1.1-RC-005-with-sandr8-patches-no_socket_buffer/include/libnet/libnet-structures.h 2003-07-12 13:01:32.000000000 +0200
@@ -167,6 +167,10 @@
char err_buf[LIBNET_ERRBUF_SIZE]; /* error buffer */
u_long total_size; /* total size */
+ unsigned long bt=0; /* initial socket buffer size, if modified */
+ socklen_t lt=sizeof(unsigned long); /* sizeof socket buffer size */
+#define LIBNET_NO_BUFFER 0
+#define LIBNET_ORIGINAL_BUFFER -1
};
typedef struct libnet_context libnet_t;
diff -rbu Libnet-1.1.1-RC-005-with-sandr8-patches/src/libnet_raw.c Libnet-1.1.1-RC-005-with-sandr8-patches-no_socket_buffer/src/libnet_raw.c
--- Libnet-1.1.1-RC-005-with-sandr8-patches/src/libnet_raw.c 2003-06-30 22:51:47.000000000 +0200
+++ Libnet-1.1.1-RC-005-with-sandr8-patches-no_socket_buffer/src/libnet_raw.c 2003-07-12 13:00:43.000000000 +0200
@@ -162,6 +162,69 @@
return (close(l->fd));
}
+int libnet_toggle_buffered_output(libnet_t *l, long buffered)
+{
+ unsigned long sndbuf = 0;
+ if (l == NULL)
+ {
+ return (-1);
+ }
+
+ if ( buffered < LIBNET_ORIGINAL_BUFFER )
+ {
+ snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
+ "%s(): parameter buffered is out of range\n", __FUNCTION__);
+ return(-1);
+ }
+
+ if ( l->bt == 0 ){
+ if ( 0 != getsockopt(l->fd, SOL_SOCKET, SO_SNDBUF, (void *)&(l->bt), &(l->lt)) )
+ {
+ snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
+ "%s(): getsockopt(): %s\n", __FUNCTION__, strerror(errno));
+ return(-1);
+ }
+#if (__linux__)
+ l->bt/=2;
+#endif
+ if ( buffered == LIBNET_ORIGINAL_BUFFER )
+ {
+ return( l->bt );
+ }
+ }
+
+ if( buffered==LIBNET_ORIGINAL_BUFFER )
+ {
+ sndbuf=l->bt;
+ }
+ else
+ {
+ sndbuf=buffered;
+ }
+
+ if ( 0 != setsockopt(l->fd, SOL_SOCKET, SO_SNDBUF, (void*)&sndbuf, sizeof(sndbuf)) )
+ {
+ snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
+ "%s(): setsockopt(): %s\n", __FUNCTION__, strerror(errno));
+ return(-1);
+ }
+ else
+ {
+ unsigned long bt;
+ socklen_t lt=sizeof(bt);
+
+ if ( 0 != getsockopt(l->fd, SOL_SOCKET, SO_SNDBUF, (void *)&(bt), &(lt)) )
+ {
+ snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
+ "%s(): getsockopt(): %s\n", __FUNCTION__, strerror(errno));
+ return(-1);
+ }
+#if (__linux__)
+ l->bt/=2;
+#endif
+ return(bt);
+ }
+}
/* EOF */
|