URL
https://opencores.org/ocsvn/or1k/or1k/trunk
Subversion Repositories or1k
[/] [or1k/] [trunk/] [rtems/] [c/] [src/] [libnetworking/] [libc/] [addr2ascii.3] - Rev 1765
Compare with Previous | Blame | View Log
.\".\" Copyright 1996 Massachusetts Institute of Technology.\".\" Permission to use, copy, modify, and distribute this software and.\" its documentation for any purpose and without fee is hereby.\" granted, provided that both the above copyright notice and this.\" permission notice appear in all copies, that both the above.\" copyright notice and this permission notice appear in all.\" supporting documentation, and that the name of M.I.T. not be used.\" in advertising or publicity pertaining to distribution of the.\" software without specific, written prior permission. M.I.T. makes.\" no representations about the suitability of this software for any.\" purpose. It is provided "as is" without express or implied.\" warranty..\".\" THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS.\" ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,.\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT.\" SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT.\" LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF.\" USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND.\" ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT.\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF.\" SUCH DAMAGE..\".\" $ANA: addr2ascii.3,v 1.1 1996/06/13 18:41:46 wollman Exp $.\" $Id: addr2ascii.3,v 1.2 2001-09-27 12:01:53 chris Exp $.\".Dd June 13, 1996.Dt ADDR2ASCII 3.Os.Sh NAME.Nm addr2ascii ,.Nm ascii2addr.Nd Generic address formatting routines.Sh SYNOPSIS.Fd #include <sys/types.h>.Fd #include <netinet/in.h>.Fd #include <arpa/inet.h>.Ft "char *".Fn addr2ascii "int af" "const void *addrp" "int len" "char *buf".Ft int.Fn ascii2addr "int af" "const char *ascii" "void *result".Sh DESCRIPTIONThe routines.Fn addr2asciiand.Fn ascii2addrare used to convert network addresses between binary form and aprintable form appropriate to the address family. Both functions takean.Fa afargument, specifying the address family to be used in the conversionprocess.(Currently, only the.Dv AF_INETand.Dv AF_LINKaddress families are supported.).PpThe.Fn addr2asciifunctionis used to convert binary, network-format addresses into printableform. In addition to.Fa af ,there are three other arguments. The.Fa addrpargument is a pointer to the network address to be converted.The.Fa lenargument is the length of the address. The.Fa bufargument is an optional pointer to a caller-allocated buffer to holdthe result; if a null pointer is passed,.Fn addr2asciiuses a statically-allocated buffer..PpThe.Fn ascii2addrfunction performs the inverse operation to.Fn addr2ascii .In addition to.Fa af ,it takes two parameters,.Fa asciiand.Fa result .The.Fa asciiparameter is a pointer to the string which is to be converted intobinary. The.Fa resultparameter is a pointer to an appropriate network address structure forthe specified family..PpThe following gives the appropriate structure to use for binaryaddresses in the specified family:.Pp.Bl -tag -width AF_INETxxxx -compact.It Dv AF_INET.Li struct in_addr.Pq in Aq Pa netinet/in.h.It Dv AF_LINK.Li struct sockaddr_dl.Pq in Aq Pa net/if_dl.h.\" .It Dv AF_INET6.\" .Li struct in6_addr.\" .Pq in Aq Pa netinet6/in6.h.El.Sh RETURN VALUESThe.Fn addr2asciifunction returns the address of the buffer it was passed, or a staticbuffer if the a null pointer was passed; on failure, it returns a nullpointer.The.Fn ascii2addrfunction returns the length of the binary address in bytes, or -1 onfailure..Sh EXAMPLESThe.Xr inet 3functions.Fn inet_ntoaand.Fn inet_atoncould be implemented thusly:.Bd -literal -offset indent#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>char *inet_ntoa(struct in_addr addr){return addr2ascii(AF_INET, &addr, sizeof addr, 0);}intinet_aton(const char *ascii, struct in_addr *addr){return (ascii2addr(AF_INET, ascii, addr)== sizeof(*addr));}.Ed.PpIn actuality, this cannot be done because.Fn addr2asciiand.Fn ascii2addrare implemented in terms of the.Xr inet 3functions, rather than the other way around..Sh ERRORSWhen a failure is returned,.Li errnois set to one of the following values:.Bl -tag -width [EPROTONOSUPPORT].It Bq Er ENAMETOOLONGThe.Fn addr2asciiroutine was passed a.Fa lenparameter which was inappropriate for the address family given by.Fa af ..It Bq Er EPROTONOSUPPORTEither routine was passed an.Fa afparameter other than.Dv AF_INETor.Dv AF_LINK ..It Bq Er EINVALThe string passed to.Fn ascii2addrwas improperly formatted for address family.Fa af ..El.Sh SEE ALSO.Xr inet 3 ,.Xr linkaddr 3 ,.Xr inet 4.Sh HISTORYAn interface close to this one was originally suggested by CraigPartridge. This particular interface originally appeared in the.Tn INRIA.Tn IPv6implementation..Sh AUTHORSCode and documentation by.An Garrett A. Wollman ,MIT Laboratory for Computer Science..Sh BUGSThe original implementations supported IPv6. This support shouldeventually be resurrected. The.Tn NRLimplementation also included support for the.Dv AF_ISOand.Dv AF_NSaddress families..PpThe genericity of this interface is somewhat questionable. A trulygeneric interface would provide a means for determining the length ofthe buffer to be used so that it could be dynamically allocated, andwould always require a.Dq Li "struct sockaddr"to hold the binary address. Unfortunately, this is incompatible with existingpractice. This limitation means that a routine for printing networkaddresses from arbitrary address families must still have internalknowledge of the maximum buffer length needed and the appropriate partof the address to use as the binary address.
