Differences From Artifact [07f169cd19]:
- File src/socket.h — part of check-in [374e1a1bfa] at 2021-01-02 22:04:26 on branch trunk — Update copyright (user: js, size: 8133) [annotate] [blame] [check-ins using] [more...]
To Artifact [2b4aae9d25]:
- File
src/OFSocket.h
— part of check-in
[2fcf5a3052]
at
2021-04-29 23:24:22
on branch trunk
— Clean up struct and enum typedefs
With TYPEDEF_HIDES_STRUCT set, Doxygen properly handles anonymous
structs and enums that are typedef'd. (user: js, size: 7772) [annotate] [blame] [check-ins using] [more...]
︙ | ︙ | |||
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | #ifndef OF_HAVE_SOCKETS # error No sockets available! #endif #include <stdbool.h> #import "OFString.h" #ifdef OF_HAVE_SYS_SOCKET_H # include <sys/socket.h> #endif #ifdef OF_HAVE_NETINET_IN_H # include <netinet/in.h> #endif #ifdef OF_HAVE_NETINET_TCP_H # include <netinet/tcp.h> #endif | > > > < < < < < < < < | > | > | | | | | | | 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | #ifndef OF_HAVE_SOCKETS # error No sockets available! #endif #include <stdbool.h> #import "OFString.h" #if defined(OF_HAVE_THREADS) && defined(OF_AMIGAOS) # import "OFTLSKey.h" #endif #ifdef OF_HAVE_SYS_SOCKET_H # include <sys/socket.h> #endif #ifdef OF_HAVE_NETINET_IN_H # include <netinet/in.h> #endif #ifdef OF_HAVE_NETINET_TCP_H # include <netinet/tcp.h> #endif #ifdef OF_HAVE_NETIPX_IPX_H # include <netipx/ipx.h> #endif #ifdef OF_WINDOWS # include <windows.h> # include <ws2tcpip.h> # ifdef OF_HAVE_IPX # include <wsipx.h> # endif #endif /** @file */ #ifdef OF_WII # include <network.h> #endif #ifdef OF_PSP # include <stdint.h> #endif #import "macros.h" OF_ASSUME_NONNULL_BEGIN #ifndef OF_WINDOWS typedef int OFSocketHandle; static const OFSocketHandle OFInvalidSocketHandle = -1; #else typedef SOCKET OFSocketHandle; static const OFSocketHandle OFInvalidSocketHandle = INVALID_SOCKET; #endif #ifdef OF_WII typedef u8 sa_family_t; #endif #ifdef OF_MORPHOS typedef long socklen_t; typedef u_char sa_family_t; typedef u_short in_port_t; #endif /** * @brief A socket address family. */ typedef enum { /** An unknown address family. */ OFSocketAddressFamilyUnknown, /** IPv4 */ OFSocketAddressFamilyIPv4, /** IPv6 */ OFSocketAddressFamilyIPv6, /** IPX */ OFSocketAddressFamilyIPX, /** Any address family */ OFSocketAddressFamilyAny = 255 } OFSocketAddressFamily; #ifndef OF_HAVE_IPV6 struct sockaddr_in6 { sa_family_t sin6_family; in_port_t sin6_port; uint32_t sin6_flowinfo; struct in6_addr { |
︙ | ︙ | |||
125 126 127 128 129 130 131 | # define sipx_family sa_family # define sipx_network sa_netnum # define sipx_node sa_nodenum # define sipx_port sa_socket #endif /** | | | | < | | > | < | | | < | | | < | | | < | | | | | | | < < | | | | | < | | | | | | | | < | | < | | | | | | | | 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 | # define sipx_family sa_family # define sipx_network sa_netnum # define sipx_node sa_nodenum # define sipx_port sa_socket #endif /** * @struct OFSocketAddress OFSocket.h ObjFW/OFSocket.h * * @brief A struct which represents a host / port pair for a socket. */ typedef struct OF_BOXABLE { /* * Even though struct sockaddr contains the family, we need to use our * own family, as we need to support storing an IPv6 address on systems * that don't support IPv6. These may not have AF_INET6 defined and we * can't just define it, as the value is system-dependent and might * clash with an existing value. */ OFSocketAddressFamily family; union { struct sockaddr sockaddr; struct sockaddr_in in; struct sockaddr_in6 in6; struct sockaddr_ipx ipx; } sockaddr; socklen_t length; } OFSocketAddress; #ifdef __cplusplus extern "C" { #endif /** * @brief Parses the specified IP (either v4 or v6) and port into an * @ref OFSocketAddress. * * @param IP The IP to parse * @param port The port to use * @return The parsed IP and port as an OFSocketAddress */ extern OFSocketAddress OFSocketAddressParseIP(OFString *IP, uint16_t port); /** * @brief Parses the specified IPv4 and port into an @ref OFSocketAddress. * * @param IP The IPv4 to parse * @param port The port to use * @return The parsed IPv4 and port as an OFSocketAddress */ extern OFSocketAddress OFSocketAddressParseIPv4(OFString *IP, uint16_t port); /** * @brief Parses the specified IPv6 and port into an @ref OFSocketAddress. * * @param IP The IPv6 to parse * @param port The port to use * @return The parsed IPv6 and port as an OFSocketAddress */ extern OFSocketAddress OFSocketAddressParseIPv6(OFString *IP, uint16_t port); /** * @brief Creates an IPX address for the specified network, node and port. * * @param node The node in the IPX network * @param network The IPX network * @param port The IPX port (sometimes called socket number) on the node */ extern OFSocketAddress OFSocketAddressMakeIPX( const unsigned char node[_Nonnull IPX_NODE_LEN], uint32_t network, uint16_t port); /** * @brief Compares two OFSocketAddress for equality. * * @param address1 The address to compare with the second address * @param address2 The second address * @return Whether the two addresses are equal */ extern bool OFSocketAddressEqual(const OFSocketAddress *_Nonnull address1, const OFSocketAddress *_Nonnull address2); /** * @brief Returns the hash for the specified @ref OFSocketAddress. * * @param address The address to hash * @return The hash for the specified OFSocketAddress */ extern unsigned long OFSocketAddressHash( const OFSocketAddress *_Nonnull address); /** * @brief Converts the specified @ref OFSocketAddress to a string. * * @param address The address to convert to a string * @return The address as an IP string */ extern OFString *_Nonnull OFSocketAddressString( const OFSocketAddress *_Nonnull address); /** * @brief Sets the port of the specified @ref OFSocketAddress, independent of * the address family used. * * @param address The address on which to set the port * @param port The port to set on the address */ extern void OFSocketAddressSetPort(OFSocketAddress *_Nonnull address, uint16_t port); /** * @brief Returns the port of the specified @ref OFSocketAddress, independent of * the address family used. * * @param address The address on which to get the port * @return The port of the address */ extern uint16_t OFSocketAddressPort(const OFSocketAddress *_Nonnull address); /** * @brief Sets the IPX network of the specified @ref OFSocketAddress. * * @param address The address on which to set the IPX network * @param network The IPX network to set on the address */ extern void OFSocketAddressSetIPXNetwork(OFSocketAddress *_Nonnull address, uint32_t network); /** * @brief Returns the IPX network of the specified @ref OFSocketAddress. * * @param address The address on which to get the IPX network * @return The IPX network of the address */ extern uint32_t OFSocketAddressIPXNetwork( const OFSocketAddress *_Nonnull address); /** * @brief Sets the IPX node of the specified @ref OFSocketAddress. * * @param address The address on which to set the IPX node * @param node The IPX node to set on the address */ extern void OFSocketAddressSetIPXNode(OFSocketAddress *_Nonnull address, const unsigned char node[_Nonnull IPX_NODE_LEN]); /** * @brief Gets the IPX node of the specified @ref OFSocketAddress. * * @param address The address on which to get the IPX node * @param node A byte array to store the IPX node of the address */ extern void OFSocketAddressIPXNode(const OFSocketAddress *_Nonnull address, unsigned char node[_Nonnull IPX_NODE_LEN]); extern bool OFSocketInit(void); #if defined(OF_HAVE_THREADS) && defined(OF_AMIGAOS) && !defined(OF_MORPHOS) extern void OFSocketDeinit(void); #endif extern int OFSocketErrNo(void); #if !defined(OF_WII) && !defined(OF_NINTENDO_3DS) extern int OFGetSockName(OFSocketHandle sock, struct sockaddr *restrict addr, socklen_t *restrict addrLen); #endif #if defined(OF_HAVE_THREADS) && defined(OF_AMIGAOS) && !defined(OF_MORPHOS) extern OFTLSKey OFSocketBaseKey; # ifdef OF_AMIGAOS4 extern OFTLSKey OFSocketInterfaceKey; # endif #endif #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END |