[Contents] [Previous] [Next] [Last]
This chapter describes the NSPR types and functions used to manipulate network addresses.
Network Address Types and Constants Network Address Functions
The API described in this chapter recognizes the emergence of Internet Protocol Version 6 (IPv6). To facilitate the transition to IPv6, it is recommended that clients treat all structures containing network addresses as transparent objects and use the functions documented here to manipulate the information.
If used consistently, this API also eliminates the need to deal with the byte ordering of network addresses. Typically, the only numeric declarations required are the well-known port numbers that are part of the PRNetAddr structure.
Network Address Types and Constants
PRHostEnt
PRProtoEnt
PR_NETDB_BUF_SIZE
PRHostEnt
A structure that defines a list of network addresses. This structure is output from PR_GetHostByName and PR_GetHostByAddr and passed to PR_EnumerateHostEnt. Clients should avoid directly accessing any of the structure's fields.
Syntax
#include <prnetdb.h>
typedef struct PRHostEnt {
char *h_name;
char **h_aliases; #if defined(_WIN32)
PRInt16 h_addrtype;
PRInt16 h_length; #else
PRInt32 h_addrtype;
PRInt32 h_length; #endif
char **h_addr_list; } PRHostEnt;
Fields
The structure has the following fields:
Description
This structure is used by many of the network address functions. All addresses are passed in host order and returned in network order (suitable for use in system calls).
Use the network address functions to manipulate the PRHostEnt structure. To make the transition to IP version 6 easier, it's best to treat PRHostEnt as an opaque structure.
NOTE:
WINSOCK.H defines h_addrtype and h_length as a 16-bit field, whereas other
platforms treat it as a 32-bit field. The #ifdef in the structure allows direct assignment
of the PRHostEnt structure.
PRProtoEnt
Protocol entry returned by PR_GetProtoByName and PR_GetProtoByNumber.
Syntax
#include <prnetdb.h>
typedef struct PRProtoEnt {
char *p_name;
char **p_aliases; #if defined(_WIN32)
PRInt16 p_num; #else
PRInt32 p_num; #endif } PRProtoEnt;
Fields
The structure has the following fields:
PR_NETDB_BUF_SIZE
Recommended size to use when specifying a scratch buffer for PR_GetHostByName, PR_GetHostByAddr, PR_GetProtoByName, or PR_GetProtoByNumber.
Syntax
#include <prnetdb.h>
#if defined(AIX) || defined(OSF1)
#define PR_NETDB_BUF_SIZE sizeof(struct protoent_data) #else
#define PR_NETDB_BUF_SIZE 1024 #endif
Network Address Functions
Initializing a Network Address Converting Between a String and a Network Address Getting Host Names and Addresses Getting Protocol Entries Enabling IP v6
Initializing a Network Address
PR_InitializeNetAddr facilitates the use of PRNetAddr, the basic network address structure, in a polymorphic manner. By using these functions with other network address functions, clients can support either version 4 or version 6 of the Internet Protocol transparently.
All NSPR functions that require PRNetAddr as an argument accept either an IPv4 or IPv6 version of the address.
PR_InitializeNetAddr
Initializes or reinitializes a network address. The storage for the network address structure is allocated by, and remains the responsibility of, the calling client.
Syntax
#include <prnetdb.h>
PRStatus PR_InitializeNetAddr(
PRNetAddrValue val,
PRUint16 port,
PRNetAddr *addr);
Parameters
The function has the following parameters:
Returns
The function returns one of the following values:
Description
PR_InitializeNetAddr allows the assignment of special network address values and the port number, while also setting the state that indicates the version of the address being used.
The special network address values are identified by the enum PRNetAddrValue:
typedef enum PRNetAddrValue{
PR_IpAddrNull,
PR_IpAddrAny,
PR_IpAddrLoopback } PRNetAddrValue;
The enum has the following enumerators:
Converting Between a String and a Network Address
PR_StringToNetAddr
Converts a character string to a network address.
Syntax
#include <prnetdb.h>
PRStatus PR_StringToNetAddr(
const char *string,
PRNetAddr *addr);
Parameters
The function has the following parameters:
Returns
The function returns one of the following values:
Description
For IPv4 addresses, the input string represents numbers in the Internet standard "." notation. IPv6 addresses are indicated as strings using ":" characters separating octets, with numerous caveats for shortcutting (see RFC #1884). If the NSPR library and the host are configured to support IPv6, both formats are supported. Otherwise, use of anything other than IPv4 dotted notation results in an error.
PR_NetAddrToString
Converts a network address to a character string.
Syntax
#include <prnetdb.h>
PRStatus PR_NetAddrToString(
const PRNetAddr *addr,
char *string,
PRUint32 size);
Parameters
The function has the following parameters:
Returns
The function returns one of the following values:
Description
The network address to be converted (addr) may be either an IPv4 or IPv6 address structure, assuming that the NSPR library and the host system are both configured to utilize IPv6 addressing.
Getting Host Names and Addresses
PR_GetHostByName
PR_GetHostByAddr
PR_EnumerateHostEnt
PR_GetHostByName
Looks up a host by name.
Syntax
#include <prnetdb.h>
PRStatus PR_GetHostByName(
const char *hostname,
char *buf,
PRIntn bufsize,
PRHostEnt *hostentry);
Parameters
The function has the following parameters:
Returns
The function returns one of the following values:
PR_GetHostByAddr
Looks up a host entry by its network address.
Syntax
#include <prnetdb.h>
PRStatus PR_GetHostByAddr(
const PRNetAddr *hostaddr,
char *buf,
PRIntn bufsize,
PRHostEnt *hostentry);
Parameters
The function has the following parameters:
Returns
The function returns one of the following values:
Description
PR_GetHostByAddr is used to perform reverse lookups of network addresses. That is, given a valid network address (of type PRNetAddr), PR_GetHostByAddr discovers the address' primary name, any aliases, and any other network addresses for the same host.
PR_EnumerateHostEnt
Evaluates each of the possible addresses of a PRHostEnt structure, acquired from PR_GetHostByName or PR_GetHostByAddr.
Syntax
#include <prnetdb.h>
PRIntn PR_EnumerateHostEnt(
PRIntn enumIndex,
const PRHostEnt *hostEnt,
PRUint16 port,
PRNetAddr *address);
Parameters
The function has the following parameters:
Returns
The function returns one of the following values:
Description
PR_EnumerateHostEnt is a stateless enumerator. The principle input, the PRHostEnt structure, is not modified.
Getting Protocol Entries
PR_GetProtoByName
Looks up a protocol entry based on the protocol's name.
Syntax
#include <prnetdb.h>
PRStatus PR_GetProtoByName(
const char* protocolname,
char* buffer,
PRInt32 bufsize,
PRProtoEnt* result);
Parameters
The function has the following parameters:
Returns
The function returns one of the following values:
PR_GetProtoByNumber
Looks up a protocol entry based on protocol's number.
Syntax
#include <prnetdb.h>
PRStatus PR_GetProtoByNumber(
PRInt32 protocolnumber,
char* buffer,
PRInt32 bufsize,
PRProtoEnt* result);
Parameters
The function has the following parameters:
Returns
The function returns one of the following values:
Enabling IP v6
PR_SetIPv6Enable
Enables or disables IPv6 capability on a platform that supports the architecture.
Syntax
#include <prnetdb.h>
PRStatus PR_SetIPv6Enable(PRBool itIs);
Parameter
The function has the following parameter:
Returns
The function returns one of the following values:
Description
For PR_SetIPv6Enable to succeed, IPv6 must first be enabled for the host platform.
If IPv6 is not enabled for the host platform, PR_SetIPv6Enable returns
PR_FAILURE on any attempt to change the setting.
[Contents] [Previous] [Next] [Last]
Last Updated: Mon Jul 13 18:11:48 PDT 1998
Copyright © 1998
Netscape Communications Corporation
|