List of commits:
Subject Hash Author Date (UTC)
Added support to force TOS by using env var FORCE_NET_TOS. 319cfbee315a0c6889791b122fdb8069aa2ffdf1 Catalin(ux) M. BOIE 2010-11-07 23:14:23
No need for duilder_release. I will use a global one. 15a59294aa3922e58bff8aaa9de7cc06dc44fe1e Catalin(ux) M. BOIE 2010-10-27 20:43:15
TODO in. 9ea8407b8a2767debcf7597bbfc1bddfe44c78eb Catalin(ux) M. BOIE 2010-10-27 20:21:13
Typo. 2282d895e91cf2b02a7b67d933af2c68db5798b6 Catalin(ux) M. BOIE 2010-10-27 19:54:40
Aded license information to README file. fe8071fd2d9f912136fb7fa22f289ddc63cf0f14 Catalin(ux) M. BOIE 2010-10-27 19:46:48
Improved description. 1f17958175bf3f2a656a365fdafca21118737cf1 Catalin(ux) M. BOIE 2010-10-27 19:43:33
Silence compiler useless warning. 117e169b70197ac7e62907f855eb475a0a43fe07 Catalin(ux) M. BOIE 2010-10-27 19:24:45
Bump up the version to 0.4. 59371ee292d38d489719f105a9ff16c923be09d0 Catalin(ux) M. BOIE 2010-10-27 19:16:53
Corrected documentation. cf9d535fcb9d433b8a66c3c5283d9d9d64ae7240 Catalin(ux) M. BOIE 2010-10-27 19:16:29
Nothing to install in /usr/bin! d6eecf1bb4cfcf3d4bc08d8e87cac05f567fd51c Catalin(ux) M. BOIE 2010-10-27 19:13:54
Bump version to 0.3. 3531182e79370861cf73083948494eb4a8ced776 Catalin(ux) M. BOIE 2010-10-27 19:13:01
Store latest version/revision into LATEST_VER/REV for easy web update. 2d3036b2a52f2825cb7be39dc3039c0c6637b4f0 Catalin(ux) M. BOIE 2010-10-27 13:03:22
Fixed install command. 85e4aa9778fa4f10df5f313aff4444f7ec1d2619 Catalin(ux) M. BOIE 2010-10-27 12:29:47
First version. 2d1ffe53a6cfd146f91157baeadb101a59fdd556 Catalin(ux) M. BOIE 2010-10-27 12:21:37
Commit 319cfbee315a0c6889791b122fdb8069aa2ffdf1 - Added support to force TOS by using env var FORCE_NET_TOS.
Author: Catalin(ux) M. BOIE
Author date (UTC): 2010-11-07 23:14
Committer name: Catalin(ux) M. BOIE
Committer date (UTC): 2010-11-07 23:14
Parent(s): 15a59294aa3922e58bff8aaa9de7cc06dc44fe1e
Signing key:
Tree: d543e46d3c1001d15248092050ff731021a75b5e
File Lines added Lines deleted
duilder 1 1
force_bind.c 74 7
test_bind.c 6 0
File duilder changed (mode: 100755) (index 458452c..d93ac48)
... ... if [ -z "${GIT_DEST}" ]; then
292 292 fi fi
293 293
294 294 # export variables - just in case a script cares # export variables - just in case a script cares
295 export PRJ VER REV EXPORT_PATH EXPORT_GIT GIT_PUSH GIT_DEST SRPMS_DEST LICENSE
295 export PRJ VER REV EXPORT_PATH EXPORT_GIT GIT_PUSH GIT_DEST SRPM_DEST LICENSE
296 296
297 297 if [ -z "${PRJ}" ]; then if [ -z "${PRJ}" ]; then
298 298 echo "ERROR: PRJ= parameter is missing." echo "ERROR: PRJ= parameter is missing."
File force_bind.c changed (mode: 100644) (index 8e92748..a5207a6)
30 30 #include <arpa/inet.h> #include <arpa/inet.h>
31 31
32 32
33 static int (*old_bind)(int sockfd, const struct sockaddr *addr, socklen_t addrlen) = NULL;
34 static char *force_address = NULL;
35 static int force_port = -1;
33 static int (*old_bind)(int sockfd, const struct sockaddr *addr, socklen_t addrlen) = NULL;
34 static int (*old_setsockopt)(int sockfd, int level, int optname, const void *optval, socklen_t optlen);
35 static int (*old_socket)(int domain, int type, int protocol);
36 static char *force_address = NULL;
37 static int force_port = -1;
38 static char set_tos = 0;
39 static unsigned char tos;
36 40
37 41 /* Functions */ /* Functions */
38 42
 
