Differences From Artifact [61fa5cfa02]:
- File
src/OFUDPSocket.m
— 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: 5043) [annotate] [blame] [check-ins using] [more...]
To Artifact [080326bc21]:
- File src/OFUDPSocket.m — part of check-in [35b565d369] at 2022-10-22 15:07:57 on branch trunk — Rename OFBind{ -> Socket}FailedException (user: js, size: 5085) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
31 32 33 34 35 36 37 | #import "OFDNSResolver.h" #import "OFData.h" #import "OFSocket.h" #import "OFSocket+Private.h" #import "OFThread.h" #import "OFAlreadyConnectedException.h" | | | | 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 | #import "OFDNSResolver.h" #import "OFData.h" #import "OFSocket.h" #import "OFSocket+Private.h" #import "OFThread.h" #import "OFAlreadyConnectedException.h" #import "OFBindSocketFailedException.h" @implementation OFUDPSocket @dynamic delegate; - (uint16_t)of_bindToAddress: (OFSocketAddress *)address extraType: (int)extraType OF_DIRECT { void *pool = objc_autoreleasePoolPush(); uint16_t port; #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC) int flags; #endif if ((_socket = socket( ((struct sockaddr *)&address->sockaddr)->sa_family, SOCK_DGRAM | SOCK_CLOEXEC | extraType, 0)) == OFInvalidSocketHandle) @throw [OFBindSocketFailedException exceptionWithHost: OFSocketAddressString(address) port: OFSocketAddressPort(address) socket: self errNo: OFSocketErrNo()]; _canBlock = true; |
︙ | ︙ | |||
73 74 75 76 77 78 79 | if (bind(_socket, (struct sockaddr *)&address->sockaddr, address->length) != 0) { int errNo = OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; | | | 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | if (bind(_socket, (struct sockaddr *)&address->sockaddr, address->length) != 0) { int errNo = OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; @throw [OFBindSocketFailedException exceptionWithHost: OFSocketAddressString(address) port: OFSocketAddressPort(address) socket: self errNo: errNo]; } #if defined(OF_HPUX) || defined(OF_WII) || defined(OF_NINTENDO_3DS) } else { |
︙ | ︙ | |||
103 104 105 106 107 108 109 | int errNo = OFSocketErrNo(); OFString *host = OFSocketAddressString(address); port = OFSocketAddressPort(address); closesocket(_socket); _socket = OFInvalidSocketHandle; | | | 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | int errNo = OFSocketErrNo(); OFString *host = OFSocketAddressString(address); port = OFSocketAddressPort(address); closesocket(_socket); _socket = OFInvalidSocketHandle; @throw [OFBindSocketFailedException exceptionWithHost: host port: port socket: self errNo: errNo]; } } } |
︙ | ︙ | |||
129 130 131 132 133 134 135 | if (OFGetSockName(_socket, (struct sockaddr *)&address->sockaddr, &address->length) != 0) { int errNo = OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; | | | | | 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 | if (OFGetSockName(_socket, (struct sockaddr *)&address->sockaddr, &address->length) != 0) { int errNo = OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; @throw [OFBindSocketFailedException exceptionWithHost: OFSocketAddressString(address) port: OFSocketAddressPort(address) socket: self errNo: errNo]; } switch (((struct sockaddr *)&address->sockaddr)->sa_family) { case AF_INET: return OFFromBigEndian16(address->sockaddr.in.sin_port); # ifdef OF_HAVE_IPV6 case AF_INET6: return OFFromBigEndian16(address->sockaddr.in6.sin6_port); # endif default: closesocket(_socket); _socket = OFInvalidSocketHandle; @throw [OFBindSocketFailedException exceptionWithHost: OFSocketAddressString(address) port: OFSocketAddressPort(address) socket: self errNo: EAFNOSUPPORT]; } #else closesocket(_socket); _socket = OFInvalidSocketHandle; @throw [OFBindSocketFailedException exceptionWithHost: OFSocketAddressString(address) port: OFSocketAddressPort(address) socket: self errNo: EADDRNOTAVAIL]; #endif } |
︙ | ︙ |