]> git.meshlink.io Git - utcp/commitdiff
Update test program to set a better default MTU.
authorGuus Sliepen <guus@sliepen.org>
Sun, 8 Mar 2020 19:56:28 +0000 (20:56 +0100)
committerGuus Sliepen <guus@sliepen.org>
Sun, 8 Mar 2020 22:49:22 +0000 (23:49 +0100)
test.c

diff --git a/test.c b/test.c
index 2784649bb5ef8a8767b079cb5bf2797099cb9386..7dd5d248836bf6342e6049c1701bd1deb94e2e95 100644 (file)
--- a/test.c
+++ b/test.c
@@ -31,7 +31,7 @@ double dropout;
 long total_out;
 long total_in;
 FILE *reference;
-long mtu = 1300;
+long mtu = 0;
 
 char *reorder_data;
 size_t reorder_len;
@@ -134,6 +134,21 @@ ssize_t do_send(struct utcp *utcp, const void *data, size_t len) {
        return result;
 }
 
+static void set_mtu(struct utcp *u, int s) {
+       if(!mtu) {
+               socklen_t optlen = sizeof(mtu);
+               getsockopt(s, IPPROTO_IP, IP_MTU, &mtu, &optlen);
+       }
+
+       if(!mtu || mtu == 65535) {
+               mtu = 1500;
+       }
+
+       fprintf(stderr, "Using MTU %lu\n", mtu);
+
+       utcp_set_mtu(u, mtu ? mtu - 48 : 1300);
+}
+
 int main(int argc, char *argv[]) {
        srand(time(NULL));
        srand48(time(NULL));
@@ -240,10 +255,10 @@ int main(int argc, char *argv[]) {
                return 1;
        }
 
-       utcp_set_mtu(u, mtu);
        utcp_set_user_timeout(u, 10);
 
        if(!server) {
+               set_mtu(u, s);
                c = utcp_connect_ex(u, 1, do_recv, NULL, flags);
        }
 
@@ -318,10 +333,12 @@ int main(int argc, char *argv[]) {
                                break;
                        }
 
-                       if(!connected)
+                       if(!connected) {
                                if(!connect(s, (struct sockaddr *)&ss, sl)) {
                                        connected = true;
+                                       set_mtu(u, s);
                                }
+                       }
 
                        inpktno++;