if (ret)
PG_RETURN_NULL();
+ clean_ipv6_addr(port->raddr.addr.ss_family, remote_host);
+
PG_RETURN_INET_P(network_in(remote_host, false));
}
if (ret)
PG_RETURN_NULL();
+ clean_ipv6_addr(port->laddr.addr.ss_family, local_host);
+
PG_RETURN_INET_P(network_in(local_host, false));
}
PG_RETURN_INT64(res);
}
+
+
+/*
+ * clean_ipv6_addr --- remove any '%zone' part from an IPv6 address string
+ *
+ * XXX This should go away someday!
+ *
+ * This is a kluge needed because we don't yet support zones in stored inet
+ * values. Since the result of getnameinfo() might include a zone spec,
+ * call this to remove it anywhere we want to feed getnameinfo's output to
+ * network_in. Beats failing entirely.
+ *
+ * An alternative approach would be to let network_in ignore %-parts for
+ * itself, but that would mean we'd silently drop zone specs in user input,
+ * which seems not such a good idea.
+ */
+void
+clean_ipv6_addr(int addr_family, char *addr)
+{
+#ifdef HAVE_IPV6
+ if (addr_family == AF_INET6)
+ {
+ char *pct = strchr(addr, '%');
+
+ if (pct)
+ *pct = '\0';
+ }
+#endif
+}
if (ret)
PG_RETURN_NULL();
+ clean_ipv6_addr(beentry->st_clientaddr.addr.ss_family, remote_host);
+
PG_RETURN_INET_P(DirectFunctionCall1(inet_in,
CStringGetDatum(remote_host)));
}
extern Datum inetpl(PG_FUNCTION_ARGS);
extern Datum inetmi_int8(PG_FUNCTION_ARGS);
extern Datum inetmi(PG_FUNCTION_ARGS);
+extern void clean_ipv6_addr(int addr_family, char *addr);
/* mac.c */
extern Datum macaddr_in(PG_FUNCTION_ARGS);