Skip to content
This repository has been archived by the owner on Sep 1, 2023. It is now read-only.

Commit

Permalink
Fixed failed to reuse address
Browse files Browse the repository at this point in the history
  • Loading branch information
猫王子 committed Jan 10, 2016
1 parent a45c01d commit c0800db
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 5 deletions.
12 changes: 9 additions & 3 deletions LightSwordX/Socket6/TCPSocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,13 @@ int tcpsocket_listen(const char *addr,int port){
}
}

int tcpsocket6_listen(const char* ipv6addr, int port) {
int tcpsocket6_listen(const char* addr, int port) {

int socketfd = socket(AF_INET6, SOCK_STREAM, 0);

int reuse = 1;
setsockopt(socketfd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse));

if (socketfd < 0) {
return socketfd;
}
Expand All @@ -231,14 +234,17 @@ int tcpsocket6_listen(const char* ipv6addr, int port) {
sa.sin6_port = htons(port);
sa.sin6_family = AF_INET6;
sa.sin6_len = sizeof(sa);
inet_pton(AF_INET6, ipv6addr, &(sa.sin6_addr));
inet_pton(AF_INET6, addr, &(sa.sin6_addr));

int b = bind(socketfd, (struct sockaddr *) &sa, sizeof(sa));
if (b != 0) {
fprintf(stderr, "%s\n", gai_strerror(b));
return -1;
}

if (listen(socketfd, 128) !=0 ) {
int l = listen(socketfd, 128);
if (l !=0 ) {
fprintf(stderr, "%s\n", gai_strerror(b));
return -2;
}

Expand Down
2 changes: 1 addition & 1 deletion LightSwordX/TCPSocket.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class TCPServer6: Socket {
return (false, "listening ready")
}

let fd = c_tcpsocket_listen(self.addr, port: Int32(self.port))
let fd = c_tcpsocket6_listen(self.addr, port: Int32(self.port))
if fd > 0 {
self.fd = fd;
return (true, "listening")
Expand Down
2 changes: 1 addition & 1 deletion LightSwordX/ViewController.Servers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ extension ViewController: NSTableViewDataSource {
server.id = servers.count

if servers.count == 0 {
server.address = "public1.lightsword.org"
server.address = "public1.2jien.com"
server.port = 443
}

Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@ Price: $0.99

LightSwordX is an open-source software, everyone can download the source code and compile it on Mac without any cost. But you may know **maintenance is the most expensive part** of software. No one can live without money! So, as a developer, I hope people would use and buy it. Thanks.

Features
---

✓ Enable mutli proxy servers simultaneously

✓ IPv6

✓ Whitelist & Blacklist

✓ Start self on system startup

✓ Traffic statistics

Privacy Policy
---

Expand Down
13 changes: 13 additions & 0 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@ LightSwordX 内置一台由网友免费提供的公用代理服务器,当然

LightSwordX 是完全开源的软件,每个人都可以下载源码并且编译运行。但是创建和维护任何一个项目都是需要成本与开销的。即便是开源项目,通常来说,也要有资金来源才能更好的发展。虽然不论你是否购买,我都会维护下去,但还是希望有用户能够购买该 App,支持这个该项目发展。

特性
---

✓ 同时使用多台服务器

✓ IPv6

✓ 黑白名单

✓ 开机启动

✓ 流量统计

隐私政策
---

Expand Down

0 comments on commit c0800db

Please sign in to comment.