Exemplo n.º 1
0
/**
 * If connection was broken, return NULL.  If the read timed out, return
 * (char *)-1.
 * @param buf Buffer to get
 * @param len Length
 * @param s Socket
 * @return buffer
 */
char *sgets(char *buf, int len, ano_socket_t s)
{
    int c = 0;
    struct timeval tv;
    fd_set fds;
    char *ptr = buf;

    flush_write_buffer(0);

    if (len == 0)
        return NULL;
    FD_SET(s, &fds);
    tv.tv_sec = ReadTimeout;
    tv.tv_usec = 0;
    while (read_buffer_len() == 0 &&
           (c = select(s + 1, &fds, NULL, NULL, &tv)) < 0) {
        if (ano_sockgeterr() != EINTR)
            break;
        flush_write_buffer(0);
    }
    if (read_buffer_len() == 0 && c == 0)
        return (char *) -1;
    c = sgetc(s);
    while (--len && (*ptr++ = c) != '\n' && (c = sgetc(s)) >= 0);
    if (c < 0)
        return NULL;
    *ptr = 0;
    return buf;
}
Exemplo n.º 2
0
/*---------------------------------------------------------------------------*/
uint16_t network_device_read(void)
{
	if (read_buffer_next())
	{	
		uip_len = read_buffer_len();
		
		for (uint16_t i = 0; i < uip_len; i++)
			uip_buf[i] = read_buffer(i);
		
		return uip_len;
	}
	else
		return 0;
}
Exemplo n.º 3
0
/**
 * Handle STATS commands
 *
 * @param source is the nick of the person whom sent the stats command
 * @param ac is the parameter count
 * @param av is the parameter array
 *
 * @return always returns MOD_CONT
 */
int m_stats(char *source, int ac, char **av)
{
    User *u;
    Dadmin *a;
    int i;

    if (ac < 1)
        return MOD_CONT;

    switch (*av[0]) {
    case 'l':
        u = user_find(source);

        if (u && is_oper(u)) {

            denora_cmd_numeric
                (source, 211,
                 "Server SendBuf SentBytes SentMsgs RecvBuf RecvBytes RecvMsgs ConnTime");
            denora_cmd_numeric(source, 211, "%s %d %d %d %d %d %d %ld",
                               RemoteServer, write_buffer_len(),
                               total_written, total_recmsg,
                               read_buffer_len(), total_read,
                               total_sendmsg,
                               time(NULL) - denora->start_time);
        }

        denora_cmd_219(source, NULL);
        break;
    case 'o':
    case 'O':
/* Check whether the user is an operator */
        u = user_find(source);
        if (u && !is_oper(u) && HideStatsO) {
            denora_cmd_219(source, av[0]);
        } else {
            for (i = 0; i < 1024; i++) {
                for (a = adminlists[i]; a; a = a->next) {
                    denora_cmd_numeric(source, 243, "O * * %s Admin 0",
                                       a->name);
                }
            }
            denora_cmd_219(source, av[0]);
        }

        break;

    case 'u':{
            int uptime = time(NULL) - denora->start_time;
            denora_cmd_numeric(source, 242,
                               ":Stats up %d day%s, %02d:%02d:%02d",
                               uptime / 86400,
                               (uptime / 86400 == 1) ? "" : "s",
                               (uptime / 3600) % 24, (uptime / 60) % 60,
                               uptime % 60);
            denora_cmd_numeric(source, 250,
                               ":Current users: %d (%d ops); maximum %d",
                               stats->users, stats->opers,
                               stats->users_max);
            denora_cmd_219(source, av[0]);
            break;
        }                       /* case 'u' */

    default:
        denora_cmd_219(source, av[0]);
        break;
    }
    return MOD_CONT;
}