Ticket #9943: 0001-Add-length-paramter-to-bind-and-connect.patch

File 0001-Add-length-paramter-to-bind-and-connect.patch, 26.6 KB (added by jscipione, 11 years ago)

Add length parameter to bind() and connect()

  • headers/private/net/net_protocol.h

    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 {  
    6565    status_t    (*close)(net_protocol* self);
    6666    status_t    (*free)(net_protocol* self);
    6767
    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);
    6970    status_t    (*accept)(net_protocol* self, net_socket** _acceptedSocket);
    7071    status_t    (*control)(net_protocol* self, int level, int option,
    7172                    void* value, size_t* _length);
    struct net_protocol_module_info {  
    7475    status_t    (*setsockopt)(net_protocol* self, int level, int option,
    7576                    const void* value, int length);
    7677
    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);
    7880    status_t    (*unbind)(net_protocol* self, struct sockaddr* address);
    7981    status_t    (*listen)(net_protocol* self, int count);
    8082    status_t    (*shutdown)(net_protocol* self, int direction);
  • src/add-ons/kernel/network/protocols/icmp/icmp.cpp

    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)  
    291291
    292292
    293293status_t
    294 icmp_connect(net_protocol* protocol, const struct sockaddr* address)
     294icmp_connect(net_protocol* protocol, const struct sockaddr* address,
     295    socklen_t addressLength)
    295296{
    296297    return B_ERROR;
    297298}
    icmp_setsockopt(net_protocol* protocol, int level, int option,  
    332333
    333334
    334335status_t
    335 icmp_bind(net_protocol* protocol, const struct sockaddr* address)
     336icmp_bind(net_protocol* protocol, const struct sockaddr* address,
     337    socklen_t addressLength)
    336338{
    337339    return B_ERROR;
    338340}
  • src/add-ons/kernel/network/protocols/icmp6/icmp6.cpp

    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)  
    8080
    8181
    8282status_t
    83 icmp6_connect(net_protocol *protocol, const struct sockaddr *address)
     83icmp6_connect(net_protocol *protocol, const struct sockaddr *address,
     84    socklen_t addressLength)
    8485{
    8586    return B_ERROR;
    8687}
    icmp6_setsockopt(net_protocol *protocol, int level, int option,  
    121122
    122123
    123124status_t
    124 icmp6_bind(net_protocol *protocol, const struct sockaddr *address)
     125icmp6_bind(net_protocol *protocol, const struct sockaddr *address,
     126    socklen_t addressLength)
    125127{
    126128    return B_ERROR;
    127129}
  • src/add-ons/kernel/network/protocols/ipv4/ipv4.cpp

    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)  
    11001100
    11011101
    11021102status_t
    1103 ipv4_connect(net_protocol* protocol, const struct sockaddr* address)
     1103ipv4_connect(net_protocol* protocol, const struct sockaddr* address,
     1104    socklen_t addressLength)
    11041105{
    11051106    return B_ERROR;
    11061107}
    ipv4_setsockopt(net_protocol* _protocol, int level, int option,  
    13121313
    13131314
    13141315status_t
    1315 ipv4_bind(net_protocol* protocol, const struct sockaddr* address)
     1316ipv4_bind(net_protocol* protocol, const struct sockaddr* address,
     1317    socklen_t addressLength)
    13161318{
    13171319    if (address->sa_family != AF_INET)
    13181320        return EAFNOSUPPORT;
    ipv4_bind(net_protocol* protocol, const struct sockaddr* address)  
    13211323    if (((sockaddr_in*)address)->sin_addr.s_addr == INADDR_ANY
    13221324        || IN_MULTICAST(ntohl(((sockaddr_in*)address)->sin_addr.s_addr))
    13231325        || 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;
    13261328            // explicitly set length, as our callers can't be trusted to
    13271329            // always provide the correct length!
    13281330        return B_OK;
  • src/add-ons/kernel/network/protocols/ipv6/ipv6.cpp

    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)  
    10401040
    10411041
    10421042status_t
    1043 ipv6_connect(net_protocol* protocol, const struct sockaddr* address)
     1043ipv6_connect(net_protocol* protocol, const struct sockaddr* address,
     1044    socklen_t addressLength)
    10441045{
    10451046    return B_ERROR;
    10461047}
    ipv6_setsockopt(net_protocol* _protocol, int level, int option,  
    11801181
    11811182
    11821183status_t
    1183 ipv6_bind(net_protocol* protocol, const sockaddr* _address)
     1184ipv6_bind(net_protocol* protocol, const sockaddr* _address, socklen_t addressLength)
    11841185{
    11851186    if (_address->sa_family != AF_INET6)
    11861187        return EAFNOSUPPORT;
    ipv6_bind(net_protocol* protocol, const sockaddr* _address)  
    11911192    if (IN6_IS_ADDR_UNSPECIFIED(&address->sin6_addr)
    11921193        || IN6_IS_ADDR_MULTICAST(&address->sin6_addr)
    11931194        || 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;
    11961197            // explicitly set length, as our callers can't be trusted to
    11971198            // always provide the correct length!
    11981199        return B_OK;
  • src/add-ons/kernel/network/protocols/tcp/EndpointManager.cpp

    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)  
    294294        SocketAddressStorage local(AddressModule());
    295295        local.SetToEmpty();
    296296
    297         status_t status = _BindToEphemeral(endpoint, *local);
     297        status_t status = _BindToEphemeral(endpoint, *local, sizeof(*local));
    298298        if (status < B_OK)
    299299            return status;
    300300    }
    EndpointManager::FindConnection(sockaddr* local, sockaddr* peer)  
    360360
    361361
    362362status_t
    363 EndpointManager::Bind(TCPEndpoint* endpoint, const sockaddr* address)
     363EndpointManager::Bind(TCPEndpoint* endpoint, const sockaddr* address,
     364    socklen_t addressLength)
    364365{
    365366    // check the family
    366367    if (!AddressModule()->is_same_family(address))
    EndpointManager::Bind(TCPEndpoint* endpoint, const sockaddr* address)  
    369370    WriteLocker locker(fLock);
    370371
    371372    if (AddressModule()->get_port(address) == 0)
    372         return _BindToEphemeral(endpoint, address);
     373        return _BindToEphemeral(endpoint, address, addressLength);
    373374
    374     return _BindToAddress(locker, endpoint, address);
     375    return _BindToAddress(locker, endpoint, address, addressLength);
    375376}
    376377
    377378
    status_t  
    379380EndpointManager::BindChild(TCPEndpoint* endpoint)
    380381{
    381382    WriteLocker _(fLock);
    382     return _Bind(endpoint, *endpoint->LocalAddress());
     383    return _Bind(endpoint, *endpoint->LocalAddress(),
     384        sizeof(*endpoint->LocalAddress()));
    383385}
    384386
    385387
    386388/*! You must have fLock write locked when calling this method. */
    387389status_t
    388390EndpointManager::_BindToAddress(WriteLocker& locker, TCPEndpoint* endpoint,
    389     const sockaddr* _address)
     391    const sockaddr* _address, socklen_t addressLength)
    390392{
    391393    ConstSocketAddress address(AddressModule(), _address);
    392394    uint16 port = address.Port();
    EndpointManager::_BindToAddress(WriteLocker& locker, TCPEndpoint* endpoint,  
    440442        }
    441443    } while (retry-- > 0);
    442444
    443     return _Bind(endpoint, *address);
     445    return _Bind(endpoint, *address, addressLength);
    444446}
    445447
    446448
    447449/*! You must have fLock write locked when calling this method. */
    448450status_t
    449451EndpointManager::_BindToEphemeral(TCPEndpoint* endpoint,
    450     const sockaddr* address)
     452    const sockaddr* address, socklen_t addressLength)
    451453{
    452454    TRACE(("EndpointManager::BindToEphemeral(%p)\n", endpoint));
    453455
    EndpointManager::_BindToEphemeral(TCPEndpoint* endpoint,  
    477479                    true).Data()));
    478480                T(Bind(endpoint, newAddress, true));
    479481
    480                 return _Bind(endpoint, *newAddress);
     482                return _Bind(endpoint, *newAddress, addressLength);
    481483            }
    482484
    483485            counter += step;
    EndpointManager::_BindToEphemeral(TCPEndpoint* endpoint,  
    490492
    491493
    492494status_t
    493 EndpointManager::_Bind(TCPEndpoint* endpoint, const sockaddr* address)
     495EndpointManager::_Bind(TCPEndpoint* endpoint, const sockaddr* address,
     496    socklen_t addressLength)
    494497{
    495498    // Thus far we have checked if the Bind() is allowed
    496499
    497     status_t status = endpoint->next->module->bind(endpoint->next, address);
     500    status_t status = endpoint->next->module->bind(endpoint->next, address,
     501        addressLength);
    498502    if (status < B_OK)
    499503        return status;
    500504
  • src/add-ons/kernel/network/protocols/tcp/EndpointManager.h

    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:  
    8080                                const sockaddr* interfaceLocal);
    8181            status_t        SetPassive(TCPEndpoint* endpoint);
    8282
    83             status_t        Bind(TCPEndpoint* endpoint,
    84                                 const sockaddr* address);
     83            status_t        Bind(TCPEndpoint* endpoint, const sockaddr* address,
     84                                socklen_t addressLength);
    8585            status_t        BindChild(TCPEndpoint* endpoint);
    8686            status_t        Unbind(TCPEndpoint* endpoint);
    8787
    public:  
    9797private:
    9898            TCPEndpoint*    _LookupConnection(const sockaddr* local,
    9999                                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);
    102102            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);
    106107
    107108    typedef BOpenHashTable<ConnectionHashDefinition> ConnectionTable;
    108109    typedef MultiHashTable<EndpointHashDefinition> EndpointTable;
  • src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.cpp

    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()  
    580580    until the connection has been established or refused.
    581581*/
    582582status_t
    583 TCPEndpoint::Connect(const sockaddr* address)
     583TCPEndpoint::Connect(const sockaddr* address, socklen_t addressLength)
    584584{
    585585    TRACE("Connect() on address %s", PrintAddress(address));
    586586
    TCPEndpoint::Accept(struct net_socket** _acceptedSocket)  
    696696
    697697
    698698status_t
    699 TCPEndpoint::Bind(const sockaddr *address)
     699TCPEndpoint::Bind(const sockaddr *address, socklen_t addressLength)
    700700{
    701701    if (address == NULL)
    702702        return B_BAD_VALUE;
    TCPEndpoint::Bind(const sockaddr *address)  
    708708    if (fState != CLOSED)
    709709        return EISCONN;
    710710
    711     return fManager->Bind(this, address);
     711    return fManager->Bind(this, address, addressLength);
    712712}
    713713
    714714
  • src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.h

    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:  
    5151            status_t    Open();
    5252            status_t    Close();
    5353            void        Free();
    54             status_t    Connect(const struct sockaddr* address);
     54            status_t    Connect(const struct sockaddr* address, socklen_t addressLength);
    5555            status_t    Accept(struct net_socket** _acceptedSocket);
    56             status_t    Bind(const sockaddr* address);
     56            status_t    Bind(const sockaddr* address, socklen_t addressLength);
    5757            status_t    Unbind(struct sockaddr* address);
    5858            status_t    Listen(int count);
    5959            status_t    Shutdown(int direction);
  • src/add-ons/kernel/network/protocols/tcp/tcp.cpp

    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)  
    503503
    504504
    505505status_t
    506 tcp_connect(net_protocol* protocol, const struct sockaddr* address)
     506tcp_connect(net_protocol* protocol, const struct sockaddr* address,
     507    socklen_t addressLength)
    507508{
    508     return ((TCPEndpoint*)protocol)->Connect(address);
     509    return ((TCPEndpoint*)protocol)->Connect(address, addressLength);
    509510}
    510511
    511512
    tcp_setsockopt(net_protocol* _protocol, int level, int option,  
    577578
    578579
    579580status_t
    580 tcp_bind(net_protocol* protocol, const struct sockaddr* address)
     581tcp_bind(net_protocol* protocol, const struct sockaddr* address,
     582    socklen_t addressLength)
    581583{
    582     return ((TCPEndpoint*)protocol)->Bind(address);
     584    return ((TCPEndpoint*)protocol)->Bind(address, addressLength);
    583585}
    584586
    585587
  • src/add-ons/kernel/network/protocols/udp/udp.cpp

    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<> {  
    7575public:
    7676                                UdpEndpoint(net_socket* socket);
    7777
    78             status_t            Bind(const sockaddr* newAddr);
     78            status_t            Bind(const sockaddr* newAddr, socklen_t addressLength);
    7979            status_t            Unbind(sockaddr* newAddr);
    80             status_t            Connect(const sockaddr* newAddr);
     80            status_t            Connect(const sockaddr* newAddr, socklen_t addressLength);
    8181
    8282            status_t            Open();
    8383            status_t            Close();
    public:  
    174174    status_t DemuxIncomingBuffer(net_buffer* buffer);
    175175    status_t DeliverError(status_t error, net_buffer* buffer);
    176176
    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);
    179181    status_t UnbindEndpoint(UdpEndpoint *endpoint);
    180182
    181183    void DumpEndpoints() const;
    182184
    183185private:
    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);
    188194
    189195    UdpEndpoint *_FindActiveEndpoint(const sockaddr *ourAddress,
    190196        const sockaddr *peerAddress, uint32 index = 0);
    UdpDomainSupport::DeliverError(status_t error, net_buffer* buffer)  
    319325
    320326status_t
    321327UdpDomainSupport::BindEndpoint(UdpEndpoint *endpoint,
    322     const sockaddr *address)
     328    const sockaddr *address, socklen_t addressLength)
    323329{
    324330    if (!AddressModule()->is_same_family(address))
    325331        return EAFNOSUPPORT;
    UdpDomainSupport::BindEndpoint(UdpEndpoint *endpoint,  
    329335    if (endpoint->IsActive())
    330336        return EINVAL;
    331337
    332     return _BindEndpoint(endpoint, address);
     338    return _BindEndpoint(endpoint, address, addressLength);
    333339}
    334340
    335341
    336342status_t
    337343UdpDomainSupport::ConnectEndpoint(UdpEndpoint *endpoint,
    338     const sockaddr *address)
     344    const sockaddr *address, socklen_t addressLength)
    339345{
    340346    MutexLocker _(fLock);
    341347
    UdpDomainSupport::ConnectEndpoint(UdpEndpoint *endpoint,  
    381387
    382388    // we need to activate no matter whether or not we have just disconnected,
    383389    // as calling connect() always triggers an implicit bind():
    384     return _BindEndpoint(endpoint, *endpoint->LocalAddress());
     390    return _BindEndpoint(endpoint, *endpoint->LocalAddress(),
     391        sizeof(*endpoint->LocalAddress()));
    385392}
    386393
    387394
    UdpDomainSupport::DumpEndpoints() const  
    415422
    416423status_t
    417424UdpDomainSupport::_BindEndpoint(UdpEndpoint *endpoint,
    418     const sockaddr *address)
     425    const sockaddr *address, socklen_t addressLength)
    419426{
    420427    if (AddressModule()->get_port(address) == 0)
    421         return _BindToEphemeral(endpoint, address);
     428        return _BindToEphemeral(endpoint, address, addressLength);
    422429
    423     return _Bind(endpoint, address);
     430    return _Bind(endpoint, address, addressLength);
    424431}
    425432
    426433
    427434status_t
    428 UdpDomainSupport::_Bind(UdpEndpoint *endpoint, const sockaddr *address)
     435UdpDomainSupport::_Bind(UdpEndpoint *endpoint, const sockaddr *address,
     436    socklen_t addressLength)
    429437{
    430438    int socketOptions = endpoint->Socket()->options;
    431439
    UdpDomainSupport::_Bind(UdpEndpoint *endpoint, const sockaddr *address)  
    457465        }
    458466    }
    459467
    460     return _FinishBind(endpoint, address);
     468    return _FinishBind(endpoint, address, addressLength);
    461469}
    462470
    463471
    464472status_t
    465473UdpDomainSupport::_BindToEphemeral(UdpEndpoint *endpoint,
    466     const sockaddr *address)
     474    const sockaddr *address, socklen_t addressLength)
    467475{
    468476    SocketAddressStorage newAddress(AddressModule());
    469477    status_t status = newAddress.SetTo(address);
    UdpDomainSupport::_BindToEphemeral(UdpEndpoint *endpoint,  
    476484
    477485    newAddress.SetPort(htons(allocedPort));
    478486
    479     return _FinishBind(endpoint, *newAddress);
     487    return _FinishBind(endpoint, *newAddress, addressLength);
    480488}
    481489
    482490
    483491status_t
    484 UdpDomainSupport::_FinishBind(UdpEndpoint *endpoint, const sockaddr *address)
     492UdpDomainSupport::_FinishBind(UdpEndpoint *endpoint, const sockaddr *address,
     493    socklen_t addressLength)
    485494{
    486     status_t status = endpoint->next->module->bind(endpoint->next, address);
     495    status_t status = endpoint->next->module->bind(endpoint->next, address,
     496        addressLength);
    487497    if (status < B_OK)
    488498        return status;
    489499
    UdpEndpoint::UdpEndpoint(net_socket *socket)  
    919929
    920930
    921931status_t
    922 UdpEndpoint::Bind(const sockaddr *address)
     932UdpEndpoint::Bind(const sockaddr *address, socklen_t addressLength)
    923933{
    924934    TRACE_EP("Bind(%s)", AddressString(Domain(), address, true).Data());
    925     return fManager->BindEndpoint(this, address);
     935    return fManager->BindEndpoint(this, address, addressLength);
    926936}
    927937
    928938
    UdpEndpoint::Unbind(sockaddr *address)  
    935945
    936946
    937947status_t
    938 UdpEndpoint::Connect(const sockaddr *address)
     948UdpEndpoint::Connect(const sockaddr *address, socklen_t addressLength)
    939949{
    940950    TRACE_EP("Connect(%s)", AddressString(Domain(), address, true).Data());
    941     return fManager->ConnectEndpoint(this, address);
     951    return fManager->ConnectEndpoint(this, address, addressLength);
    942952}
    943953
    944954
    udp_free(net_protocol *protocol)  
    11411151
    11421152
    11431153status_t
    1144 udp_connect(net_protocol *protocol, const struct sockaddr *address)
     1154udp_connect(net_protocol *protocol, const struct sockaddr *address,
     1155    socklen_t addressLength)
    11451156{
    1146     return ((UdpEndpoint *)protocol)->Connect(address);
     1157    return ((UdpEndpoint *)protocol)->Connect(address, addressLength);
    11471158}
    11481159
    11491160
    udp_setsockopt(net_protocol *protocol, int level, int option,  
    11821193
    11831194
    11841195status_t
    1185 udp_bind(net_protocol *protocol, const struct sockaddr *address)
     1196udp_bind(net_protocol *protocol, const struct sockaddr *address,
     1197    socklen_t addressLength)
    11861198{
    1187     return ((UdpEndpoint *)protocol)->Bind(address);
     1199    return ((UdpEndpoint *)protocol)->Bind(address, addressLength);
    11881200}
    11891201
    11901202
  • src/add-ons/kernel/network/protocols/unix/UnixEndpoint.cpp

    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()  
    149149
    150150
    151151status_t
    152 UnixEndpoint::Bind(const struct sockaddr *_address)
     152UnixEndpoint::Bind(const struct sockaddr *_address, socklen_t addressLength)
    153153{
    154154    if (_address->sa_family != AF_UNIX)
    155155        RETURN_ERROR(EAFNOSUPPORT);
    UnixEndpoint::Bind(const struct sockaddr *_address)  
    206206            RETURN_ERROR(error);
    207207        }
    208208
    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;
    212211
    213212        UnixAddressManagerLocker addressLocker(gAddressManager);
    214213        gAddressManager.Add(this);
    UnixEndpoint::Listen(int backlog)  
    261260
    262261
    263262status_t
    264 UnixEndpoint::Connect(const struct sockaddr *_address)
     263UnixEndpoint::Connect(const struct sockaddr *_address, socklen_t addressLength)
    265264{
    266265    if (_address->sa_family != AF_UNIX)
    267266        RETURN_ERROR(EAFNOSUPPORT);
  • src/add-ons/kernel/network/protocols/unix/UnixEndpoint.h

    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:  
    6060        mutex_unlock(&fLock);
    6161    }
    6262
    63     status_t Bind(const struct sockaddr *_address);
     63    status_t Bind(const struct sockaddr *_address, socklen_t addressLength);
    6464    status_t Unbind();
    6565    status_t Listen(int backlog);
    66     status_t Connect(const struct sockaddr *address);
     66    status_t Connect(const struct sockaddr *_address, socklen_t addressLength);
    6767    status_t Accept(net_socket **_acceptedSocket);
    6868
    6969    ssize_t Send(const iovec *vecs, size_t vecCount,
  • src/add-ons/kernel/network/protocols/unix/unix.cpp

    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)  
    110110
    111111
    112112status_t
    113 unix_connect(net_protocol *_protocol, const struct sockaddr *address)
     113unix_connect(net_protocol *_protocol, const struct sockaddr *_address,
     114    socklen_t addressLength)
    114115{
    115     return ((UnixEndpoint*)_protocol)->Connect(address);
     116    return ((UnixEndpoint*)_protocol)->Connect(_address, addressLength);
    116117}
    117118
    118119
    unix_setsockopt(net_protocol *protocol, int level, int option,  
    176177
    177178
    178179status_t
    179 unix_bind(net_protocol *_protocol, const struct sockaddr *_address)
     180unix_bind(net_protocol *_protocol, const struct sockaddr *_address,
     181    socklen_t addressLength)
    180182{
    181     return ((UnixEndpoint*)_protocol)->Bind(_address);
     183    return ((UnixEndpoint*)_protocol)->Bind(_address, addressLength);
    182184}
    183185
    184186
  • src/add-ons/kernel/network/stack/link.cpp

    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:  
    5050            status_t            StartMonitoring(const char* deviceName);
    5151            status_t            StopMonitoring(const char* deviceName);
    5252
    53             status_t            Bind(const sockaddr* address);
     53            status_t            Bind(const sockaddr* address, socklen_t addressLength);
    5454            status_t            Unbind();
    5555            bool                IsBound() const
    5656                                    { return fBoundToDevice != NULL; }
    LinkProtocol::StopMonitoring(const char* deviceName)  
    140140
    141141
    142142status_t
    143 LinkProtocol::Bind(const sockaddr* address)
     143LinkProtocol::Bind(const sockaddr* address, socklen_t addressLength)
    144144{
    145145    // Only root is allowed to bind to a link layer interface
    146146    if (address == NULL || geteuid() != 0)
    LinkProtocol::Bind(const sockaddr* address)  
    182182    fBoundToDevice = boundTo;
    183183    socket->bound_to_device = boundTo->device->index;
    184184
    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;
    187187
    188188    return B_OK;
    189189}
    link_free(net_protocol* protocol)  
    337337
    338338
    339339static status_t
    340 link_connect(net_protocol* protocol, const struct sockaddr* address)
     340link_connect(net_protocol* protocol, const struct sockaddr* address,
     341    socklen_t addressLength)
    341342{
    342343    return B_NOT_SUPPORTED;
    343344}
    link_setsockopt(net_protocol* protocol, int level, int option,  
    541542
    542543
    543544static status_t
    544 link_bind(net_protocol* _protocol, const struct sockaddr* address)
     545link_bind(net_protocol* _protocol, const struct sockaddr* address,
     546    socklen_t addressLength)
    545547{
    546548    LinkProtocol* protocol = (LinkProtocol*)_protocol;
    547     return protocol->Bind(address);
     549    return protocol->Bind(address, addressLength);
    548550}
    549551
    550552
  • src/add-ons/kernel/network/stack/net_socket.cpp

    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,  
    10141014    socket->address.ss_len = sizeof(sockaddr_storage);
    10151015
    10161016    status_t status = socket->first_info->bind(socket->first_protocol,
    1017         (sockaddr*)address);
     1017        (sockaddr*)address, addressLength);
    10181018    if (status != B_OK) {
    10191019        // clear address again, as binding failed
    10201020        socket->address.ss_len = 0;
    socket_connect(net_socket* socket, const struct sockaddr* address,  
    10381038            return status;
    10391039    }
    10401040
    1041     return socket->first_info->connect(socket->first_protocol, address);
     1041    return socket->first_info->connect(socket->first_protocol, address,
     1042        addressLength);
    10421043}
    10431044
    10441045