Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Questions about accept in src/desock.c #62

Open
thinkycx opened this issue Aug 15, 2019 · 0 comments
Open

Questions about accept in src/desock.c #62

thinkycx opened this issue Aug 15, 2019 · 0 comments

Comments

@thinkycx
Copy link

thinkycx commented Aug 15, 2019

Hello! Thanks for your awesome codes!
Here I have some questions about the accept function in src/desock.c. After writte the accept function ,I think all the accept will return a fake addr and port (0.0.0.0:9000) and addrlen which will have an influence on the normal request ?

int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
{
	if (preeny_desock_did_accept)
		exit(0);
	preeny_desock_did_accept = 1;

	//initialize a sockaddr_in for the peer
	 struct sockaddr_in peer_addr;
	 memset(&peer_addr, '0', sizeof(struct sockaddr_in));

	//Set the contents in the peer's sock_addr. 
	//Make sure the contents will simulate a real client that connects with the intercepted server, as the server may depend on the contents to make further decisions. 
	//The followings set-up should be fine with Nginx.
	 peer_addr.sin_family = AF_INET;
	 peer_addr.sin_addr.s_addr = htonl(INADDR_ANY);
         peer_addr.sin_port = htons(9000); 

	//copy the initialized peer_addr back to the original sockaddr. Note the space for the original sockaddr, namely addr, has already been allocated
	if (addr) memcpy(addr, &peer_addr, sizeof(struct sockaddr_in));

	if (preeny_socket_threads_to_front[sockfd]) return dup(sockfd);
	else return original_accept(sockfd, addr, addrlen);
}

So I think we should change the if (preeny_socket_threads_to_front[sockfd]) like the following? If it is correct, I am glad to pull a request to update it.

int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
{
    if (preeny_socket_threads_to_front[sockfd]) 
    {
        if (preeny_desock_did_accept)
            exit(0);
        preeny_desock_did_accept = 1;

        //initialize a sockaddr_in for the peer
        struct sockaddr_in peer_addr;
        memset(&peer_addr, '0', sizeof(struct sockaddr_in));

        //Set the contents in the peer's sock_addr. 
        //Make sure the contents will simulate a real client that connects with the intercepted server, as the server may depend on the contents to make further decisions. 
        //The followings set-up should be fine with Nginx.
        peer_addr.sin_family = AF_INET;
        peer_addr.sin_addr.s_addr = htonl(INADDR_ANY);
            peer_addr.sin_port = htons(9000); 

        //copy the initialized peer_addr back to the original sockaddr. Note the space for the original sockaddr, namely addr, has already been allocated
        if (addr) memcpy(addr, &peer_addr, sizeof(struct sockaddr_in));

        return dup(sockfd);
    }
    else return original_accept(sockfd, addr, addrlen);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant