Commit 94ef248a authored by jan.koester's avatar jan.koester
Browse files

now it works

parent b4d617ee
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -104,9 +104,10 @@ void netplus::socket::setTimeout(int sec){
    }
}

void netplus::socket::copyAddrInfo(ULONG_PTR *dest, ULONG_PTR src){
void netplus::socket::copyAddrInfo(ULONG_PTR *dest, ULONG_PTR src, size_t srclen){

    memcpy((void*)*dest, (void*)src,srclen);

    memcpy((void*)*dest, (void*)src, sizeof(struct addrinfo));
    ((struct addrinfo*)*dest)->ai_addr = (struct sockaddr*)malloc(((struct addrinfo*)src)->ai_addrlen);

    memset(((struct addrinfo*)*dest)->ai_addr,0,((struct addrinfo*)src)->ai_addrlen);
+4 −3
Original line number Diff line number Diff line
@@ -103,10 +103,11 @@ netplus::tcp::tcp(const char* addr, int port,int maxconnections,int sockopts) :
                           rp->ai_protocol);
        if (_Socket == -1)
            continue;
        copyAddrInfo(&_SocketInfo,(ULONG_PTR)rp);
        copyAddrInfo(&_SocketInfo,(ULONG_PTR)rp,sizeof(hints));
        break;
    }

    _SocketInfoLen = sizeof(hints);
    ::freeaddrinfo(result);

    int optval = 1;
@@ -151,7 +152,7 @@ int netplus::tcp::getMaxconnections(){
void netplus::tcp::accept(socket *csock){
    NetException exception;

    copyAddrInfo(&csock->_SocketInfo,_SocketInfo);
    copyAddrInfo(&csock->_SocketInfo,_SocketInfo,_SocketInfoLen);

    socklen_t len=0;

@@ -239,7 +240,7 @@ size_t netplus::tcp::recvData(void* data, unsigned long size,int flags){
void netplus::tcp::connect(socket *ssock){
    NetException exception;

    copyAddrInfo(&_SocketInfo,ssock->_SocketInfo);
    copyAddrInfo(&_SocketInfo,ssock->_SocketInfo, ssock->_SocketInfoLen);

    if( (_Socket=::socket(((struct addrinfo*)_SocketInfo)->ai_family,SOCK_STREAM,0) ) < 0 ){
        NetException exception;
+1 −0
Original line number Diff line number Diff line
@@ -107,6 +107,7 @@ netplus::udp::udp(const char* addr, int port,int maxconnections,int sockopts) :
        break;
    }

    _SocketInfoLen = sizeof(hints);
    ::freeaddrinfo(result);

    int optval = 1;
+1 −1
Original line number Diff line number Diff line
@@ -78,7 +78,7 @@ namespace netplus {
            WSAOVERLAPPED            _Overlapped;
#endif
        protected:
            void copyAddrInfo(ULONG_PTR *dest,ULONG_PTR src);
            void copyAddrInfo(ULONG_PTR *dest,ULONG_PTR src,size_t srclen);
        };
        
        class tcp : public socket{
+13 −8
Original line number Diff line number Diff line
@@ -85,12 +85,17 @@ SOCKET netplus::socket::fd() {
    return _Socket;
}

void netplus::socket::copyAddrInfo(ULONG_PTR *dest, ULONG_PTR src){
        memcpy((void*)*(dest),(void*)src,sizeof(struct addrinfo));
void netplus::socket::copyAddrInfo(ULONG_PTR* dest, ULONG_PTR src, size_t srclen) {

    memcpy((void*)*dest, (void*)src, srclen);

    ((struct addrinfo*)*dest)->ai_addr = (struct sockaddr*)malloc(((struct addrinfo*)src)->ai_addrlen);

    memset(((struct addrinfo*)*dest)->ai_addr, 0, ((struct addrinfo*)src)->ai_addrlen);

    memcpy((void*)((struct addrinfo*)*dest)->ai_addr,
        (void*)((struct addrinfo*)src)->ai_addr,
               ((struct addrinfo*)*(struct addrinfo**)dest)->ai_addrlen
        ((struct addrinfo*)(struct addrinfo*)*dest)->ai_addrlen
    );
    ((struct addrinfo*)*dest)->ai_addrlen = ((struct addrinfo*)src)->ai_addrlen;
}
Loading