diff options
author | David du Colombier <0intro@gmail.com> | 2012-08-03 21:25:31 +0200 |
---|---|---|
committer | David du Colombier <0intro@gmail.com> | 2012-08-03 21:25:31 +0200 |
commit | d24b8141673530ad65407434918136543c228df1 (patch) | |
tree | 8907f97a949a338ba355f795e26102b169cd0805 /src/lib9 | |
parent | 3a616eaa80070a1b89b907baacc8b603b02c670e (diff) | |
download | plan9port-d24b8141673530ad65407434918136543c228df1.tar.gz plan9port-d24b8141673530ad65407434918136543c228df1.tar.bz2 plan9port-d24b8141673530ad65407434918136543c228df1.zip |
lib9/getnetconn: add support for IPv6
R=rsc
http://codereview.appspot.com/6457077
Diffstat (limited to 'src/lib9')
-rw-r--r-- | src/lib9/getnetconn.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/lib9/getnetconn.c b/src/lib9/getnetconn.c index 52303d07..9fa8a9e0 100644 --- a/src/lib9/getnetconn.c +++ b/src/lib9/getnetconn.c @@ -5,6 +5,7 @@ #include <sys/socket.h> #include <netinet/in.h> #include <netinet/tcp.h> +#include <arpa/inet.h> #include <sys/un.h> #include <errno.h> @@ -20,6 +21,7 @@ convert(int s, struct sockaddr *sa, char **lsys, char **lserv, char **laddr) { struct sockaddr_un *sun; struct sockaddr_in *sin; + struct sockaddr_in6 *sin6; uchar *ip; u32int ipl; socklen_t sn; @@ -51,6 +53,30 @@ convert(int s, struct sockaddr *sa, char **lsys, char **lserv, char **laddr) if(*lsys == nil || *lserv == nil || *laddr == nil) return -1; return 0; + case AF_INET6: + sin6 = (void*)sa; + if (memcmp(&sin6->sin6_addr, &in6addr_any, sizeof(in6addr_any)) == 0) + *lsys = strdup("*"); + else{ + *lsys = malloc(INET6_ADDRSTRLEN); + inet_ntop(AF_INET6, &sin6->sin6_addr, *lsys, INET6_ADDRSTRLEN); + } + *lserv = smprint("%d", ntohs(sin6->sin6_port)); + sn = sizeof n; + if(getsockopt(s, SOL_SOCKET, SO_TYPE, (void*)&n, &sn) < 0) + return -1; + if(n == SOCK_STREAM) + net = "tcp"; + else if(n == SOCK_DGRAM) + net = "udp"; + else{ + werrstr("unknown network type"); + return -1; + } + *laddr = smprint("%s!%s!%s", net, *lsys, *lserv); + if(*lsys == nil || *lserv == nil || *laddr == nil) + return -1; + return 0; case AF_UNIX: sun = (void*)sa; *lsys = unknown; @@ -72,6 +98,7 @@ getnetconninfo(char *dir, int fd) union { struct sockaddr sa; struct sockaddr_in sin; + struct sockaddr_in6 sin6; struct sockaddr_un sun; } u; NetConnInfo *nci; |