Beispiel #1
0
int
client_parse(struct session *s)
{
	/* Reset any previous command. */
	s->cmd = CMD_NONE;
	s->port = 0;

	/* Commands we are looking for are at least 4 chars long. */
	if (linelen < 4)
		return (1);

	if (linebuf[0] == 'P' || linebuf[0] == 'p' ||
	    linebuf[0] == 'E' || linebuf[0] == 'e') {
		if (!client_parse_cmd(s))
			return (0);

		/*
		 * Allow active mode connections immediately, instead of
		 * waiting for a positive reply from the server.  Some
		 * rare servers/proxies try to probe or setup the data
		 * connection before an actual transfer request.
		 */
		if (s->cmd == CMD_PORT || s->cmd == CMD_EPRT)
			return (allow_data_connection(s));
	}
	
	if (anonymous_only && (linebuf[0] == 'U' || linebuf[0] == 'u'))
		return (client_parse_anon(s));

	return (1);
}
Beispiel #2
0
void client_main(int csock, struct sockaddr_in *client_addr)
{
    //printf("client connected: %s\n", inet_ntoa(client_addr->sin_addr));
    uint8_t cmd;
    while(1) {
        int n = recv(csock, &cmd, sizeof(cmd), 0);

        if(n == 0) {
            //printf("client disconnected\n");
            if(close(csock) == -1)
                printf("close failed: %s\n", strerror(errno));
            break;
        }
        else if(n == -1) {
            printf("read error: %s\n", strerror(errno));
            if(close(csock) == -1)
                printf("close failed: %s\n", strerror(errno));
            break;
        }

        if(client_parse_cmd(csock, client_addr, cmd) <= 0)
            break;
    }
}