Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unix.getaddrinfo returns incorrects ipv6 addresses #3565

Closed
vicuna opened this issue Mar 30, 2005 · 1 comment
Closed

Unix.getaddrinfo returns incorrects ipv6 addresses #3565

vicuna opened this issue Mar 30, 2005 · 1 comment
Labels

Comments

@vicuna
Copy link

vicuna commented Mar 30, 2005

Original bug ID: 3565
Reporter: administrator
Status: closed
Resolution: fixed
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)

Bug description

Full_Name: Samuel Thibault
Version: 3.08.3
OS: Linux
Submission from: d83-177-178-162.cust.tele2.fr (83.177.178.162)

Hi,

While trying to use ipv6 with Ocaml, getaddrinfo returned me strange results. My
/etc/hosts contains
fec0::2d0:59ff:fe4b:1b2e interface.ipv6
and ping6 interface.ipv6 does work, so C resolving works, but:

open Unix;;

let [ ai ] = getaddrinfo "interface.ipv6" "12345" [AI_SOCKTYPE SOCK_STREAM];;

Warning: this pattern-matching is not exhaustive.
Here is an example of a value that is not matched:
[]
val ai : Unix.addr_info =
{ai_family = PF_INET6; ai_socktype = SOCK_STREAM; ai_protocol = 6;
ai_addr = ADDR_INET (, 12345); ai_canonname = ""}

let ADDR_INET(adr,port) = ai.ai_addr;;

Warning: this pattern-matching is not exhaustive.
Here is an example of a value that is not matched:
ADDR_UNIX _
val adr : Unix.inet_addr =
val port : int = 12345

string_of_inet_addr adr;;

  • : string = "fec0::90e8:ffbf:200:0"

Which is just garbage. In otherlibs/unix/getaddrinfo.c, I noticed the following
lines in convert_addrinfo():
memcpy(&sa.s_gen, a->ai_addr, sizeof(struct sockaddr));
vaddr = alloc_sockaddr(&sa, sizeof(struct sockaddr), -1);
This is wrong: struct sockaddr is not always big enough to hold struct
sockaddr_in6 for instance. sizeof(struct sockaddr) should be replaced by
a->ai_addrlen for instance (after checking that this is smaller than caml's
sizeof(union sock_addr_union) ), in which case it does work:

open Unix;;

let [ ai ] = getaddrinfo "interface.ipv6" "12345" [AI_SOCKTYPE SOCK_STREAM];;

Warning: this pattern-matching is not exhaustive.
Here is an example of a value that is not matched:
[]
val ai : Unix.addr_info =
{ai_family = PF_INET6; ai_socktype = SOCK_STREAM; ai_protocol = 6;
ai_addr = ADDR_INET (, 12345); ai_canonname = ""}

let ADDR_INET(adr,port) = ai.ai_addr;;

Warning: this pattern-matching is not exhaustive.
Here is an example of a value that is not matched:
ADDR_UNIX _
val adr : Unix.inet_addr =
val port : int = 12345

string_of_inet_addr adr;;

  • : string = "fec0::2d0:59ff:fe4b:1b2e"

Regards,
Samuel Thibault

@vicuna
Copy link
Author

vicuna commented Apr 17, 2005

Comment author: administrator

Fixed as suggested in 3.08 branch. XL, 2005-04-17

@vicuna vicuna closed this as completed Apr 17, 2005
@vicuna vicuna added the bug label Mar 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant