# Partial IPv6 support (split topic)

**URL:** <https://swi-prolog.discourse.group/t/partial-ipv6-support-split-topic/6283>\
**Category:** Split Topic\
**Created:** [February 7, 2023, 12:32pm UTC](https://swi-prolog.discourse.group/t/partial-ipv6-support-split-topic/6283 "2023-02-07T12:32:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [February 7, 2023, 12:32pm UTC](https://swi-prolog.discourse.group/t/partial-ipv6-support-split-topic/6283/1 "2023-02-07T12:32:23Z")

</div>

Pushed some further updates. tcp\_connect/3 now fetches the address info first and then tries the returned addresses in order until one connects. If none connects it re-throws the exception of the first attempt. It seems Linux first returns the IPv6 addresses. I have no clue whether this is a coincident or design.

Also pushed an updated to the http package, so we can now do this to get a HTTP server listening on all interfaces to IPv6.

```
 ?- http_server('::':8080, []).

```

The equivalent for `localhost:8080` in IPv6 is

```
?- http_server('::1':8080, []).

```

As noted in [Compiling the latest version from source fails on macOS](https://swi-prolog.discourse.group/t/compiling-the-latest-version-from-source-fails-on-macos/6193), compilation seems to fail on some platform.

For the **inet6 experts** : The IPv6 address is captured in `struct in6_addr`. So far, so good and all agree. They also all agree this struct contains a union of three members that provide an 8-bit, 16-bit and 32-bit view on the 128-bit IPv6 address. Only Windows, Linux and MacOS seem to disagree on how to call the union and how to call the three members thereof. They all provide the `s6_addr` macro to get the 8-bit view, but there seems no agreement way to get the 16 bit view which I use from Prolog as that that matches the notation as close as possible. Linux provides `s6_addr16` for the 16-bit view, but Windows calls this `s6_word` and Apple doesn’t define the macro at all ☹ And there are more operating systems …

Should I use `s6_addr` and combine/split these myself to get the 16 bit view? They are in “network byte” order, which is why we need `ntohs()` to get the 16-bit integers from the 16 bit view.

---

<div class="post-metadata">

**Author:** ![EricGT](https://avatars.discourse-cdn.com/v4/letter/e/f1d935/32.png) [@EricGT](https://swi-prolog.discourse.group/u/EricGT)\
**Post date:** [February 7, 2023, 1:01pm UTC](https://swi-prolog.discourse.group/t/partial-ipv6-support-split-topic/6283/2 "2023-02-07T13:01:05Z")

</div>

I don’t know enough to give any sensible answer, so instead asked ChatGPT.

Me

> The IPv6 address is captured in struct in6\_addr. So far, so good and all agree. They also all agree this struct contains a union of three members that provide an 8-bit, 16-bit and 32-bit view on the 128-bit IPv6 address. Only Windows, Linux and MacOS seem to disagree on how to call the union and how to call the three members thereof. They all provide the s6\_addr macro to get the 8-bit view, but there seems no agreement way to get the 16 bit view which I use from Prolog as that that matches the notation as close as possible. Linux provides s6\_addr16 for the 16-bit view, but Windows calls this s6\_word and Apple doesn’t define the macro at all ☹ And there are more operating systems …
> 
> Should I use s6\_addr and combine/split these myself to get the 16 bit view? They are in “network byte” order, which is why we need ntohs() to get the 16-bit integers from the 16 bit view.

ChatGPT

> It is recommended to use the standard macros provided by each operating system to access the 16-bit view of the IPv6 address in struct in6\_addr, as the naming conventions may differ between different operating systems. On Linux, use the s6\_addr16 macro, on Windows use s6\_word, and on Apple systems you may need to define the macro yourself. It is necessary to use the ntohs() function to convert the 16-bit values from network byte order to host byte order.

* * *

If this is of no value, let me know and I will delete it.

* * *

After [reply](https://swi-prolog.discourse.group/t/partial-ipv6-support/6187/4) below.

Me

> Is there a portable way across many operating systems to solve this?

ChatGPT

> Unfortunately, there is no portable way across many operating systems to access the 16-bit view of the IPv6 address in struct in6\_addr. Different operating systems may have different naming conventions for the macros and there is no standardization. If portability is a concern, it might be better to implement the necessary macro definitions in your code and use the same macro names across all platforms, or to manually split the 128-bit address into 16-bit values yourself and convert them with ntohs().

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [February 7, 2023, 1:25pm UTC](https://swi-prolog.discourse.group/t/partial-ipv6-support-split-topic/6283/3 "2023-02-07T13:25:59Z")

</div>

> [@EricGT](#):
>
> If this is of no value, let me know and I will delete it.

I won’t delete it. It is pretty accurate and reflects what I found as well. The real question is how to solve this in a portable way however is not answered. These are just 3 of the many OSes SWI-Prolog runs on. Ok, they are the most popular and the only three for which we create official releases, but still …

… and still, I’m impressed by ChatGPT. Despite it sometimes weird failures 🙂
