aboutsummaryrefslogtreecommitdiff
path: root/okclient.c
diff options
context:
space:
mode:
Diffstat (limited to 'okclient.c')
-rw-r--r--okclient.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/okclient.c b/okclient.c
index a648c02..9a0d3c6 100644
--- a/okclient.c
+++ b/okclient.c
@@ -2,24 +2,34 @@
#include <sys/stat.h>
#include "str.h"
#include "ip4.h"
+#include "ip6.h"
+#include "byte.h"
#include "okclient.h"
-static char fn[3 + IP4_FMT];
+static char fn[3 + IP6_FMT];
-int okclient(char ip[4])
+int okclient(char ip[16])
{
struct stat st;
int i;
+ char sep;
fn[0] = 'i';
fn[1] = 'p';
fn[2] = '/';
- fn[3 + ip4_fmt(fn + 3,ip)] = 0;
+ if (byte_equal(ip,12,V4mappedprefix)) {
+ fn[3 + ip4_fmt(fn + 3,ip+12)] = 0;
+ sep='.';
+ } else {
+ fn[3 + ip6_fmt(fn + 3,ip)] = 0;
+ sep=':';
+ }
for (;;) {
+ if (!fn[3]) return 0;
if (stat(fn,&st) == 0) return 1;
/* treat temporary error as rejection */
- i = str_rchr(fn,'.');
+ i = str_rchr(fn,sep);
if (!fn[i]) return 0;
fn[i] = 0;
}