# IPv6 fallback to IPv4

**URL:** https://racket.discourse.group/t/ipv6-fallback-to-ipv4/1039
**Category:** General
**Created:** [May 28, 2022, 12:23am UTC](https://racket.discourse.group/t/ipv6-fallback-to-ipv4/1039 "2022-05-28T00:23:59Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![evdubs](https://avatars.discourse-cdn.com/v4/letter/e/b5ac83/32.png) [@evdubs](https://racket.discourse.group/u/evdubs)
#### Post date: [May 28, 2022, 12:23am UTC](https://racket.discourse.group/t/ipv6-fallback-to-ipv4/1039/1 "2022-05-28T00:23:59Z")

</div>

I recently had an issue where my IPv6 connection was not working (`ping google.com` resolved to an IPv6 address and failed to get a response), but IPv4 was working (`ping -4 google.com` got responses). I was able to use Firefox without noticing any issues, but my racket programs had failed with timeout errors. Is there perhaps a way to either force racket to use IPv4 or try to set a fallback mechanism to use IPv4 in case of IPv6 connection failures? So far, this situation seems very rare for my internet connectivity.

---

<div class="post-metadata">

### Author: ![evdubs](https://avatars.discourse-cdn.com/v4/letter/e/b5ac83/32.png) [@evdubs](https://racket.discourse.group/u/evdubs)
#### Post date: [July 2, 2024, 8:54pm UTC](https://racket.discourse.group/t/ipv6-fallback-to-ipv4/1039/2 "2024-07-02T20:54:21Z")

</div>

I recently ran into this issue again. I am currently in an IPv6 outage and my solution has been to disable IPv6 on my Ethernet device.

Is there perhaps some way to configure Racket to fall back to IPv4?

---

<div class="post-metadata">

### Author: ![jbclements](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/jbclements/32/11_2.png) [@jbclements](https://racket.discourse.group/u/jbclements)
#### Post date: [July 2, 2024, 9:30pm UTC](https://racket.discourse.group/t/ipv6-fallback-to-ipv4/1039/3 "2024-07-02T21:30:28Z")

</div>

Well... that's just weird. I thought for sure there was good relevant documentation here, but I can't find it.

Specifically, it looks like functions like `http-open-conn!` call functions like `tcp-connect` to establish connections, but I don't see any documentation for `tcp-connect` that indicates how hostname resolution is done. I also don't see anything in the net/dns documentation that would indicate the presence of a parameter controlling hostname resolution.

I do see that there's a function called `dns-get-address` that can be instructed to do IPv6 lookup, so one obvious workaround (maybe this isn't a workaround, maybe it's ....

Okay, actually, no, I'm giving up for now. At a minimum, I think we need at least an update to the `http-open-conn!` documentation that specifies how host resolution is performed.

---

<div class="post-metadata">

### Author: ![mflatt](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/mflatt/32/6_2.png) [@mflatt](https://racket.discourse.group/u/mflatt)
#### Post date: [July 2, 2024, 10:53pm UTC](https://racket.discourse.group/t/ipv6-fallback-to-ipv4/1039/4 "2024-07-02T22:53:19Z")

</div>

I think the only relevant documentation is `tcp-connect`: "(If hostname is associated with multiple addresses, they are tried one at a time until a connection succeeds....)".

Racket uses the `getaddrinfo` library from the OS, and it tries the resulting addresses in order, which might mean trying an IPv6 address before IPv4. Depending on the failure mode, that sequence it might get stuck trying IPv6 so that it never gets around to trying an IPv4 address.

Racket's use of `getaddrinfo` includes a non-NULL `hints`, but its hints flags do not include `AI_ADDRCONFIG | AI_V4MAPPED`, which is apparently the default these days (as opposed to 0). It seems possible that adding those flags would improve things and maybe address the problem, but I welcome advice from anyone who knows more about this.

---

<div class="post-metadata">

### Author: ![jbclements](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/jbclements/32/11_2.png) [@jbclements](https://racket.discourse.group/u/jbclements)
#### Post date: [July 5, 2024, 4:56pm UTC](https://racket.discourse.group/t/ipv6-fallback-to-ipv4/1039/5 "2024-07-05T16:56:58Z")

</div>

Oh, I see; I had assumed that the hostname-\>ip step was done in a way that's visible to the language, when in fact this happens at the OS level. It looks like @evdubs understood this already.

---

<div class="post-metadata">

### Author: ![evdubs](https://avatars.discourse-cdn.com/v4/letter/e/b5ac83/32.png) [@evdubs](https://racket.discourse.group/u/evdubs)
#### Post date: [July 5, 2024, 8:38pm UTC](https://racket.discourse.group/t/ipv6-fallback-to-ipv4/1039/6 "2024-07-05T20:38:37Z")

</div>

> [@mflatt](#):
>
> Racket's use of `getaddrinfo` includes a non-NULL `hints`, but its hints flags do not include `AI_ADDRCONFIG | AI_V4MAPPED`, which is apparently the default these days (as opposed to 0).

In the absence of other comments or advice about this, I would like for a way to set these hints flags if they won't be supplied as defaults. There is this note in the `getaddrinfo(3)` man page, which I take is what you mean above about "the default these days":

> According to POSIX.1, specifying hints as NULL should cause ai\_flags to be assumed as 0. The GNU C library instead assumes a value of (AI\_V4MAPPED | AI\_ADDRCONFIG) for this case, since this value is considered an improvement on the specification.

---

<div class="post-metadata">

### Author: ![mflatt](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/mflatt/32/6_2.png) [@mflatt](https://racket.discourse.group/u/mflatt)
#### Post date: [July 9, 2024, 2:40am UTC](https://racket.discourse.group/t/ipv6-fallback-to-ipv4/1039/7 "2024-07-09T02:40:15Z")

</div>

I've merged a change to include these flags — but to be on the safer side, not included it for the upcoming 8.14 release, so we have more time to try it out for v8.15.
