summaryrefslogtreecommitdiff
path: root/overlays/libdscp/src/libdscp.c
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2023-03-10 22:24:40 +0100
committerGregor Kleen <gkleen@yggdrasil.li>2023-03-10 22:24:40 +0100
commitc2fbcde4449ffaf798f9ba4f742b942d33a1c1c8 (patch)
tree71822737cbc6d60d1949a4b07a93dcaaff415bb0 /overlays/libdscp/src/libdscp.c
parente275caddb607b8ff37569be66f1bf44303919502 (diff)
downloadnixos-c2fbcde4449ffaf798f9ba4f742b942d33a1c1c8.tar
nixos-c2fbcde4449ffaf798f9ba4f742b942d33a1c1c8.tar.gz
nixos-c2fbcde4449ffaf798f9ba4f742b942d33a1c1c8.tar.bz2
nixos-c2fbcde4449ffaf798f9ba4f742b942d33a1c1c8.tar.xz
nixos-c2fbcde4449ffaf798f9ba4f742b942d33a1c1c8.zip
libdscp
Diffstat (limited to 'overlays/libdscp/src/libdscp.c')
-rw-r--r--overlays/libdscp/src/libdscp.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/overlays/libdscp/src/libdscp.c b/overlays/libdscp/src/libdscp.c
new file mode 100644
index 00000000..1bc9a16d
--- /dev/null
+++ b/overlays/libdscp/src/libdscp.c
@@ -0,0 +1,38 @@
1#include <dlfcn.h>
2#include <stdio.h>
3#include <stdlib.h>
4#include <errno.h>
5#include <arpa/inet.h>
6
7void _init(void);
8int (*sys_connect)(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
9int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
10
11int dscp_val = 0;
12
13void _init(void) {
14 const char* err;
15
16 char* env_dscp;
17
18 env_dscp = getenv("DSCP");
19
20 if (env_dscp)
21 dscp_val = atoi(env_dscp) << 2;
22
23 sys_connect = dlsym(RTLD_NEXT, "connect");
24
25 err = dlerror();
26 if (err != NULL)
27 (void)fprintf(stderr, "libdscp:dlsym (connect): %s\n", err);
28}
29
30int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen) {
31 int oerrno = errno;
32
33 setsockopt(sockfd, IPPROTO_IP, IP_TOS, &dscp_val, sizeof dscp_val);
34 setsockopt(sockfd, IPPROTO_IPV6, IPV6_TCLASS, &dscp_val, sizeof dscp_val);
35
36 errno = oerrno;
37 return sys_connect(sockfd, addr, addrlen);
38}