examples/linux_ip: send multiple packets from one input
#include <net/if.h>
#include <netinet/in.h>
#include <netinet/ip.h>
+#include <netinet/tcp.h>
#include <sched.h>
#include <stdarg.h>
#include <stdint.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/types.h>
+#include <sys/uio.h>
#include <unistd.h>
void HF_ITER(uint8_t**, size_t*);
@@ -107,6 +109,8 @@ int main(void)
if (setsockopt(tcp_sock, SOL_SOCKET, SO_NO_CHECK, (void*)&disable, sizeof(disable)) == -1) {
pfatal("setsockopt(tcp_sock, SOL_SOCKET, SO_NO_CHECK)");
}
+ const uint8_t md5s[TCP_MD5SIG_MAXKEYLEN] = { 0 };
+ setsockopt(tcp_sock, SOL_TCP, TCP_MD5SIG, (void*)md5s, sizeof(md5s));
if (setsockopt(sctp_sock, SOL_SOCKET, SO_NO_CHECK, (void*)&disable, sizeof(disable)) == -1) {
pfatal("setsockopt(sctp_sock, SOL_SOCKET, SO_NO_CHECK)");
}
@@ -182,7 +186,15 @@ int main(void)
HF_ITER(&buf, &len);
- write(fd, buf, len);
+ const size_t pkt_size = 1400UL;
+ size_t num_iov = 0;
+ if (len > 0) {
+ num_iov = ((len - 1) / pkt_size) + 1;
+ }
+ for (size_t i = 0; i < num_iov; i++) {
+ size_t off = pkt_size * i;
+ size_t sz = ((len - off) > pkt_size) ? pkt_size : (len - off);
+ write(fd, &buf[off], sz);
char b[1024 * 128];
for (;;) {
@@ -221,3 +233,4 @@ int main(void)
}
}
}
+}
