aboutsummaryrefslogtreecommitdiff
path: root/sshnodelay.c
blob: 03a4756a1764f8912fb2262db0aab45900fcda80 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#define _GNU_SOURCE
#include <dlfcn.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>

int connect(int sock, const struct sockaddr *addr, socklen_t addrlen)
{
    int (*next_connect)(int, const struct sockaddr *, socklen_t) =
        dlsym(RTLD_NEXT, "connect");
    int res = next_connect(sock, addr, addrlen);
    if (!res && addr->sa_family == AF_INET) {
        int opt = 1;
        setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, &opt, sizeof(opt));
    }
    return res;
}