Skip to content

Commit

Permalink
client: add ipv6 option
Browse files Browse the repository at this point in the history
  • Loading branch information
liudongmiao committed Apr 28, 2024
1 parent ea731a7 commit a8b5f71
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion wss-proxy-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
struct wss_server_info {
uint8_t tls: 1;
uint8_t ws: 1;
uint8_t ipv6: 1;
uint16_t port;
const char *addr;
const char *host;
Expand Down Expand Up @@ -150,6 +151,11 @@ static int init_wss_addr(struct wss_server_info *server) {
server->ws = 1;
}

// ipv6
if ((value = find_option(options, "ipv6", "1")) != NULL) {
server->ipv6 = (int) strtol(value, NULL, 10);
}

// strip
server->host = strdup(server->host);
if ((end = strchr(server->host, ';')) != NULL) {
Expand All @@ -173,7 +179,7 @@ static int init_wss_addr(struct wss_server_info *server) {
wss = "ss";
}
}
LOGI("wss client %s:%d (%s://%s%s)", remote_host, port, wss, server->host, server->path);
LOGI("wss client%s %s:%d (%s://%s%s)", server->ipv6 ? "6" : "", remote_host, port, wss, server->host, server->path);
if (server->ws && mux) {
LOGW("mux %d is unsupported", mux);
}
Expand Down Expand Up @@ -303,6 +309,10 @@ static struct evhttp_connection *connect_wss(struct wss_proxy_context *context,
goto error;
}

if (context->server.ipv6) {
evhttp_connection_set_family(wss, AF_INET6);
}

evhttp_connection_set_timeout(wss, WSS_TIMEOUT);
if (raw->be_ops) {
bufferevent_setcb(raw, NULL, NULL, raw_event_cb, wss);
Expand Down

0 comments on commit a8b5f71

Please sign in to comment.