... ... void init(void)
47 51 inited = 1; inited = 1;
48 52
49 53 x = getenv("FORCE_BIND_ADDRESS"); x = getenv("FORCE_BIND_ADDRESS");
50 if (x != NULL)
54 if (x != NULL) {
51 55 force_address = x; force_address = x;
56 syslog(LOG_INFO, "force_bind: Force bind to address %s.\n",
57 force_address);
58 }
52 59
53 60 x = getenv("FORCE_BIND_PORT"); x = getenv("FORCE_BIND_PORT");
54 if (x != NULL)
61 if (x != NULL) {
55 62 force_port = strtol(x, NULL, 10); force_port = strtol(x, NULL, 10);
63 syslog(LOG_INFO, "force_bind: Force bind to port %d.\n",
64 force_port);
65 }
56 66
57 syslog(LOG_INFO, "force_bind: Force bind to %s/%d.\n",
58 force_address, force_port);
67 /* tos */
68 x = getenv("FORCE_NET_TOS");
69 if (x != NULL) {
70 set_tos = 1;
71 tos = strtoul(x, NULL, 0);
72 syslog(LOG_INFO, "force_bind: Force TOS to %hhu.\n",
73 tos);
74 }
59 75
60 76 old_bind = dlsym(RTLD_NEXT, "bind"); old_bind = dlsym(RTLD_NEXT, "bind");
61 77 if (old_bind == NULL) { if (old_bind == NULL) {
62 78 syslog(LOG_ERR, "force_bind: Cannot resolve 'bind'!\n"); syslog(LOG_ERR, "force_bind: Cannot resolve 'bind'!\n");
63 79 exit(1); exit(1);
64 80 } }
81
82 old_setsockopt = dlsym(RTLD_NEXT, "setsockopt");
83 if (old_setsockopt == NULL) {
84 syslog(LOG_ERR, "force_bind: Cannot resolve 'setsockopt'!\n");
85 exit(1);
86 }
87
88 old_socket = dlsym(RTLD_NEXT, "socket");
89 if (old_socket == NULL) {
90 syslog(LOG_ERR, "force_bind: Cannot resolve 'socket'!\n");
91 exit(1);
92 }
65 93 } }
66 94
67 95 int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen) int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen)
 
... ... int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen)
111 139
112 140 return old_bind(sockfd, &new, addrlen); return old_bind(sockfd, &new, addrlen);
113 141 } }
142
143 int setsockopt(int sockfd, int level, int optname, const void *optval,
144 socklen_t optlen)
145 {
146 init();
147
148 switch (optname) {
149 case IP_TOS:
150 if (set_tos == 1) {
151 syslog(LOG_INFO, "force_bind: changing TOS from %hhu to %hhu.\n",
152 *(char *)optval, tos);
153 optval = &tos;
154 }
155 break;
156 }
157
158
159 return old_setsockopt(sockfd, level, optname, optval, optlen);
160 }
161
162 /*
163 * 'socket' is hijacked to be able to call setsockopt on it.
164 */
165 int socket(int domain, int type, int protocol)
166 {
167 int sock;
168
169 init();
170
171 sock = old_socket(domain, type, protocol);
172 if (sock == -1)
173 return -1;
174
175 if (set_tos == 1)
176 setsockopt(sock, IPPROTO_IP, IP_TOS, &tos, 1);
177
178 return sock;
179 }
180
File test_bind.c changed (mode: 100644) (index 117d3cf..ef56403)
... ... int main(int argc, char *argv[])
14 14 socklen_t sa_len; socklen_t sa_len;
15 15 int port = 4444; int port = 4444;
16 16 char junk[128]; char junk[128];
17 unsigned char tos;
17 18
18 19 sock = socket(AF_INET, SOCK_STREAM, 0); sock = socket(AF_INET, SOCK_STREAM, 0);
19 20 if (sock == -1) { if (sock == -1) {
 
... ... int main(int argc, char *argv[])
46 47 inet_ntop(sa2.sin_family, &sa2.sin_addr, junk, sa_len), inet_ntop(sa2.sin_family, &sa2.sin_addr, junk, sa_len),
47 48 ntohs(sa2.sin_port)); ntohs(sa2.sin_port));
48 49
50 tos = 0x00;
51 err = setsockopt(sock, IPPROTO_IP, IP_TOS, &tos, 1);
52 if (err != 0)
53 perror("setsockopt");
54
49 55 close(sock); close(sock);
50 56
51 57 return 0; return 0;
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/catalinux/force_bind

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/catalinux/force_bind

Clone this repository using git:
git clone git://git.rocketgit.com/user/catalinux/force_bind

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main