]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
DEV: tcploop: add minimal UDP support
authorWilly Tarreau <w@1wt.eu>
Tue, 7 Jun 2022 10:09:55 +0000 (12:09 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 8 Jun 2022 12:42:15 +0000 (14:42 +0200)
Passing "-u" turns to SOCK_DGRAM + IPPROTO_UDP, which still allows
bind/connect()/recv()/send() and can be convenient for experimentation
purposes.

dev/tcploop/tcploop.c

index 8433872f8f66dc42cb9a0d1eaa3463e4a0c95d06..89229f7a648bf7d66c9c284e47f50464b71e87b3 100644 (file)
@@ -72,6 +72,8 @@ static struct timeval start_time;
 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 @@ __attribute__((noreturn)) void usage(int code, const char *arg0)
            "\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 tcp_socket()
 {
        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 @@ int main(int argc, char **argv)
                        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