1getnameinfo(3XNET)X/Open Networking Services Library Functionsgetnameinfo(3XNET)
2
3
4

NAME

6       getnameinfo - get name information
7

SYNOPSIS

9       cc [ flag ... ] file ... -lxnet [ library ... ]
10       #include <sys/socket.h>
11       #include <netdb.h>
12
13       int getnameinfo(const struct sockaddr *restrict sa, socklen_t salen,
14            char *restrict node, socklen_t nodelen, char *restrict service,
15            socklen_t servicelen, unsigned flags);
16
17

DESCRIPTION

19       The  getnameinfo()  function translates a socket address to a node name
20       and  service  location,  all  of  which  are  defined  as   in   getad‐
21       drinfo(3XNET).
22
23
24       The  sa argument points to a socket address structure to be translated.
25       If the socket address structure contains an IPv4-mapped IPv6 address or
26       an IPv4-compatible IPv6 address, the implementation extracts the embed‐
27       ded IPv4 address and lookup the node name for that IPv4 address.
28
29
30       If the node argument is non-NULL and the nodelen argument is  non-zero,
31       then the node argument points to a buffer able to contain up to nodelen
32       characters that receives the node name as a null-terminated string.  If
33       the  node  argument  is  NULL or the nodelen argument is zero, the node
34       name is not returned. If the node's name cannot be located, the numeric
35       form of the node's address is returned instead of its name.
36
37
38       If the service argument is non-NULL and the servicelen argument is non-
39       zero, then the service argument points to a buffer able to  contain  up
40       to servicelen bytes that receives the service name as a null-terminated
41       string. If the service argument is NULL or the servicelen  argument  is
42       zero, the service name is not returned. If the service's name cannot be
43       located, the numeric form of the service address (for example, its port
44       number) is returned instead of its name.
45
46
47       The  flags  argument  is a flag that changes the default actions of the
48       function. By default the fully-qualified domain  name  (FQDN)  for  the
49       host is returned, but:
50
51           o      If the flag bit NI_NOFQDN is set, only the node name portion
52                  of the FQDN is returned for local hosts.
53
54           o      If the flag bit NI_NUMERICHOST is set, the numeric  form  of
55                  the  host's  address  is returned instead of its name, under
56                  all circumstances.
57
58           o      If the flag bit NI_NAMEREQD is set, an error is returned  if
59                  the host's name cannot be located.
60
61           o      If  the  flag bit NI_NUMERICSERV is set, the numeric form of
62                  the service address is returned (for example, its port  num‐
63                  ber) instead of its name, under all circumstances.
64
65           o      If  the  flag  bit  NI_DGRAM is set, this indicates that the
66                  service is a  datagram  service  (SOCK_DGRAM).  The  default
67                  behavior  assumes  that  the  service  is  a  stream service
68                  (SOCK_STREAM).
69

RETURN VALUES

71       A 0 return value for getnameinfo() indicates successful  completion;  a
72       non-zero  return  value  indicates failure. The possible values for the
73       failures are listed in the ERRORS section.
74
75
76       Upon successful completion, getnameinfo() returns the node and  service
77       names,  if  requested,  in the buffers provided. The returned names are
78       always null-terminated strings.
79

ERRORS

81       The getnameinfo() function will fail if:
82
83       EAI_AGAIN       The name could not be resolved  at  this  time.  Future
84                       attempts might succeed.
85
86
87       EAI_BADFLAGS    The flags argument had an invalid value.
88
89
90       EAI_FAIL        A non-recoverable error occurred.
91
92
93       EAI_FAMILY      The  address  family  was not recognized or the address
94                       length was invalid for the specified family.
95
96
97       EAI_MEMORY      There was a memory allocation failure.
98
99
100       EAI_NONAME      The name does not resolve for the supplied  parameters.
101                       NI_NAMEREQD  is  set  and  the  host's  name  cannot be
102                       located, or both nodename and servname were NULL.
103
104
105       EAI_SYSTEM      A system error occurred. The error code can be found in
106                       errno.
107
108

USAGE

110       If the returned values are to be used as part of any further name reso‐
111       lution (for example, passed to getaddrinfo()), applications should pro‐
112       vide buffers large enough to store any result possible on the system.
113
114
115       Given the IPv4-mapped IPv6 address "::ffff:1.2.3.4", the implementation
116       performs a lookup as if the socket address structure contains the  IPv4
117       address "1.2.3.4".
118

ATTRIBUTES

120       See attributes(5) for descriptions of the following attributes:
121
122
123
124
125       ┌─────────────────────────────┬─────────────────────────────┐
126       │      ATTRIBUTE TYPE         │      ATTRIBUTE VALUE        │
127       ├─────────────────────────────┼─────────────────────────────┤
128       │Interface Stability          │Standard                     │
129       ├─────────────────────────────┼─────────────────────────────┤
130       │MT-Level                     │MT-Safe                      │
131       └─────────────────────────────┴─────────────────────────────┘
132

SEE ALSO

134       gai_strerror(3XNET),      getaddrinfo(3XNET),     getservbyname(3XNET),
135       socket(3XNET), attributes(5), standards(5)
136

NOTES

138       The IPv6 unspecified address  ("::")  and  the  IPv6  loopback  address
139       ("::1")  are  not IPv4-compatible addresses. If the address is the IPv6
140       unspecified address ("::"), a lookup is not performed, and the  EAI_NO‐
141       NAME error is returned.
142
143
144       The  two  NI_NUMERICxxx  flags are required to support the -n flag that
145       many commands provide.
146
147
148       The NI_DGRAM flag is required for the few  AF_INET  and  AF_INET6  port
149       numbers  (for example, [512,514]) that represent different services for
150       UDP and TCP.
151
152
153
154SunOS 5.11                        1 Nov 2003                getnameinfo(3XNET)
Impressum