Next: , Previous: , Up: posix socket addresses   [Index]


4.15.1.4 ASCII address representations

Dotted quad address representations can be handled as follows:

(import (vicare)
  (prefix (vicare posix) px.))

(px.inet-aton "127.0.0.1") ⇒ #vu8(127 0 0 1)
(px.inet-aton "ciao")      error→ invalid argument

(px.inet-ntoa/string '#vu8(127 0 0 1))
⇒ "127.0.0.1"

care must be taken when handling such raw values.

Function: inet-aton dotted-quad

ASCII to number. Given the bytevector dotted-quad holding the ASCII dotted quad representation of a host address, build and return a bytevector holding the corresponding struct in_addr. If dotted-quad is invalid: an exception is raised.

Function: inet-ntoa host-address
Function: inet-ntoa/string host-address

Number to ASCII. Given the bytevector host-address holding a struct in_addr: inet-ntoa builds and returns a bytevector holding the corresponding ASCII dotted quad representation, inet-ntoa/string builds and returns a string holding the corresponding ASCII dotted quad representation.

Addresses in presentation format can be handled as follows:

#!vicare
(import (vicare)
  (prefix (vicare posix) px.)
  (vicare platform constants))

(px.inet-pton AF_INET "127.0.0.1") ⇒ #vu8(127 0 0 1)
(px.inet-pton AF_INET "ciao")      error→ invalid arguments

(px.inet-pton AF_INET6 "1:2:3:4:5:6:7:8")
⇒ #vu16b(1 2 3 4 5 6 7 8)

(px.inet-ntop/string AF_INET '#vu8(127 0 0 1))
⇒ "127.0.0.1"

(px.inet-ntop/string AF_INET6 '#vu16b(1 2 3 4 5 6 7 8))
⇒ "1:2:3:4:5:6:7:8"

care must be taken when handling such raw values.

Function: inet-pton af presentation

Given the fixnum af, being AF_INET or AF_INET6, and the string or bytevector presentation holding the ASCII presentation of an Internet address, build and return a bytevector holding the corresponding struct in_addr or struct in6_addr. If either af or presentation is invalid: raise an exception.

Function: inet-ntop af host-address
Function: inet-ntop/string af host-address

Given the fixnum af, being AF_INET or AF_INET6, and the bytevector host-address holding a struct in_addr or struct in6_addr: inet-ntop builds and returns a bytevector holding the corresponding ASCII presentation of the Internet address, inet-ntop/string builds and returns a string holding the corresponding ASCII presentation of the Internet address. If the arguments are invalid: an exception is raised.


Next: , Previous: , Up: posix socket addresses   [Index]