}  if (nbytes <= 0) { printf("client %u disconnected\n", client->id); client->should_destroy = 1; return;
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 position = 0, 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) {            /* we need 16 bytes for a header */            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;        }        /* length check - check if the UOAM packet length is OK */        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 + position, length);        nbytes -= (ssize_t)length;        position += length;        /* try to read more data - the first read may have stopped at           the buffer boundary, i.e. the rest of a packet may come           with the next recv() call, so do it here to prevent an           error at the length check */        if (nbytes > 0) {            ssize_t ret;            memmove(buffer, buffer + position, (size_t)nbytes);            position = 0;            ret = select_more_data(client->sockfd, buffer + nbytes,                                   sizeof(buffer) - nbytes);            if (ret > 0)                nbytes += ret;        }    }}