Ejemplo n.º 1
0
/* Handle a RST 38 (system call) */
int handle_sys(int scall, int parameter) 
{
        char buffer[2];
        switch (scall) {
                case 0: {
                        /* Read in from telnet */
                        if (flags&DSOCKETS) {
                                return socket_get(tsocket);
                        }
                        return 0;
                        break;
                }
                case 1: {
                        /* Write to telnet */
                        if (flags&DSOCKETS) {
                                buffer[0]=(parameter&0x0ff);
                                return socket_write( tsocket, buffer, 1);
                        }
                        return -1;
                }
                case 2: {
                        /* Return !0 if data is available */
                        if (flags&DSOCKETS) {
                                return socket_poll( tsocket );
                        }
                        return -1;
                }
        }
        return 0;
}
Ejemplo n.º 2
0
int client_init(int s)
{
	sockinfo *i;
	struct client *c;
	int newfd;

	i = socket_accept(s);
	if(!i)
		return 0;

	/* We have the connection details, but not the actual
	 * file decriptor itself, use socket.c to extract it
	 * for us.
	 */
	newfd = socket_get(i);

	/* First new client - list needs creating */
	if(!clients)
	{
		clients = calloc(newfd, sizeof(struct client *));
		maxfd = newfd;
	}

	/* This fd is the largest fd we've ever seen
	 * so the client array won't be big enough for it.
	 * Reallocate it big enough for the new fd
	 * and zero all of the memory between the
	 * previous biggest and the new biggest.
	 */
	if(newfd > maxfd)
	{
		clients = realloc(clients, 
			sizeof(struct client *) * (newfd + 1));
		memset(&clients[maxfd + 1], 0, 
			(newfd - maxfd) * sizeof(struct client *));
		maxfd = newfd;
	}


	c = malloc(sizeof(struct client));
	c->si = i;
	c->buffer = buffer_init();
	c->ch = character_init(c);
	c->state = CONNECTING;

	clients[newfd] = c;

	parse(c);

	/* The server wants this fd so it can update the
	 * file descriptor read set.
	 */
	return newfd;
}
Ejemplo n.º 3
0
void client_destroy(client *c)
{
	int fd;

	fd = socket_get(c->si);
	clients[fd] = NULL;

	socket_free(c->si);
	buffer_free(c->buffer);
	character_free(c->ch);
	free(c);
}