Пример #1
0
int LshttpdMain::processAdminSockConn(int fd)
{
    char achBuf[4096];
    char *pEnd = &achBuf[4096];
    char *p = achBuf;
    int len;
    while ((len = ls_fio_read(fd, p, pEnd - p)) > 0)
        p += len;

    if ((len == -1) || (pEnd == p))
    {
        LS_ERROR("[ADMIN] failed to read command, command buf len=%d",
                 (int)(p - achBuf));
        return LS_FAIL;
    }
    char *pEndAuth = strchr(achBuf, '\n');
    if (!pEndAuth)
        return LS_FAIL;
    if (m_pServer->authAdminReq(achBuf) != 0)
        return LS_FAIL;
    ++pEndAuth;
    return processAdminBuffer(pEndAuth, p);

}
Пример #2
0
struct ifi_info *parse_proc_net()
{
    struct ifi_info   *ifi, *ifihead, **ifipnext;
    int fd;
    char achBuf[8192];
    fd = ls_fio_open("/proc/net/if_inet6", O_RDONLY, 0644);
    if (fd == -1)
        return NULL;
    int ret, total = 0;
    while ((ret = ls_fio_read(fd, &achBuf[total],
                              sizeof(achBuf) - total - 1)) > 0)
    {
        total += ret;
        if (total >= (int)sizeof(achBuf) - 1)
            break;
    }
    ls_fio_close(fd);

    struct sockaddr_in6 addr;
    char *pEnd = &achBuf[total];
    char *pLineEnd;
    char *p = achBuf;
    *pEnd = 0;
    addr.sin6_family = AF_INET6;

    ifihead = NULL;
    ifipnext = &ifihead;
    while (p < pEnd)
    {
        pLineEnd = strchr(p, '\n');
        if (!pLineEnd)
            pLineEnd = pEnd;
        *pLineEnd = 0;
        if (pLineEnd - p > 45)
        {
            int index, prefix, scope, flag;
            char achName[256];
            StringTool::hexDecode(p, 32, (char *)&addr.sin6_addr);
            if (sscanf(p + 32, " %x %x %x %x %s", &index, &prefix,
                       &scope, &flag, achName) == 5)
            {
                if (scope != 32)
                {
                    ifi = (struct ifi_info *)calloc(1, sizeof(struct ifi_info));
                    *ifipnext = ifi;            /* prev points to this new one */
                    ifipnext = &ifi->ifi_next;    /* pointer to next one goes here */

                    ifi->ifi_flags = flag;        /* IFF_xxx values */
                    memmove(ifi->ifi_name, achName, IFI_NAME);
                    ifi->ifi_name[IFI_NAME - 1] = '\0';
                    if (ifi->ifi_addr == NULL)
                    {
                        ifi->ifi_addr = (sockaddr *)calloc(1, sizeof(struct sockaddr_in6));
                        memmove(ifi->ifi_addr, &addr, sizeof(struct sockaddr_in6));
                    }

                }
            }
        }

        p = pLineEnd + 1;
    }
    return ifihead;

}