ascii2addr man page on MacOSX

Man page or keyword search:  
man Server   23457 pages
apropos Keyword Search (all sections)
Output format
MacOSX logo
[printable version]

ADDR2ASCII(3)		 BSD Library Functions Manual		 ADDR2ASCII(3)

     addr2ascii, ascii2addr — Generic address formatting routines

     Standard C Library (libc, -lc)

     #include <arpa/inet.h>

     char *
     addr2ascii(int af, const void *addrp, int len, char *buf);

     ascii2addr(int af, const char *ascii, void *result);

     The routines addr2ascii() and ascii2addr() are used to convert network
     addresses between binary form and a printable form appropriate to the
     address family.  Both functions take an af argument, specifying the
     address family to be used in the conversion process.  (Currently, only
     the AF_INET and AF_LINK address families are supported.)

     The addr2ascii() function is used to convert binary, network-format
     addresses into printable form.  In addition to af, there are three other
     arguments.	 The addrp argument is a pointer to the network address to be
     converted.	 The len argument is the length of the address.	 The buf argu‐
     ment is an optional pointer to a caller-allocated buffer to hold the
     result; if a null pointer is passed, addr2ascii() uses a statically-allo‐
     cated buffer.

     The ascii2addr() function performs the inverse operation to addr2ascii().
     In addition to af, it takes two arguments, ascii and result.  The ascii
     argument is a pointer to the string which is to be converted into binary.
     The result argument is a pointer to an appropriate network address struc‐
     ture for the specified family.

     The following gives the appropriate structure to use for binary addresses
     in the specified family:

     AF_INET	  struct in_addr (in <arpa/inet.h>)
     AF_LINK	  struct sockaddr_dl (in <net/if_dl.h>)

     AF_INET and AF_LINK constants are defined in <sys/socket.h>

     The addr2ascii() function returns the address of the buffer it was
     passed, or a static buffer if the a null pointer was passed; on failure,
     it returns a null pointer.	 The ascii2addr() function returns the length
     of the binary address in bytes, or -1 on failure.

     The inet(3) functions inet_ntoa() and inet_aton() could be implemented

	   #include <sys/socket.h>
	   #include <arpa/inet.h>

	   char *
	   inet_ntoa(struct in_addr addr)
		   return addr2ascii(AF_INET, &addr, sizeof addr, 0);

	   inet_aton(const char *ascii, struct in_addr *addr)
		   return (ascii2addr(AF_INET, ascii, addr)
		       == sizeof(*addr));

     In actuality, this cannot be done because addr2ascii() and ascii2addr()
     are implemented in terms of the inet(3) functions, rather than the other
     way around.

     When a failure is returned, errno is set to one of the following values:

     [ENAMETOOLONG]	The addr2ascii() routine was passed a len argument
			which was inappropriate for the address family given
			by af.

     [EPROTONOSUPPORT]	Either routine was passed an af argument other than

     [EINVAL]		The string passed to ascii2addr() was improperly for‐
			matted for address family af.

     inet(3), linkaddr(3), inet(4)

     An interface close to this one was originally suggested by Craig Par‐
     tridge.  This particular interface originally appeared in the INRIA IPv6

     Code and documentation by Garrett A. Wollman, MIT Laboratory for Computer

     The original implementations supported IPv6.  This support should eventu‐
     ally be resurrected.  The NRL implementation also included support for
     the AF_ISO and AF_NS address families.

     The genericity of this interface is somewhat questionable.	 A truly
     generic interface would provide a means for determining the length of the
     buffer to be used so that it could be dynamically allocated, and would
     always require a “struct sockaddr” to hold the binary address.  Unfortu‐
     nately, this is incompatible with existing practice.  This limitation
     means that a routine for printing network addresses from arbitrary
     address families must still have internal knowledge of the maximum buffer
     length needed and the appropriate part of the address to use as the
     binary address.

BSD				 June 13, 1996				   BSD

List of man pages available for MacOSX

Copyright (c) for man pages and the logo by the respective OS vendor.

For those who want to learn more, the polarhome community provides shell access and support.

[legal] [privacy] [GNU] [policy] [cookies] [netiquette] [sponsors] [FAQ]
Polarhome, production since 1999.
Member of Polarhome portal.
Based on Fawad Halim's script.
Vote for polarhome
Free Shell Accounts :: the biggest list on the net