From 86e4c225e4cea8f4de1ba0dc38922e872e1c2dca Mon Sep 17 00:00:00 2001
From: John Scipione <jscipione@gmail.com>
Date: Tue, 27 Aug 2013 18:18:05 -0400
Subject: [PATCH] Add length paramter to bind() and connect()
---
headers/private/net/net_protocol.h | 6 +-
src/add-ons/kernel/network/protocols/icmp/icmp.cpp | 6 +-
.../kernel/network/protocols/icmp6/icmp6.cpp | 6 +-
src/add-ons/kernel/network/protocols/ipv4/ipv4.cpp | 10 ++--
src/add-ons/kernel/network/protocols/ipv6/ipv6.cpp | 9 +--
.../network/protocols/tcp/EndpointManager.cpp | 26 ++++----
.../kernel/network/protocols/tcp/EndpointManager.h | 15 ++---
.../kernel/network/protocols/tcp/TCPEndpoint.cpp | 6 +-
.../kernel/network/protocols/tcp/TCPEndpoint.h | 4 +-
src/add-ons/kernel/network/protocols/tcp/tcp.cpp | 10 ++--
src/add-ons/kernel/network/protocols/udp/udp.cpp | 70 +++++++++++++---------
.../kernel/network/protocols/unix/UnixEndpoint.cpp | 9 ++-
.../kernel/network/protocols/unix/UnixEndpoint.h | 4 +-
src/add-ons/kernel/network/protocols/unix/unix.cpp | 10 ++--
src/add-ons/kernel/network/stack/link.cpp | 16 ++---
src/add-ons/kernel/network/stack/net_socket.cpp | 5 +-
16 files changed, 122 insertions(+), 90 deletions(-)
diff --git a/headers/private/net/net_protocol.h b/headers/private/net/net_protocol.h
index 352b8a5..6ff9a1b 100644
a
|
b
|
struct net_protocol_module_info {
|
65 | 65 | status_t (*close)(net_protocol* self); |
66 | 66 | status_t (*free)(net_protocol* self); |
67 | 67 | |
68 | | status_t (*connect)(net_protocol* self, const struct sockaddr* address); |
| 68 | status_t (*connect)(net_protocol* self, const struct sockaddr* address, |
| 69 | socklen_t addressLength); |
69 | 70 | status_t (*accept)(net_protocol* self, net_socket** _acceptedSocket); |
70 | 71 | status_t (*control)(net_protocol* self, int level, int option, |
71 | 72 | void* value, size_t* _length); |
… |
… |
struct net_protocol_module_info {
|
74 | 75 | status_t (*setsockopt)(net_protocol* self, int level, int option, |
75 | 76 | const void* value, int length); |
76 | 77 | |
77 | | status_t (*bind)(net_protocol* self, const struct sockaddr* address); |
| 78 | status_t (*bind)(net_protocol* self, const struct sockaddr* address, |
| 79 | socklen_t addressLength); |
78 | 80 | status_t (*unbind)(net_protocol* self, struct sockaddr* address); |
79 | 81 | status_t (*listen)(net_protocol* self, int count); |
80 | 82 | status_t (*shutdown)(net_protocol* self, int direction); |
diff --git a/src/add-ons/kernel/network/protocols/icmp/icmp.cpp b/src/add-ons/kernel/network/protocols/icmp/icmp.cpp
index 2beff1a..f800d32 100644
a
|
b
|
icmp_free(net_protocol* protocol)
|
291 | 291 | |
292 | 292 | |
293 | 293 | status_t |
294 | | icmp_connect(net_protocol* protocol, const struct sockaddr* address) |
| 294 | icmp_connect(net_protocol* protocol, const struct sockaddr* address, |
| 295 | socklen_t addressLength) |
295 | 296 | { |
296 | 297 | return B_ERROR; |
297 | 298 | } |
… |
… |
icmp_setsockopt(net_protocol* protocol, int level, int option,
|
332 | 333 | |
333 | 334 | |
334 | 335 | status_t |
335 | | icmp_bind(net_protocol* protocol, const struct sockaddr* address) |
| 336 | icmp_bind(net_protocol* protocol, const struct sockaddr* address, |
| 337 | socklen_t addressLength) |
336 | 338 | { |
337 | 339 | return B_ERROR; |
338 | 340 | } |
diff --git a/src/add-ons/kernel/network/protocols/icmp6/icmp6.cpp b/src/add-ons/kernel/network/protocols/icmp6/icmp6.cpp
index 4f2dd1d..b01ad20 100644
a
|
b
|
icmp6_free(net_protocol *protocol)
|
80 | 80 | |
81 | 81 | |
82 | 82 | status_t |
83 | | icmp6_connect(net_protocol *protocol, const struct sockaddr *address) |
| 83 | icmp6_connect(net_protocol *protocol, const struct sockaddr *address, |
| 84 | socklen_t addressLength) |
84 | 85 | { |
85 | 86 | return B_ERROR; |
86 | 87 | } |
… |
… |
icmp6_setsockopt(net_protocol *protocol, int level, int option,
|
121 | 122 | |
122 | 123 | |
123 | 124 | status_t |
124 | | icmp6_bind(net_protocol *protocol, const struct sockaddr *address) |
| 125 | icmp6_bind(net_protocol *protocol, const struct sockaddr *address, |
| 126 | socklen_t addressLength) |
125 | 127 | { |
126 | 128 | return B_ERROR; |
127 | 129 | } |
diff --git a/src/add-ons/kernel/network/protocols/ipv4/ipv4.cpp b/src/add-ons/kernel/network/protocols/ipv4/ipv4.cpp
index 15011da..ee6cc6d 100644
a
|
b
|
ipv4_free(net_protocol* protocol)
|
1100 | 1100 | |
1101 | 1101 | |
1102 | 1102 | status_t |
1103 | | ipv4_connect(net_protocol* protocol, const struct sockaddr* address) |
| 1103 | ipv4_connect(net_protocol* protocol, const struct sockaddr* address, |
| 1104 | socklen_t addressLength) |
1104 | 1105 | { |
1105 | 1106 | return B_ERROR; |
1106 | 1107 | } |
… |
… |
ipv4_setsockopt(net_protocol* _protocol, int level, int option,
|
1312 | 1313 | |
1313 | 1314 | |
1314 | 1315 | status_t |
1315 | | ipv4_bind(net_protocol* protocol, const struct sockaddr* address) |
| 1316 | ipv4_bind(net_protocol* protocol, const struct sockaddr* address, |
| 1317 | socklen_t addressLength) |
1316 | 1318 | { |
1317 | 1319 | if (address->sa_family != AF_INET) |
1318 | 1320 | return EAFNOSUPPORT; |
… |
… |
ipv4_bind(net_protocol* protocol, const struct sockaddr* address)
|
1321 | 1323 | if (((sockaddr_in*)address)->sin_addr.s_addr == INADDR_ANY |
1322 | 1324 | || IN_MULTICAST(ntohl(((sockaddr_in*)address)->sin_addr.s_addr)) |
1323 | 1325 | || sDatalinkModule->is_local_address(sDomain, address, NULL, NULL)) { |
1324 | | memcpy(&protocol->socket->address, address, sizeof(struct sockaddr_in)); |
1325 | | protocol->socket->address.ss_len = sizeof(struct sockaddr_in); |
| 1326 | memcpy(&protocol->socket->address, address, addressLength); |
| 1327 | protocol->socket->address.ss_len = addressLength; |
1326 | 1328 | // explicitly set length, as our callers can't be trusted to |
1327 | 1329 | // always provide the correct length! |
1328 | 1330 | return B_OK; |
diff --git a/src/add-ons/kernel/network/protocols/ipv6/ipv6.cpp b/src/add-ons/kernel/network/protocols/ipv6/ipv6.cpp
index 76a5ec5..44aff2f 100644
a
|
b
|
ipv6_free(net_protocol* protocol)
|
1040 | 1040 | |
1041 | 1041 | |
1042 | 1042 | status_t |
1043 | | ipv6_connect(net_protocol* protocol, const struct sockaddr* address) |
| 1043 | ipv6_connect(net_protocol* protocol, const struct sockaddr* address, |
| 1044 | socklen_t addressLength) |
1044 | 1045 | { |
1045 | 1046 | return B_ERROR; |
1046 | 1047 | } |
… |
… |
ipv6_setsockopt(net_protocol* _protocol, int level, int option,
|
1180 | 1181 | |
1181 | 1182 | |
1182 | 1183 | status_t |
1183 | | ipv6_bind(net_protocol* protocol, const sockaddr* _address) |
| 1184 | ipv6_bind(net_protocol* protocol, const sockaddr* _address, socklen_t addressLength) |
1184 | 1185 | { |
1185 | 1186 | if (_address->sa_family != AF_INET6) |
1186 | 1187 | return EAFNOSUPPORT; |
… |
… |
ipv6_bind(net_protocol* protocol, const sockaddr* _address)
|
1191 | 1192 | if (IN6_IS_ADDR_UNSPECIFIED(&address->sin6_addr) |
1192 | 1193 | || IN6_IS_ADDR_MULTICAST(&address->sin6_addr) |
1193 | 1194 | || sDatalinkModule->is_local_address(sDomain, _address, NULL, NULL)) { |
1194 | | memcpy(&protocol->socket->address, address, sizeof(sockaddr_in6)); |
1195 | | protocol->socket->address.ss_len = sizeof(sockaddr_in6); |
| 1195 | memcpy(&protocol->socket->address, address, addressLength); |
| 1196 | protocol->socket->address.ss_len = addressLength; |
1196 | 1197 | // explicitly set length, as our callers can't be trusted to |
1197 | 1198 | // always provide the correct length! |
1198 | 1199 | return B_OK; |
diff --git a/src/add-ons/kernel/network/protocols/tcp/EndpointManager.cpp b/src/add-ons/kernel/network/protocols/tcp/EndpointManager.cpp
index 1739b63..8dcd2ea 100644
a
|
b
|
EndpointManager::SetPassive(TCPEndpoint* endpoint)
|
294 | 294 | SocketAddressStorage local(AddressModule()); |
295 | 295 | local.SetToEmpty(); |
296 | 296 | |
297 | | status_t status = _BindToEphemeral(endpoint, *local); |
| 297 | status_t status = _BindToEphemeral(endpoint, *local, sizeof(*local)); |
298 | 298 | if (status < B_OK) |
299 | 299 | return status; |
300 | 300 | } |
… |
… |
EndpointManager::FindConnection(sockaddr* local, sockaddr* peer)
|
360 | 360 | |
361 | 361 | |
362 | 362 | status_t |
363 | | EndpointManager::Bind(TCPEndpoint* endpoint, const sockaddr* address) |
| 363 | EndpointManager::Bind(TCPEndpoint* endpoint, const sockaddr* address, |
| 364 | socklen_t addressLength) |
364 | 365 | { |
365 | 366 | // check the family |
366 | 367 | if (!AddressModule()->is_same_family(address)) |
… |
… |
EndpointManager::Bind(TCPEndpoint* endpoint, const sockaddr* address)
|
369 | 370 | WriteLocker locker(fLock); |
370 | 371 | |
371 | 372 | if (AddressModule()->get_port(address) == 0) |
372 | | return _BindToEphemeral(endpoint, address); |
| 373 | return _BindToEphemeral(endpoint, address, addressLength); |
373 | 374 | |
374 | | return _BindToAddress(locker, endpoint, address); |
| 375 | return _BindToAddress(locker, endpoint, address, addressLength); |
375 | 376 | } |
376 | 377 | |
377 | 378 | |
… |
… |
status_t
|
379 | 380 | EndpointManager::BindChild(TCPEndpoint* endpoint) |
380 | 381 | { |
381 | 382 | WriteLocker _(fLock); |
382 | | return _Bind(endpoint, *endpoint->LocalAddress()); |
| 383 | return _Bind(endpoint, *endpoint->LocalAddress(), |
| 384 | sizeof(*endpoint->LocalAddress())); |
383 | 385 | } |
384 | 386 | |
385 | 387 | |
386 | 388 | /*! You must have fLock write locked when calling this method. */ |
387 | 389 | status_t |
388 | 390 | EndpointManager::_BindToAddress(WriteLocker& locker, TCPEndpoint* endpoint, |
389 | | const sockaddr* _address) |
| 391 | const sockaddr* _address, socklen_t addressLength) |
390 | 392 | { |
391 | 393 | ConstSocketAddress address(AddressModule(), _address); |
392 | 394 | uint16 port = address.Port(); |
… |
… |
EndpointManager::_BindToAddress(WriteLocker& locker, TCPEndpoint* endpoint,
|
440 | 442 | } |
441 | 443 | } while (retry-- > 0); |
442 | 444 | |
443 | | return _Bind(endpoint, *address); |
| 445 | return _Bind(endpoint, *address, addressLength); |
444 | 446 | } |
445 | 447 | |
446 | 448 | |
447 | 449 | /*! You must have fLock write locked when calling this method. */ |
448 | 450 | status_t |
449 | 451 | EndpointManager::_BindToEphemeral(TCPEndpoint* endpoint, |
450 | | const sockaddr* address) |
| 452 | const sockaddr* address, socklen_t addressLength) |
451 | 453 | { |
452 | 454 | TRACE(("EndpointManager::BindToEphemeral(%p)\n", endpoint)); |
453 | 455 | |
… |
… |
EndpointManager::_BindToEphemeral(TCPEndpoint* endpoint,
|
477 | 479 | true).Data())); |
478 | 480 | T(Bind(endpoint, newAddress, true)); |
479 | 481 | |
480 | | return _Bind(endpoint, *newAddress); |
| 482 | return _Bind(endpoint, *newAddress, addressLength); |
481 | 483 | } |
482 | 484 | |
483 | 485 | counter += step; |
… |
… |
EndpointManager::_BindToEphemeral(TCPEndpoint* endpoint,
|
490 | 492 | |
491 | 493 | |
492 | 494 | status_t |
493 | | EndpointManager::_Bind(TCPEndpoint* endpoint, const sockaddr* address) |
| 495 | EndpointManager::_Bind(TCPEndpoint* endpoint, const sockaddr* address, |
| 496 | socklen_t addressLength) |
494 | 497 | { |
495 | 498 | // Thus far we have checked if the Bind() is allowed |
496 | 499 | |
497 | | status_t status = endpoint->next->module->bind(endpoint->next, address); |
| 500 | status_t status = endpoint->next->module->bind(endpoint->next, address, |
| 501 | addressLength); |
498 | 502 | if (status < B_OK) |
499 | 503 | return status; |
500 | 504 | |
diff --git a/src/add-ons/kernel/network/protocols/tcp/EndpointManager.h b/src/add-ons/kernel/network/protocols/tcp/EndpointManager.h
index ebe2aea..2e8d070 100644
a
|
b
|
public:
|
80 | 80 | const sockaddr* interfaceLocal); |
81 | 81 | status_t SetPassive(TCPEndpoint* endpoint); |
82 | 82 | |
83 | | status_t Bind(TCPEndpoint* endpoint, |
84 | | const sockaddr* address); |
| 83 | status_t Bind(TCPEndpoint* endpoint, const sockaddr* address, |
| 84 | socklen_t addressLength); |
85 | 85 | status_t BindChild(TCPEndpoint* endpoint); |
86 | 86 | status_t Unbind(TCPEndpoint* endpoint); |
87 | 87 | |
… |
… |
public:
|
97 | 97 | private: |
98 | 98 | TCPEndpoint* _LookupConnection(const sockaddr* local, |
99 | 99 | const sockaddr* peer); |
100 | | status_t _Bind(TCPEndpoint* endpoint, |
101 | | const sockaddr* address); |
| 100 | status_t _Bind(TCPEndpoint* endpoint, const sockaddr* address, |
| 101 | socklen_t addressLength); |
102 | 102 | status_t _BindToAddress(WriteLocker& locker, |
103 | | TCPEndpoint* endpoint, const sockaddr* address); |
104 | | status_t _BindToEphemeral(TCPEndpoint* endpoint, |
105 | | const sockaddr* address); |
| 103 | TCPEndpoint* endpoint, const sockaddr* address, |
| 104 | socklen_t addressLength); |
| 105 | status_t _BindToEphemeral(TCPEndpoint* endpoint, const sockaddr* address, |
| 106 | socklen_t addressLength); |
106 | 107 | |
107 | 108 | typedef BOpenHashTable<ConnectionHashDefinition> ConnectionTable; |
108 | 109 | typedef MultiHashTable<EndpointHashDefinition> EndpointTable; |
diff --git a/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.cpp b/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.cpp
index 8c3fae3..03d66fa 100644
a
|
b
|
TCPEndpoint::Free()
|
580 | 580 | until the connection has been established or refused. |
581 | 581 | */ |
582 | 582 | status_t |
583 | | TCPEndpoint::Connect(const sockaddr* address) |
| 583 | TCPEndpoint::Connect(const sockaddr* address, socklen_t addressLength) |
584 | 584 | { |
585 | 585 | TRACE("Connect() on address %s", PrintAddress(address)); |
586 | 586 | |
… |
… |
TCPEndpoint::Accept(struct net_socket** _acceptedSocket)
|
696 | 696 | |
697 | 697 | |
698 | 698 | status_t |
699 | | TCPEndpoint::Bind(const sockaddr *address) |
| 699 | TCPEndpoint::Bind(const sockaddr *address, socklen_t addressLength) |
700 | 700 | { |
701 | 701 | if (address == NULL) |
702 | 702 | return B_BAD_VALUE; |
… |
… |
TCPEndpoint::Bind(const sockaddr *address)
|
708 | 708 | if (fState != CLOSED) |
709 | 709 | return EISCONN; |
710 | 710 | |
711 | | return fManager->Bind(this, address); |
| 711 | return fManager->Bind(this, address, addressLength); |
712 | 712 | } |
713 | 713 | |
714 | 714 | |
diff --git a/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.h b/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.h
index 085e173..35ed4dd 100644
a
|
b
|
public:
|
51 | 51 | status_t Open(); |
52 | 52 | status_t Close(); |
53 | 53 | void Free(); |
54 | | status_t Connect(const struct sockaddr* address); |
| 54 | status_t Connect(const struct sockaddr* address, socklen_t addressLength); |
55 | 55 | status_t Accept(struct net_socket** _acceptedSocket); |
56 | | status_t Bind(const sockaddr* address); |
| 56 | status_t Bind(const sockaddr* address, socklen_t addressLength); |
57 | 57 | status_t Unbind(struct sockaddr* address); |
58 | 58 | status_t Listen(int count); |
59 | 59 | status_t Shutdown(int direction); |
diff --git a/src/add-ons/kernel/network/protocols/tcp/tcp.cpp b/src/add-ons/kernel/network/protocols/tcp/tcp.cpp
index 7c1dbb4..b0c5a62 100644
a
|
b
|
tcp_free(net_protocol* protocol)
|
503 | 503 | |
504 | 504 | |
505 | 505 | status_t |
506 | | tcp_connect(net_protocol* protocol, const struct sockaddr* address) |
| 506 | tcp_connect(net_protocol* protocol, const struct sockaddr* address, |
| 507 | socklen_t addressLength) |
507 | 508 | { |
508 | | return ((TCPEndpoint*)protocol)->Connect(address); |
| 509 | return ((TCPEndpoint*)protocol)->Connect(address, addressLength); |
509 | 510 | } |
510 | 511 | |
511 | 512 | |
… |
… |
tcp_setsockopt(net_protocol* _protocol, int level, int option,
|
577 | 578 | |
578 | 579 | |
579 | 580 | status_t |
580 | | tcp_bind(net_protocol* protocol, const struct sockaddr* address) |
| 581 | tcp_bind(net_protocol* protocol, const struct sockaddr* address, |
| 582 | socklen_t addressLength) |
581 | 583 | { |
582 | | return ((TCPEndpoint*)protocol)->Bind(address); |
| 584 | return ((TCPEndpoint*)protocol)->Bind(address, addressLength); |
583 | 585 | } |
584 | 586 | |
585 | 587 | |
diff --git a/src/add-ons/kernel/network/protocols/udp/udp.cpp b/src/add-ons/kernel/network/protocols/udp/udp.cpp
index 97926b1..d54967f 100644
a
|
b
|
class UdpEndpoint : public net_protocol, public DatagramSocket<> {
|
75 | 75 | public: |
76 | 76 | UdpEndpoint(net_socket* socket); |
77 | 77 | |
78 | | status_t Bind(const sockaddr* newAddr); |
| 78 | status_t Bind(const sockaddr* newAddr, socklen_t addressLength); |
79 | 79 | status_t Unbind(sockaddr* newAddr); |
80 | | status_t Connect(const sockaddr* newAddr); |
| 80 | status_t Connect(const sockaddr* newAddr, socklen_t addressLength); |
81 | 81 | |
82 | 82 | status_t Open(); |
83 | 83 | status_t Close(); |
… |
… |
public:
|
174 | 174 | status_t DemuxIncomingBuffer(net_buffer* buffer); |
175 | 175 | status_t DeliverError(status_t error, net_buffer* buffer); |
176 | 176 | |
177 | | status_t BindEndpoint(UdpEndpoint *endpoint, const sockaddr *address); |
178 | | status_t ConnectEndpoint(UdpEndpoint *endpoint, const sockaddr *address); |
| 177 | status_t BindEndpoint(UdpEndpoint *endpoint, const sockaddr *address, |
| 178 | socklen_t addressLength); |
| 179 | status_t ConnectEndpoint(UdpEndpoint *endpoint, const sockaddr *address, |
| 180 | socklen_t addressLength); |
179 | 181 | status_t UnbindEndpoint(UdpEndpoint *endpoint); |
180 | 182 | |
181 | 183 | void DumpEndpoints() const; |
182 | 184 | |
183 | 185 | private: |
184 | | status_t _BindEndpoint(UdpEndpoint *endpoint, const sockaddr *address); |
185 | | status_t _Bind(UdpEndpoint *endpoint, const sockaddr *address); |
186 | | status_t _BindToEphemeral(UdpEndpoint *endpoint, const sockaddr *address); |
187 | | status_t _FinishBind(UdpEndpoint *endpoint, const sockaddr *address); |
| 186 | status_t _BindEndpoint(UdpEndpoint *endpoint, const sockaddr *address, |
| 187 | socklen_t addressLength); |
| 188 | status_t _Bind(UdpEndpoint *endpoint, const sockaddr *address, |
| 189 | socklen_t addressLength); |
| 190 | status_t _BindToEphemeral(UdpEndpoint *endpoint, const sockaddr *address, |
| 191 | socklen_t addressLength); |
| 192 | status_t _FinishBind(UdpEndpoint *endpoint, const sockaddr *address, |
| 193 | socklen_t addressLength); |
188 | 194 | |
189 | 195 | UdpEndpoint *_FindActiveEndpoint(const sockaddr *ourAddress, |
190 | 196 | const sockaddr *peerAddress, uint32 index = 0); |
… |
… |
UdpDomainSupport::DeliverError(status_t error, net_buffer* buffer)
|
319 | 325 | |
320 | 326 | status_t |
321 | 327 | UdpDomainSupport::BindEndpoint(UdpEndpoint *endpoint, |
322 | | const sockaddr *address) |
| 328 | const sockaddr *address, socklen_t addressLength) |
323 | 329 | { |
324 | 330 | if (!AddressModule()->is_same_family(address)) |
325 | 331 | return EAFNOSUPPORT; |
… |
… |
UdpDomainSupport::BindEndpoint(UdpEndpoint *endpoint,
|
329 | 335 | if (endpoint->IsActive()) |
330 | 336 | return EINVAL; |
331 | 337 | |
332 | | return _BindEndpoint(endpoint, address); |
| 338 | return _BindEndpoint(endpoint, address, addressLength); |
333 | 339 | } |
334 | 340 | |
335 | 341 | |
336 | 342 | status_t |
337 | 343 | UdpDomainSupport::ConnectEndpoint(UdpEndpoint *endpoint, |
338 | | const sockaddr *address) |
| 344 | const sockaddr *address, socklen_t addressLength) |
339 | 345 | { |
340 | 346 | MutexLocker _(fLock); |
341 | 347 | |
… |
… |
UdpDomainSupport::ConnectEndpoint(UdpEndpoint *endpoint,
|
381 | 387 | |
382 | 388 | // we need to activate no matter whether or not we have just disconnected, |
383 | 389 | // as calling connect() always triggers an implicit bind(): |
384 | | return _BindEndpoint(endpoint, *endpoint->LocalAddress()); |
| 390 | return _BindEndpoint(endpoint, *endpoint->LocalAddress(), |
| 391 | sizeof(*endpoint->LocalAddress())); |
385 | 392 | } |
386 | 393 | |
387 | 394 | |
… |
… |
UdpDomainSupport::DumpEndpoints() const
|
415 | 422 | |
416 | 423 | status_t |
417 | 424 | UdpDomainSupport::_BindEndpoint(UdpEndpoint *endpoint, |
418 | | const sockaddr *address) |
| 425 | const sockaddr *address, socklen_t addressLength) |
419 | 426 | { |
420 | 427 | if (AddressModule()->get_port(address) == 0) |
421 | | return _BindToEphemeral(endpoint, address); |
| 428 | return _BindToEphemeral(endpoint, address, addressLength); |
422 | 429 | |
423 | | return _Bind(endpoint, address); |
| 430 | return _Bind(endpoint, address, addressLength); |
424 | 431 | } |
425 | 432 | |
426 | 433 | |
427 | 434 | status_t |
428 | | UdpDomainSupport::_Bind(UdpEndpoint *endpoint, const sockaddr *address) |
| 435 | UdpDomainSupport::_Bind(UdpEndpoint *endpoint, const sockaddr *address, |
| 436 | socklen_t addressLength) |
429 | 437 | { |
430 | 438 | int socketOptions = endpoint->Socket()->options; |
431 | 439 | |
… |
… |
UdpDomainSupport::_Bind(UdpEndpoint *endpoint, const sockaddr *address)
|
457 | 465 | } |
458 | 466 | } |
459 | 467 | |
460 | | return _FinishBind(endpoint, address); |
| 468 | return _FinishBind(endpoint, address, addressLength); |
461 | 469 | } |
462 | 470 | |
463 | 471 | |
464 | 472 | status_t |
465 | 473 | UdpDomainSupport::_BindToEphemeral(UdpEndpoint *endpoint, |
466 | | const sockaddr *address) |
| 474 | const sockaddr *address, socklen_t addressLength) |
467 | 475 | { |
468 | 476 | SocketAddressStorage newAddress(AddressModule()); |
469 | 477 | status_t status = newAddress.SetTo(address); |
… |
… |
UdpDomainSupport::_BindToEphemeral(UdpEndpoint *endpoint,
|
476 | 484 | |
477 | 485 | newAddress.SetPort(htons(allocedPort)); |
478 | 486 | |
479 | | return _FinishBind(endpoint, *newAddress); |
| 487 | return _FinishBind(endpoint, *newAddress, addressLength); |
480 | 488 | } |
481 | 489 | |
482 | 490 | |
483 | 491 | status_t |
484 | | UdpDomainSupport::_FinishBind(UdpEndpoint *endpoint, const sockaddr *address) |
| 492 | UdpDomainSupport::_FinishBind(UdpEndpoint *endpoint, const sockaddr *address, |
| 493 | socklen_t addressLength) |
485 | 494 | { |
486 | | status_t status = endpoint->next->module->bind(endpoint->next, address); |
| 495 | status_t status = endpoint->next->module->bind(endpoint->next, address, |
| 496 | addressLength); |
487 | 497 | if (status < B_OK) |
488 | 498 | return status; |
489 | 499 | |
… |
… |
UdpEndpoint::UdpEndpoint(net_socket *socket)
|
919 | 929 | |
920 | 930 | |
921 | 931 | status_t |
922 | | UdpEndpoint::Bind(const sockaddr *address) |
| 932 | UdpEndpoint::Bind(const sockaddr *address, socklen_t addressLength) |
923 | 933 | { |
924 | 934 | TRACE_EP("Bind(%s)", AddressString(Domain(), address, true).Data()); |
925 | | return fManager->BindEndpoint(this, address); |
| 935 | return fManager->BindEndpoint(this, address, addressLength); |
926 | 936 | } |
927 | 937 | |
928 | 938 | |
… |
… |
UdpEndpoint::Unbind(sockaddr *address)
|
935 | 945 | |
936 | 946 | |
937 | 947 | status_t |
938 | | UdpEndpoint::Connect(const sockaddr *address) |
| 948 | UdpEndpoint::Connect(const sockaddr *address, socklen_t addressLength) |
939 | 949 | { |
940 | 950 | TRACE_EP("Connect(%s)", AddressString(Domain(), address, true).Data()); |
941 | | return fManager->ConnectEndpoint(this, address); |
| 951 | return fManager->ConnectEndpoint(this, address, addressLength); |
942 | 952 | } |
943 | 953 | |
944 | 954 | |
… |
… |
udp_free(net_protocol *protocol)
|
1141 | 1151 | |
1142 | 1152 | |
1143 | 1153 | status_t |
1144 | | udp_connect(net_protocol *protocol, const struct sockaddr *address) |
| 1154 | udp_connect(net_protocol *protocol, const struct sockaddr *address, |
| 1155 | socklen_t addressLength) |
1145 | 1156 | { |
1146 | | return ((UdpEndpoint *)protocol)->Connect(address); |
| 1157 | return ((UdpEndpoint *)protocol)->Connect(address, addressLength); |
1147 | 1158 | } |
1148 | 1159 | |
1149 | 1160 | |
… |
… |
udp_setsockopt(net_protocol *protocol, int level, int option,
|
1182 | 1193 | |
1183 | 1194 | |
1184 | 1195 | status_t |
1185 | | udp_bind(net_protocol *protocol, const struct sockaddr *address) |
| 1196 | udp_bind(net_protocol *protocol, const struct sockaddr *address, |
| 1197 | socklen_t addressLength) |
1186 | 1198 | { |
1187 | | return ((UdpEndpoint *)protocol)->Bind(address); |
| 1199 | return ((UdpEndpoint *)protocol)->Bind(address, addressLength); |
1188 | 1200 | } |
1189 | 1201 | |
1190 | 1202 | |
diff --git a/src/add-ons/kernel/network/protocols/unix/UnixEndpoint.cpp b/src/add-ons/kernel/network/protocols/unix/UnixEndpoint.cpp
index b2d12b5..884d0d4 100644
a
|
b
|
UnixEndpoint::Free()
|
149 | 149 | |
150 | 150 | |
151 | 151 | status_t |
152 | | UnixEndpoint::Bind(const struct sockaddr *_address) |
| 152 | UnixEndpoint::Bind(const struct sockaddr *_address, socklen_t addressLength) |
153 | 153 | { |
154 | 154 | if (_address->sa_family != AF_UNIX) |
155 | 155 | RETURN_ERROR(EAFNOSUPPORT); |
… |
… |
UnixEndpoint::Bind(const struct sockaddr *_address)
|
206 | 206 | RETURN_ERROR(error); |
207 | 207 | } |
208 | 208 | |
209 | | size_t addressLen = address->sun_path + pathLen + 1 - (char*)address; |
210 | | memcpy(&socket->address, address, addressLen); |
211 | | socket->address.ss_len = addressLen; |
| 209 | memcpy(&socket->address, address, addressLength); |
| 210 | socket->address.ss_len = addressLength; |
212 | 211 | |
213 | 212 | UnixAddressManagerLocker addressLocker(gAddressManager); |
214 | 213 | gAddressManager.Add(this); |
… |
… |
UnixEndpoint::Listen(int backlog)
|
261 | 260 | |
262 | 261 | |
263 | 262 | status_t |
264 | | UnixEndpoint::Connect(const struct sockaddr *_address) |
| 263 | UnixEndpoint::Connect(const struct sockaddr *_address, socklen_t addressLength) |
265 | 264 | { |
266 | 265 | if (_address->sa_family != AF_UNIX) |
267 | 266 | RETURN_ERROR(EAFNOSUPPORT); |
diff --git a/src/add-ons/kernel/network/protocols/unix/UnixEndpoint.h b/src/add-ons/kernel/network/protocols/unix/UnixEndpoint.h
index 5e09fb0..34d1b57 100644
a
|
b
|
public:
|
60 | 60 | mutex_unlock(&fLock); |
61 | 61 | } |
62 | 62 | |
63 | | status_t Bind(const struct sockaddr *_address); |
| 63 | status_t Bind(const struct sockaddr *_address, socklen_t addressLength); |
64 | 64 | status_t Unbind(); |
65 | 65 | status_t Listen(int backlog); |
66 | | status_t Connect(const struct sockaddr *address); |
| 66 | status_t Connect(const struct sockaddr *_address, socklen_t addressLength); |
67 | 67 | status_t Accept(net_socket **_acceptedSocket); |
68 | 68 | |
69 | 69 | ssize_t Send(const iovec *vecs, size_t vecCount, |
diff --git a/src/add-ons/kernel/network/protocols/unix/unix.cpp b/src/add-ons/kernel/network/protocols/unix/unix.cpp
index eec335b..398903c 100644
a
|
b
|
unix_free(net_protocol *_protocol)
|
110 | 110 | |
111 | 111 | |
112 | 112 | status_t |
113 | | unix_connect(net_protocol *_protocol, const struct sockaddr *address) |
| 113 | unix_connect(net_protocol *_protocol, const struct sockaddr *_address, |
| 114 | socklen_t addressLength) |
114 | 115 | { |
115 | | return ((UnixEndpoint*)_protocol)->Connect(address); |
| 116 | return ((UnixEndpoint*)_protocol)->Connect(_address, addressLength); |
116 | 117 | } |
117 | 118 | |
118 | 119 | |
… |
… |
unix_setsockopt(net_protocol *protocol, int level, int option,
|
176 | 177 | |
177 | 178 | |
178 | 179 | status_t |
179 | | unix_bind(net_protocol *_protocol, const struct sockaddr *_address) |
| 180 | unix_bind(net_protocol *_protocol, const struct sockaddr *_address, |
| 181 | socklen_t addressLength) |
180 | 182 | { |
181 | | return ((UnixEndpoint*)_protocol)->Bind(_address); |
| 183 | return ((UnixEndpoint*)_protocol)->Bind(_address, addressLength); |
182 | 184 | } |
183 | 185 | |
184 | 186 | |
diff --git a/src/add-ons/kernel/network/stack/link.cpp b/src/add-ons/kernel/network/stack/link.cpp
index c88f19b..c6fccb1 100644
a
|
b
|
public:
|
50 | 50 | status_t StartMonitoring(const char* deviceName); |
51 | 51 | status_t StopMonitoring(const char* deviceName); |
52 | 52 | |
53 | | status_t Bind(const sockaddr* address); |
| 53 | status_t Bind(const sockaddr* address, socklen_t addressLength); |
54 | 54 | status_t Unbind(); |
55 | 55 | bool IsBound() const |
56 | 56 | { return fBoundToDevice != NULL; } |
… |
… |
LinkProtocol::StopMonitoring(const char* deviceName)
|
140 | 140 | |
141 | 141 | |
142 | 142 | status_t |
143 | | LinkProtocol::Bind(const sockaddr* address) |
| 143 | LinkProtocol::Bind(const sockaddr* address, socklen_t addressLength) |
144 | 144 | { |
145 | 145 | // Only root is allowed to bind to a link layer interface |
146 | 146 | if (address == NULL || geteuid() != 0) |
… |
… |
LinkProtocol::Bind(const sockaddr* address)
|
182 | 182 | fBoundToDevice = boundTo; |
183 | 183 | socket->bound_to_device = boundTo->device->index; |
184 | 184 | |
185 | | memcpy(&socket->address, address, sizeof(struct sockaddr_storage)); |
186 | | socket->address.ss_len = sizeof(struct sockaddr_storage); |
| 185 | memcpy(&socket->address, address, addressLength); |
| 186 | socket->address.ss_len = addressLength; |
187 | 187 | |
188 | 188 | return B_OK; |
189 | 189 | } |
… |
… |
link_free(net_protocol* protocol)
|
337 | 337 | |
338 | 338 | |
339 | 339 | static status_t |
340 | | link_connect(net_protocol* protocol, const struct sockaddr* address) |
| 340 | link_connect(net_protocol* protocol, const struct sockaddr* address, |
| 341 | socklen_t addressLength) |
341 | 342 | { |
342 | 343 | return B_NOT_SUPPORTED; |
343 | 344 | } |
… |
… |
link_setsockopt(net_protocol* protocol, int level, int option,
|
541 | 542 | |
542 | 543 | |
543 | 544 | static status_t |
544 | | link_bind(net_protocol* _protocol, const struct sockaddr* address) |
| 545 | link_bind(net_protocol* _protocol, const struct sockaddr* address, |
| 546 | socklen_t addressLength) |
545 | 547 | { |
546 | 548 | LinkProtocol* protocol = (LinkProtocol*)_protocol; |
547 | | return protocol->Bind(address); |
| 549 | return protocol->Bind(address, addressLength); |
548 | 550 | } |
549 | 551 | |
550 | 552 | |
diff --git a/src/add-ons/kernel/network/stack/net_socket.cpp b/src/add-ons/kernel/network/stack/net_socket.cpp
index 9d5cfc9..ff2c1d4 100644
a
|
b
|
socket_bind(net_socket* socket, const struct sockaddr* address,
|
1014 | 1014 | socket->address.ss_len = sizeof(sockaddr_storage); |
1015 | 1015 | |
1016 | 1016 | status_t status = socket->first_info->bind(socket->first_protocol, |
1017 | | (sockaddr*)address); |
| 1017 | (sockaddr*)address, addressLength); |
1018 | 1018 | if (status != B_OK) { |
1019 | 1019 | // clear address again, as binding failed |
1020 | 1020 | socket->address.ss_len = 0; |
… |
… |
socket_connect(net_socket* socket, const struct sockaddr* address,
|
1038 | 1038 | return status; |
1039 | 1039 | } |
1040 | 1040 | |
1041 | | return socket->first_info->connect(socket->first_protocol, address); |
| 1041 | return socket->first_info->connect(socket->first_protocol, address, |
| 1042 | addressLength); |
1042 | 1043 | } |
1043 | 1044 | |
1044 | 1045 | |