DEV: tcploop: add minimal UDP support
Passing "-u" turns to SOCK_DGRAM + IPPROTO_UDP, which still allows
bind/connect()/recv()/send() and can be convenient for experimentation
purposes.
diff --git a/dev/tcploop/tcploop.c b/dev/tcploop/tcploop.c
index 8433872..89229f7 100644
--- a/dev/tcploop/tcploop.c
+++ b/dev/tcploop/tcploop.c
@@ -72,6 +72,8 @@
static int showtime;
static int verbose;
static int pid;
+static int sock_type = SOCK_STREAM;
+static int sock_proto = IPPROTO_TCP;
/* display the message and exit with the code */
@@ -95,6 +97,7 @@
"\n"
"options :\n"
" -v : verbose\n"
+ " -u : use UDP instead of TCP (limited)\n"
" -t|-tt|-ttt : show time (msec / relative / absolute)\n"
"actions :\n"
" A[<count>] : Accepts <count> incoming sockets and closes count-1\n"
@@ -338,7 +341,7 @@
{
int sock;
- sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+ sock = socket(AF_INET, sock_type, sock_proto);
if (sock < 0) {
perror("socket()");
return -1;
@@ -806,6 +809,10 @@
showtime += 3;
else if (strcmp(argv[0], "-v") == 0)
verbose ++;
+ else if (strcmp(argv[0], "-u") == 0) {
+ sock_type = SOCK_DGRAM;
+ sock_proto = IPPROTO_UDP;
+ }
else if (strcmp(argv[0], "--") == 0)
break;
else