position += length;
static void client_data_available(struct client *client) {    unsigned char buffer[4096];    ssize_t nbytes;    struct packet_header *header = (struct packet_header*)buffer;    size_t length;    /* read from stream */    nbytes = recv(client->sockfd, buffer, sizeof(buffer), 0);    if (verbose >= 4) {        printf("received from client %u\n", client->id);        dump_packet(stdout, buffer, (size_t)nbytes);        printf("\n");    }    if (nbytes <= 0) {        printf("client %u disconnected\n", client->id);        client->should_destroy = 1;        return;    }    while (nbytes > 0) {        if (nbytes < 16) {            fprintf(stderr, "packet from client %u is too small (%lu bytes)\n",                   client->id, (unsigned long)nbytes);            client->should_destroy = 1;            return;        }        /* check header */        if (header->five != 0x05 || header->zero1 != 0x00 ||            header->three != 0x03 || header->ten != 0x10) {            fprintf(stderr, "malformed packet, killing client %u\n",                    client->id);            client->should_destroy = 1;            return;        }        /* extract data */        length = read_uint32(buffer + 8);        if (length < 16 || length > (size_t)nbytes) {            fprintf(stderr, "malformed length %lu in packet, killing client %u\n",                    (unsigned long)length, client->id);            client->should_destroy = 1;            return;        }        /* handle packet */        handle_packet(client, buffer, length);        nbytes -= (ssize_t)length;    }}