KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
inet.h
Go to the documentation of this file.
1/* KallistiOS ##version##
2
3 arpa/inet.h
4 Copyright (C) 2006, 2007, 2010 Lawrence Sebald
5
6*/
7
8/** \file arpa/inet.h
9 \brief Definitions for internet operations.
10 \ingroup networking_utils
11
12 This file contains the standard definitions (as directed by the POSIX 2008
13 standard) for several internet-related functions.
14
15 \author Lawrence Sebald
16*/
17
18#ifndef __ARPA_INET_H
19#define __ARPA_INET_H
20
21#include <sys/cdefs.h>
22
23__BEGIN_DECLS
24
25/* Bring in <netinet/in.h> to get the in_port_t, in_addr_t, and struct in_addr
26 types. Bring in <inttypes.h> for uint32_t and uint16_t. IEEE Std 1003.1-2008
27 specifically says that <arpa/inet.h> can make all the symbols from these
28 headers visible. */
29#include <netinet/in.h>
30#include <inttypes.h>
31
32/** \defgroup networking_utils Utilities
33 \brief Miscellaneous networking utilities
34 \ingroup networking
35
36 @{
37*/
38
39/** \brief Convert a 32-bit value from host byte order to network byte order.
40 \param value The value to convert.
41 \return value converted to network byte order.
42*/
43uint32_t htonl(uint32_t value);
44
45/** \brief Convert a 32-bit value from network byte order to host byte order.
46 \param value The value to convert.
47 \return value converted to host byte order.
48*/
49uint32_t ntohl(uint32_t value);
50
51/** \brief Convert a 16-bit value from host byte order to network byte order.
52 \param value The value to convert.
53 \return value converted to network byte order.
54*/
55uint16_t htons(uint16_t value);
56
57/** \brief Convert a 16-bit value from network byte order to host byte order.
58 \param value The value to convert.
59 \return value converted to host byte order.
60*/
61uint16_t ntohs(uint16_t value);
62
63/** \brief Convert a string representation of an IPv4 address to an in_addr_t.
64
65 This function converts a "dotted-decimal" string representation of an IPv4
66 address to an in_addr_t for use in a struct in_addr. This function supports
67 all POSIX-required formats for the representation of the address.
68
69 \param cp A string representation of an IPv4 address.
70 \return The binary representation of the requested IPv4
71 address. (in_addr_t)(-1) is returned on error.
72*/
73in_addr_t inet_addr(const char *cp);
74
75/** \brief Convert a string representation of an IPv4 address to a struct
76 in_addr.
77
78 This function, much like inet_addr, converts a string representation of an
79 IPv4 address to a binary representation. This function, however, is
80 non-standard (but seems to appear a lot of places). This function is a
81 little nicer to work with than inet_addr simply because of the fact that the
82 error return from inet_addr happens to actually correspond to a real IPv4
83 address (255.255.255.255). This version actually distinguishes between that
84 address and invalid addresses.
85
86 \param cp A string representation of an IPv4 address.
87 \param pin The destination for the conversion.
88 \retval 0 An invalid IPv4 address was given.
89 \retval 1 Upon successful conversion.
90*/
91int inet_aton(const char *cp, struct in_addr *pin);
92
93/** \brief Convert a string representation of an IP address to its binary
94 representation.
95
96 This function, like inet_addr, converts a string representation of an IP
97 address to its binary representation. This function, unlike inet_aton, is
98 actually standard (in POSIX 2008), and operates very similarly. The only
99 differences between this function and inet_aton are that this function does
100 not support hexadecimal or octal representations and that this function has
101 the ability to support IPv6. This is the function that you should actually
102 use to convert addresses from strings to binary in new code, rather than
103 inet_addr or inet_aton.
104
105 \param af The address family that src is an address in. The
106 only supported values are AF_INET and AF_INET6.
107 \param src A string representation of the address.
108 \param dst Storage for the result. For AF_INET, this must be at
109 least 32-bits in size (the function treats it as a
110 struct in_addr). For AF_INET6, this must be at least
111 128-bits in size (the function treats it as a struct
112 in6_addr).
113 \retval -1 af is unsupported.
114 \retval 0 An invalid address was given.
115 \retval 1 Upon successful conversion.
116
117 \par Error Conditions:
118 \em EAFNOSUPPORT - the specified address family is unsupported
119*/
120int inet_pton(int af, const char *src, void *dst);
121
122/** \brief Convert a binary representation of an IP address to a string.
123
124 This function does the exact opposite of the inet_pton function, converting
125 a binary form of an address to a string. This function, unlike inet_ntoa, is
126 reentrant, and is the function that you should generally use if you need to
127 convert a binary representation of an IP address to a string.
128
129 \param af The address family that src is in. The only
130 supported values are AF_INET and AF_INET6.
131 \param src A binary representation of an IP address.
132 \param dst Storage for the resulting string. This string should
133 be at least 16-bytes long for IPv4, and 46 bytes for
134 IPv6.
135 \param size The length of dst.
136 \retval NULL Upon failed conversion.
137 \retval dst Upon successful conversion.
138
139 \par Error Conditions:
140 \em EAFNOSUPPORT - the specified address family is unsupported \n
141 \em ENOSPC - the size given is insufficient
142*/
143const char *inet_ntop(int af, const void *src, char *dst, socklen_t size);
144
145/** \brief Convert a binary representation of an IPv4 address to a string.
146
147 This function does the exact opposite of the inet_addr function, converting
148 a binary form of an address to a string. This function, unlike inet_ntop
149 is non-reentrant (not thread-safe), and will always only support IPv4
150 addresses. It is suggested to use inet_ntop in any new code.
151
152 \param addr The address to convert.
153 \return A string representation of addr (in dotted-decimal
154 form).
155*/
156char *inet_ntoa(struct in_addr addr);
157
158/** @} */
159
160__END_DECLS
161
162#endif /* __ARPA_INET_H */
uint32_t in_addr_t
32-bit value used to store an IPv4 address.
Definition in.h:43
__uint32_t socklen_t
Socket length type.
Definition socket.h:39
uint32_t htonl(uint32_t value)
Convert a 32-bit value from host byte order to network byte order.
uint16_t ntohs(uint16_t value)
Convert a 16-bit value from network byte order to host byte order.
in_addr_t inet_addr(const char *cp)
Convert a string representation of an IPv4 address to an in_addr_t.
int inet_aton(const char *cp, struct in_addr *pin)
Convert a string representation of an IPv4 address to a struct in_addr.
const char * inet_ntop(int af, const void *src, char *dst, socklen_t size)
Convert a binary representation of an IP address to a string.
char * inet_ntoa(struct in_addr addr)
Convert a binary representation of an IPv4 address to a string.
int inet_pton(int af, const char *src, void *dst)
Convert a string representation of an IP address to its binary representation.
uint32_t ntohl(uint32_t value)
Convert a 32-bit value from network byte order to host byte order.
uint16_t htons(uint16_t value)
Convert a 16-bit value from host byte order to network byte order.
Definitions for the Internet address family.
Structure used to store an IPv4 address.
Definition in.h:49