Exemple #1
0
int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
{
    int fd, ret, envfd;
    static void * (*func)();
    if (!func) func = (void *(*)()) dlsym(RTLD_NEXT, "accept");
    DEBUG("accept(%d, _, _) called\n", sockfd);

    fd = (int) func(sockfd, addr, addrlen);

    if (_WS_sockfd == 0) {
        _WS_sockfd = fd;

        if (!_WS_rbuf) {
            if (! _WS_init()) {
                RET_ERROR(ENOMEM, "Could not allocate interposer buffer\n");
            }
        }

        ret = _WS_handshake(_WS_sockfd);
        if (ret < 0) {
            errno = EPROTO;
            return ret;
        }
        MSG("interposing on fd %d\n", _WS_sockfd);
    } else {
        DEBUG("already interposing on fd %d\n", _WS_sockfd);
    }

    return fd;
}
Exemple #2
0
int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
{
    int fd, ret, envfd;
    static void * (*func)();
    if (!func) func = (void *(*)()) dlsym(RTLD_NEXT, "accept");
    DEBUG("accept(%d, _, _) called\n", sockfd);

    fd = (int) func(sockfd, addr, addrlen);

    if (_WS_listen_fd == -1) {
        DEBUG("not interposing\n");
        return fd;
    }

    if (_WS_listen_fd != sockfd) {
        DEBUG("not interposing on fd %d\n", sockfd);
        return fd;
    }


    if (_WS_connections[fd]) {
        MSG("error, already interposing on fd %d\n", fd);
    } else {
        /* It's a port we're interposing on so allocate memory for it */
        if (! (_WS_connections[fd] = malloc(sizeof(_WS_connection)))) {
            RET_ERROR(ENOMEM, "Could not allocate interposer memory\n");
        }
        _WS_connections[fd]->rcarry_cnt = 0;
        _WS_connections[fd]->rcarry[0]  = '\0';
        _WS_connections[fd]->newframe   = 1;

        ret = _WS_handshake(fd);
        if (ret < 0) {
            free(_WS_connections[fd]);
            _WS_connections[fd] = NULL;
            errno = EPROTO;
            return ret;
        }
        MSG("interposing on fd %d (allocated memory)\n", fd);
    }

    return fd;
}