Differences From Artifact [0929d955af]:
- File
src/OFSocket.h
— part of check-in
[25adea9a23]
at
2022-08-06 21:14:31
on branch trunk
— Don't use struct sockaddr in OFSocketAddress
struct sockaddr can contain a variable length array, which breaks the
union. (user: js, size: 8480) [annotate] [blame] [check-ins using] [more...]
To Artifact [18fc1aa593]:
- File src/OFSocket.h — part of check-in [019ff77f50] at 2022-10-31 21:41:38 on branch trunk — Check for and use <netat/appletalk.h> (user: js, size: 11939) [annotate] [blame] [check-ins using] [more...]
︙ | ︙ | |||
31 32 33 34 35 36 37 | #endif #ifdef OF_HAVE_NETINET_IN_H # include <netinet/in.h> #endif #ifdef OF_HAVE_NETINET_TCP_H # include <netinet/tcp.h> #endif | < < < > > > > > > > > > > > | 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 | #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_SYS_UN_H # include <sys/un.h> #endif #ifdef OF_HAVE_AFUNIX_H # include <afunix.h> #endif #ifdef OF_HAVE_NETIPX_IPX_H # include <netipx/ipx.h> #endif #if defined(OF_HAVE_NETAT_APPLETALK_H) # include <netat/appletalk.h> #elif defined(OF_HAVE_NETATALK_AT_H) # include <netatalk/at.h> #endif #ifdef OF_WINDOWS # include <windows.h> # include <ws2tcpip.h> # ifdef OF_HAVE_IPX # include <wsipx.h> # endif # ifdef OF_HAVE_APPLETALK # include <atalkwsh.h> # endif #endif /** @file */ #ifdef OF_WII # include <network.h> |
︙ | ︙ | |||
99 100 101 102 103 104 105 106 107 108 109 110 111 112 | OFSocketAddressFamilyIPv4, /** IPv6 */ OFSocketAddressFamilyIPv6, /** UNIX */ OFSocketAddressFamilyUNIX, /** IPX */ OFSocketAddressFamilyIPX, /** Any address family */ OFSocketAddressFamilyAny = 255 } OFSocketAddressFamily; #ifndef OF_HAVE_IPV6 struct sockaddr_in6 { sa_family_t sin6_family; | > > | 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | OFSocketAddressFamilyIPv4, /** IPv6 */ OFSocketAddressFamilyIPv6, /** UNIX */ OFSocketAddressFamilyUNIX, /** IPX */ OFSocketAddressFamilyIPX, /** AppleTalk */ OFSocketAddressFamilyAppleTalk, /** Any address family */ OFSocketAddressFamilyAny = 255 } OFSocketAddressFamily; #ifndef OF_HAVE_IPV6 struct sockaddr_in6 { sa_family_t sin6_family; |
︙ | ︙ | |||
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 | # define IPX_NODE_LEN 6 # 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 { OFSocketAddressFamily family; /* * We can't use struct sockaddr as it can contain variable length * arrays. */ union { struct sockaddr_in in; struct sockaddr_in6 in6; struct sockaddr_un un; 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 a UNIX socket address from the specified path. * * @param path The path of the UNIX socket * @return A UNIX socket address with the specified path */ extern OFSocketAddress OFSocketAddressMakeUNIX(OFString *path); /** | > > > > > > > > > > > > > > > > > > > > > | > > > > > > > > > > > > | 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 | # define IPX_NODE_LEN 6 # define sipx_family sa_family # define sipx_network sa_netnum # define sipx_node sa_nodenum # define sipx_port sa_socket #endif #ifndef OF_HAVE_APPLETALK struct sockaddr_at { sa_family_t sat_family; uint8_t sat_port; struct at_addr { uint16_t s_net; uint8_t s_node; } sat_addr; }; #endif #ifdef OF_WINDOWS # define sat_port sat_socket #else # define sat_net sat_addr.s_net # define sat_node sat_addr.s_node #endif /** * @struct OFSocketAddress OFSocket.h ObjFW/OFSocket.h * * @brief A struct which represents a host / port pair for a socket. */ typedef struct OF_BOXABLE { OFSocketAddressFamily family; /* * We can't use struct sockaddr as it can contain variable length * arrays. */ union { struct sockaddr_in in; struct sockaddr_in6 in6; struct sockaddr_un un; struct sockaddr_ipx ipx; struct sockaddr_at at; } 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 * @throw OFInvalidFormatException The specified string is not a valid IP */ 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 * @throw OFInvalidFormatException The specified string is not a valid IPv4 */ 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 * @throw OFInvalidFormatException The specified string is not a valid IPv6 */ extern OFSocketAddress OFSocketAddressParseIPv6(OFString *IP, uint16_t port); /** * @brief Creates a UNIX socket address from the specified path. * * @param path The path of the UNIX socket * @return A UNIX socket address with the specified path */ extern OFSocketAddress OFSocketAddressMakeUNIX(OFString *path); /** * @brief Creates an IPX address for the specified network, node and port. * * @param network The IPX network * @param node The node in the IPX network * @param port The IPX port (sometimes called socket number) on the node * @return An IPX socket address with the specified node, network and port. */ extern OFSocketAddress OFSocketAddressMakeIPX(uint32_t network, const unsigned char node[_Nonnull IPX_NODE_LEN], uint16_t port); /** * @brief Creates an AppleTalk address for the specified network, node and port. * * @param network The AppleTalk network * @param node The node in the AppleTalk network * @param port The AppleTalk (sometimes called socket number) on the node * @return An AppleTalk socket address with the specified node, network and * port. */ extern OFSocketAddress OFSocketAddressMakeAppleTalk(uint16_t network, uint8_t node, uint8_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 */ |
︙ | ︙ | |||
239 240 241 242 243 244 245 | * @param address The address to convert to a string * @return The address as an IP string */ extern OFString *_Nonnull OFSocketAddressString( const OFSocketAddress *_Nonnull address); /** | | < | | < | | 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 | * @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 IP port of the specified @ref OFSocketAddress. * * @param address The address on which to set the port * @param port The port to set on the address */ extern void OFSocketAddressSetIPPort(OFSocketAddress *_Nonnull address, uint16_t port); /** * @brief Returns the IP port of the specified @ref OFSocketAddress. * * @param address The address on which to get the port * @return The port of the address */ extern uint16_t OFSocketAddressIPPort(const OFSocketAddress *_Nonnull address); /** * @brief Gets the UNIX socket path of the specified @ref OFSocketAddress. * * @param address The address on which to get the UNIX socket path * @return The UNIX socket path */ |
︙ | ︙ | |||
299 300 301 302 303 304 305 | /** * @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 */ | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 | /** * @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 OFSocketAddressGetIPXNode(const OFSocketAddress *_Nonnull address, unsigned char node[_Nonnull IPX_NODE_LEN]); /** * @brief Sets the IPX port of the specified @ref OFSocketAddress. * * @param address The address on which to set the port * @param port The port to set on the address */ extern void OFSocketAddressSetIPXPort(OFSocketAddress *_Nonnull address, uint16_t port); /** * @brief Returns the IPX port of the specified @ref OFSocketAddress. * * @param address The address on which to get the port * @return The port of the address */ extern uint16_t OFSocketAddressIPXPort(const OFSocketAddress *_Nonnull address); /** * @brief Sets the AppleTalk network of the specified @ref OFSocketAddress. * * @param address The address on which to set the AppleTalk network * @param network The AppleTalk network to set on the address */ extern void OFSocketAddressSetAppleTalkNetwork( OFSocketAddress *_Nonnull address, uint16_t network); /** * @brief Returns the AppleTalk network of the specified @ref OFSocketAddress. * * @param address The address on which to get the AppleTalk network * @return The AppleTalk network of the address */ extern uint16_t OFSocketAddressAppleTalkNetwork( const OFSocketAddress *_Nonnull address); /** * @brief Sets the AppleTalk node of the specified @ref OFSocketAddress. * * @param address The address on which to set the AppleTalk node * @param node The AppleTalk node to set on the address */ extern void OFSocketAddressSetAppleTalkNode(OFSocketAddress *_Nonnull address, uint8_t node); /** * @brief Gets the AppleTalk node of the specified @ref OFSocketAddress. * * @param address The address on which to get the AppleTalk node * @return The AppleTalk node of the address */ extern uint8_t OFSocketAddressAppleTalkNode( const OFSocketAddress *_Nonnull address); /** * @brief Sets the AppleTalk port of the specified @ref OFSocketAddress. * * @param address The address on which to set the port * @param port The port to set on the address */ extern void OFSocketAddressSetAppleTalkPort(OFSocketAddress *_Nonnull address, uint8_t port); /** * @brief Returns the AppleTalk port of the specified @ref OFSocketAddress. * * @param address The address on which to get the port * @return The port of the address */ extern uint8_t OFSocketAddressAppleTalkPort( const OFSocketAddress *_Nonnull address); 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, |
︙ | ︙ |