diff options
Diffstat (limited to 'overlays/libdscp/src/libdscp.c')
-rw-r--r-- | overlays/libdscp/src/libdscp.c | 38 |
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 | |||
7 | void _init(void); | ||
8 | int (*sys_connect)(int sockfd, const struct sockaddr *addr, socklen_t addrlen); | ||
9 | int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen); | ||
10 | |||
11 | int dscp_val = 0; | ||
12 | |||
13 | void _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 | |||
30 | int 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 | } | ||