warp-vpn

point to point VPN implementation
git clone git://git.2f30.org/warp-vpn
Log | Files | Refs | README

commit cb2d934aea9637edc89ad27fe86bacf0e7c4cf85
parent 4f4bd4e789eb5d045a45c8e1b79a886f4e949acb
Author: sin <sin@2f30.org>
Date:   Tue, 12 Apr 2016 22:41:11 +0100

ipv6 support

Diffstat:
Mclient.c | 8++++++--
Mserver.c | 10+++++++---
2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/client.c b/client.c @@ -19,13 +19,17 @@ clientconnect(char *host, char *port) int ret, netfd; memset(&hints, 0, sizeof(hints)); - hints.ai_family = AF_INET; + hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; if ((ret = getaddrinfo(host, port, &hints, &ai))) logerr("getaddrinfo: %s", gai_strerror(ret)); for (p = ai; p; p = p->ai_next) { - if ((netfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) + if (p->ai_family != AF_INET && + p->ai_family != AF_INET6) + continue; + if ((netfd = socket(p->ai_family, p->ai_socktype, + p->ai_protocol)) < 0) continue; if (connect(netfd, p->ai_addr, p->ai_addrlen) < 0) { close(netfd); diff --git a/server.c b/server.c @@ -20,7 +20,7 @@ serverinit(char *host, char *port) int ret, listenfd; memset(&hints, 0, sizeof(hints)); - hints.ai_family = AF_INET; + hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; hints.ai_flags = AI_PASSIVE; @@ -28,7 +28,11 @@ serverinit(char *host, char *port) logerr("getaddrinfo: %s", gai_strerror(ret)); for (p = ai; p; p = p->ai_next) { - if ((listenfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) + if (p->ai_family != AF_INET && + p->ai_family != AF_INET6) + continue; + if ((listenfd = socket(p->ai_family, p->ai_socktype, + p->ai_protocol)) < 0) continue; setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, (int []){1}, sizeof(int)); @@ -51,7 +55,7 @@ serverinit(char *host, char *port) int serveraccept(int listenfd) { - struct sockaddr_in remote; + struct sockaddr_storage remote; int netfd; netfd = accept(listenfd, (struct sockaddr *)&remote,