Ejemplo n.º 1
0
Archivo: PACKET.C Proyecto: barmi/tcpip
void
check_buffer()
{
    if (driver_type == SLIP_DRIVER) {
        union REGS ireg, oreg;

        ireg.h.ah = 6;
        ireg.x.cx = _DS;
        ireg.x.dx = (unsigned)RING_BUFFER;
loop:		//rprintf("BEFORE SLIP");
        int86(packet_int, &ireg, &oreg);
        //rprintf("AFTER SLIP");
        if (oreg.x.ax) {
            statistics.lanInPackets++;
            rcv_ip();
            goto loop;
        }
    } else {
        while (Frame_Count || Tick_Count) {
            if (Frame_Count) {
                if (!PACKET_SIZE(Rtail))
                    Rtail = 0;
                packet_buffer = RING_BUFFER + Rtail + 2;
                rcv_packet();
                Rtail += (PACKET_SIZE(Rtail) + 2);
                disable();
                Frame_Count--;
                enable();
            }
            if (Tick_Count) {
                tmr_service();
            }
        }
    }
}
Ejemplo n.º 2
0
int main(int argc, char **argv)
{
    struct sigaction action;
    char *pps_filename;
    char *lat_filename;
    uint64_t expected_packets;
    socklen_t len = 4;
    int enabled = 1;
    int val = 0;
    unsigned char *buffers = (unsigned char *)malloc(BUFFER_SIZE * NUM_BUFFERS);

    pps = (unsigned int *)malloc(sizeof(unsigned int) * MAX_SECONDS);

    memset(pps, 0, sizeof(unsigned int) * MAX_SECONDS);

    if (!handle_opts(argc, argv, &expected_packets, &pps_filename, &lat_filename))
    {
        printf("%s", USAGE);
        return 0;
    }

    if (pps_filename)
    {
        pps_output = fopen(pps_filename, "a+");
        if (!pps_output)
            ERROR("Failed to open/create file: %s, %s", pps_filename, strerror(errno));
    }
    else
    {
        pps_output = stdout;
    }

    if (lat_filename)
    {
        lat_output = fopen(lat_filename, "a+");
        if (!lat_output)
            ERROR("Failed to open/create file: %s, %s", lat_filename, strerror(errno));
    }
    else
    {
        lat_output = stdout;
    }

    if (hdr_init(LOWEST_LAT_US, HIGHEST_LAT_US, 4, &hist) != 0)
    {
        ERROR("Failed to init histogram");
        return -1;
    }

    sock_raw = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
    if (sock_raw < 0)
        ERROR("Socket error: %s", strerror(errno));

    if (setsockopt(sock_raw, SOL_SOCKET, SO_TIMESTAMPNS,
                   &enabled, sizeof(enabled)) < 0 ||
        getsockopt(sock_raw, SOL_SOCKET, SO_TIMESTAMPNS, &val, &len) < 0 ||
        val == 0)
    {
        ERROR("Failed to configure rx timestamps: %s", strerror(errno));
    }

    memset(&action, 0, sizeof(struct sigaction));
    action.sa_handler = on_signal;
    sigaction(SIGINT, &action, NULL);

    if (expected_packets == 0)
        expected_packets = ~UINT64_C(0);

    while (received_packets < expected_packets)
    {
        int npkts = rcv_packet(sock_raw, buffers, hist);
        if (npkts == 0)
            continue;
        if (start == -1)
            start = time(NULL);
        uint64_t second = time(NULL) - start;
        pps[second] += npkts;
        received_packets += npkts;
    }

    report();
    return 0;
}