Node:Network Address Conversion, Next:, Up:Networking



38.11.1 Network Address Conversion

This section describes procedures which convert internet addresses between numeric and string formats.

38.11.1.1 IPv4 Address Conversion

inet-aton address Scheme Procedure
scm_inet_aton (address) C Function
Convert an IPv4 Internet address from printable string (dotted decimal notation) to an integer. E.g.,
(inet-aton "127.0.0.1") => 2130706433

inet-ntoa inetid Scheme Procedure
scm_inet_ntoa (inetid) C Function
Convert an IPv4 Internet address to a printable (dotted decimal notation) string. E.g.,
(inet-ntoa 2130706433) => "127.0.0.1"

inet-netof address Scheme Procedure
scm_inet_netof (address) C Function
Return the network number part of the given IPv4 Internet address. E.g.,
(inet-netof 2130706433) => 127

inet-lnaof address Scheme Procedure
scm_lnaof (address) C Function
Return the local-address-with-network part of the given IPv4 Internet address, using the obsolete class A/B/C system. E.g.,
(inet-lnaof 2130706433) => 1

inet-makeaddr net lna Scheme Procedure
scm_inet_makeaddr (net, lna) C Function
Make an IPv4 Internet address by combining the network number net with the local-address-within-network number lna. E.g.,
(inet-makeaddr 127 1) => 2130706433

38.11.1.2 IPv6 Address Conversion

inet-ntop family address Scheme Procedure
scm_inet_ntop (family, address) C Function
Convert a network address into a printable string. Note that unlike the C version of this function, the input is an integer with normal host byte ordering. family can be AF_INET or AF_INET6. E.g.,
(inet-ntop AF_INET 2130706433) => "127.0.0.1"
(inet-ntop AF_INET6 (- (expt 2 128) 1)) =>
ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff

inet-pton family address Scheme Procedure
scm_inet_pton (family, address) C Function
Convert a string containing a printable network address to an integer address. Note that unlike the C version of this function, the result is an integer with normal host byte ordering. family can be AF_INET or AF_INET6. E.g.,
(inet-pton AF_INET "127.0.0.1") => 2130706433
(inet-pton AF_INET6 "::1") => 1