Beispiel #1
0
/* 
 * function registered to HOOK_DISPATCHER
 * it is a wrapper to the real one
 */
static void log_info(struct packet_object *po)
{
   /* 
    * skip packet sent (spoofed) by us
    * else we will get duplicated hosts with our mac address
    * this is necessary because check_forwarded() is executed
    * in ec_ip.c, but here we are getting even arp packets...
    */
   EXECUTE(EC_GBL_SNIFF->check_forwarded, po);
   if (po->flags & PO_FORWARDED)
      return;

   /*
    * recheck if the packet is compliant with the visualization filters.
    * we need to redo the test, because here we are hooked to ARP and ICMP
    * packets that are before the test in ec_decode.c
    */
   po->flags |= PO_IGNORE;
   EXECUTE(EC_GBL_SNIFF->interesting, po);
   if ( po->flags & PO_IGNORE )
       return;

   /* if all the tests are ok, write it to the disk */
   if (po->L4.proto == NL_TYPE_ICMP || po->L3.proto == htons(LL_TYPE_ARP))
      log_write_info_arp_icmp(&fdi, po);      
   else
      log_write_info(&fdi, po);
}
Beispiel #2
0
/**
 * Flush the write buffers
 */
void lcb_luv_flush(lcb_luv_socket_t sock)
{
    int status;
    struct lcb_luv_evstate_st *evstate;
    if (sock->write.nb == 0) {
        return;
    }

    evstate = EVSTATE_FIND(sock, WRITE);
    if (EVSTATE_IS(evstate, FLUSHING)) {
        log_write_info("Not flushing because we are in the middle of a flush");
        return;
    }

    sock->write.buf.base = sock->write.data;
    sock->write.buf.len = sock->write.nb;
    log_write_debug("Will flush");
    status = uv_write(&sock->u_req.write,
                      (uv_stream_t *)&sock->tcp,
                      &sock->write.buf, 1, write_cb);
    lcb_luv_socket_ref(sock);

    if (status) {
        evstate->err =
            lcb_luv_errno_map((uv_last_error(sock->parent->loop)).code);
    }
    evstate->flags |= LCB_LUV_EVf_FLUSHING;
}
Beispiel #3
0
static lcb_ssize_t write_common(lcb_luv_socket_t sock,
                                const void *buf,
                                size_t len,
                                int *errno_out)
{
    lcb_ssize_t ret;
    struct lcb_luv_evstate_st *evstate = EVSTATE_FIND(sock, WRITE);

    log_write_debug("%d: Requested to write %d bytes from %p",
                    sock->idx, len, buf);

    if (evstate->err) {
        log_write_warn("Socket has pending error %d", evstate->err);
        *errno_out = evstate->err;
        evstate->err = 0;
        return -1;
    }

    if (EVSTATE_IS(evstate, FLUSHING)) {
        log_write_info("Will not write because we are inside a flush");
        *errno_out = EWOULDBLOCK;
        return -1;
    }

    ret = MINIMUM(len, sizeof(sock->write.data) - sock->write.nb);
    if (ret == 0) {
        log_write_info("We have no more space inside the buffer");
        *errno_out = EWOULDBLOCK;
        return -1;
    }



    memcpy(sock->write.data + sock->write.pos, buf, ret);
    //    lcb_luv_hexdump(sock->write.data + sock->write.pos, ret);
    sock->write.pos += ret;
    sock->write.nb += ret;
    log_write_trace("Returning %d", ret);
    return ret;
}