Patch by Jp Calderone:

- The socket module now provides the functions inet_pton and inet_ntop
  for converting between string and packed representation of IP addresses.
  See SF patch #658327.

This still needs a bit of work in the doc area, because it is not
available on all platforms (especially not on Windows).
This commit is contained in:
Guido van Rossum 2003-04-25 05:48:32 +00:00
parent 45f4130029
commit 47dfa4a89a
6 changed files with 221 additions and 1 deletions

View file

@ -150,6 +150,11 @@ those symbols that are defined in the \UNIX{} header files are defined;
for a few symbols, default values are provided.
\end{datadesc}
\begin{datadesc}{has_ipv6}
This constant contains a boolean value which indicates if IPv6 is
supported on this platform.
\end{datadesc}
\begin{funcdesc}{getaddrinfo}{host, port\optional{, family, socktype, proto, flags}}
Resolves the \var{host}/\var{port} argument, into a sequence of
@ -349,6 +354,43 @@ length, \exception{socket.error} will be raised.
support.
\end{funcdesc}
\begin{funcdesc}{inet_pton}{address_family, ip_string}
Convert an IP address from its family-specific string format to a packed,
binary format.
Supported values for address_family are currently \constant{AF_INET}
and \constant{AF_INET6}.
\function{inet_pton()} is useful when a library or network protocol calls for
an object of type \ctype{struct in_addr} (similar to \function{inet_aton()})
or \ctype{struct in6_addr}.
If the IP address string passed to this function is invalid,
\exception{socket.error} will be raised. Note that exactly what is valid
depends on both the value of \var{address_family} and the underlying
implementation of \cfunction{inet_pton()}.
\versionadded{2.3}
\end{funcdesc}
\begin{funcdesc}{inet_ntop}{address_family, packed_ip}
Convert a packed IP address (a string of some number of characters) to its
standard, family-specific string representation (for example, '7.10.0.5' or
'5aef:2b::8')
Supported values for address_family are currently \constant{AF_INET}
and \constant{AF_INET6}.
\function{inet_pton()} is useful when a library or network protocol calls for
an object of type \ctype{struct in_addr} (similar to \function{inet_aton()})
or \ctype{struct in6_addr}.
If the string passed to this function is not the correct length for the
specified address family, \exception{ValueError} will be raised.
A \exception{socket.error} is raised for errors from the call to
\function{inet_ntop()}.
\versionadded{2.3}
\end{funcdesc}
\begin{funcdesc}{getdefaulttimeout}{}
Return the default timeout in floating seconds for new socket objects.
A value of \code{None} indicates that new socket objects have no timeout.