/test_bind.c (ef564034e516db96e7e9346000e4a7917da3b82d) (1135 bytes) (mode 100644) (type blob)
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
int main(int argc, char *argv[])
{
int sock, err;
struct sockaddr_in sa, sa2;
socklen_t sa_len;
int port = 4444;
char junk[128];
unsigned char tos;
sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock == -1) {
perror("socket");
return 1;
}
if (argc >= 2)
port = strtol(argv[1], NULL, 10);
memset(&sa, 0, sizeof(struct sockaddr));
sa.sin_family = AF_INET;
sa.sin_port = htons(port);
sa.sin_addr.s_addr = htonl(INADDR_ANY);
sa_len = sizeof(struct sockaddr_in);
err = bind(sock, (struct sockaddr *) &sa, sa_len);
if (err != 0) {
perror("bind");
return 1;
}
err = getsockname(sock, (struct sockaddr *) &sa2, &sa_len);
if (err != 0) {
perror("getsockname");
return 1;
}
fprintf(stderr, "Socket bound to %s/%d.\n",
inet_ntop(sa2.sin_family, &sa2.sin_addr, junk, sa_len),
ntohs(sa2.sin_port));
tos = 0x00;
err = setsockopt(sock, IPPROTO_IP, IP_TOS, &tos, 1);
if (err != 0)
perror("setsockopt");
close(sock);
return 0;
}
Mode |
Type |
Size |
Ref |
File |
100644 |
blob |
43 |
9108d94cb8e6f127c99b7099975be00532899907 |
.gitignore |
100644 |
blob |
30 |
d987fa5df957830331139935d517009e2911b0cf |
INSTALL |
100644 |
blob |
35147 |
94a9ed024d3859793618152ea559a168bbcbb5e2 |
LICENSE |
100644 |
blob |
541 |
b035b10712cea5a98c1d9e50887c363226307608 |
Makefile.in |
100644 |
blob |
855 |
70d1482667fbea25d33d3bbed803bb508cf0dd53 |
README |
100644 |
blob |
174 |
a0af61e812bd62970aa1e3dc33c883c756520f42 |
TODO |
100755 |
blob |
23 |
d33bb6c4ecdce1390ce1db3c79ea3b93e22ea755 |
configure |
100755 |
blob |
12723 |
62411b6de6bc9d88b550b7c96e140e8ce9015086 |
duilder |
100644 |
blob |
261 |
11bcae688fe61c68a0e1ac8e6694459208cbc2e3 |
duilder.conf |
100644 |
blob |
3807 |
a5207a60db67a4c778de9ee0e238069c6c978978 |
force_bind.c |
100644 |
blob |
804 |
b7ef7798c25d781fc2c7790aa80f8f431703e781 |
force_bind.spec.in |
100755 |
blob |
165 |
83d21d25e27dc624569788a2467ff66002d3b4a3 |
test1.sh |
100644 |
blob |
1135 |
ef564034e516db96e7e9346000e4a7917da3b82d |
test_bind.c |
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