static int protocol_version(VncState *vs, uint8_t *version, size_t len)

{

    char local[13];



    memcpy(local, version, 12);

    local[12] = 0;



    if (sscanf(local, "RFB %03d.%03d\n", &vs->major, &vs->minor) != 2) {

        VNC_DEBUG("Malformed protocol version %s\n", local);

        vnc_client_error(vs);

        return 0;

    }

    VNC_DEBUG("Client request protocol version %d.%d\n", vs->major, vs->minor);

    if (vs->major != 3 ||

        (vs->minor != 3 &&

         vs->minor != 4 &&

         vs->minor != 5 &&

         vs->minor != 7 &&

         vs->minor != 8)) {

        VNC_DEBUG("Unsupported client version\n");

        vnc_write_u32(vs, VNC_AUTH_INVALID);

        vnc_flush(vs);

        vnc_client_error(vs);

        return 0;

    }

    /* Some broken clients report v3.4 or v3.5, which spec requires to be treated

     * as equivalent to v3.3 by servers

     */

    if (vs->minor == 4 || vs->minor == 5)

        vs->minor = 3;



    if (vs->minor == 3) {

        if (vs->auth == VNC_AUTH_NONE) {

            VNC_DEBUG("Tell client auth none\n");

            vnc_write_u32(vs, vs->auth);

            vnc_flush(vs);

            start_client_init(vs);

       } else if (vs->auth == VNC_AUTH_VNC) {

            VNC_DEBUG("Tell client VNC auth\n");

            vnc_write_u32(vs, vs->auth);

            vnc_flush(vs);

            start_auth_vnc(vs);

       } else {

            VNC_DEBUG("Unsupported auth %d for protocol 3.3\n", vs->auth);

            vnc_write_u32(vs, VNC_AUTH_INVALID);

            vnc_flush(vs);

            vnc_client_error(vs);

       }

    } else {

        VNC_DEBUG("Telling client we support auth %d\n", vs->auth);

        vnc_write_u8(vs, 1); /* num auth */

        vnc_write_u8(vs, vs->auth);

        vnc_read_when(vs, protocol_client_auth, 1);

        vnc_flush(vs);

    }



    return 0;

}

static int protocol_version(VncState *vs, uint8_t *version, size_t len)

{

    char local[13];



    memcpy(local, version, 12);

    local[12] = 0;



    if (sscanf(local, "RFB %03d.%03d\n", &vs->major, &vs->minor) != 2) {

        VNC_DEBUG("Malformed protocol version %s\n", local);

        vnc_client_error(vs);

        return 0;

    }

    VNC_DEBUG("Client request protocol version %d.%d\n", vs->major, vs->minor);

    if (vs->major != 3 ||

        (vs->minor != 3 &&

         vs->minor != 4 &&

         vs->minor != 5 &&

         vs->minor != 7 &&

         vs->minor != 8)) {

        VNC_DEBUG("Unsupported client version\n");

        vnc_write_u32(vs, VNC_AUTH_INVALID);

        vnc_flush(vs);

        vnc_client_error(vs);

        return 0;

    }

    





    if (vs->minor == 4 || vs->minor == 5)

        vs->minor = 3;



    if (vs->minor == 3) {

        if (vs->auth == VNC_AUTH_NONE) {

            VNC_DEBUG("Tell client auth none\n");

            vnc_write_u32(vs, vs->auth);

            vnc_flush(vs);

            start_client_init(vs);

       } else if (vs->auth == VNC_AUTH_VNC) {

            VNC_DEBUG("Tell client VNC auth\n");

            vnc_write_u32(vs, vs->auth);

            vnc_flush(vs);

            start_auth_vnc(vs);

       } else {

            VNC_DEBUG("Unsupported auth %d for protocol 3.3\n", vs->auth);

            vnc_write_u32(vs, VNC_AUTH_INVALID);

            vnc_flush(vs);

            vnc_client_error(vs);

       }

    } else {

        VNC_DEBUG("Telling client we support auth %d\n", vs->auth);

        vnc_write_u8(vs, 1); 

        vnc_write_u8(vs, vs->auth);

        vnc_read_when(vs, protocol_client_auth, 1);

        vnc_flush(vs);

    }



    return 0;

}

            VNC_DEBUG("Tell client auth none\n");             VNC_DEBUG("Unsupported auth %d for protocol 3.3\n", vs->auth);         VNC_DEBUG("Telling client we support auth %d\n", vs->auth);
static int FUNC_0(VncState *VAR_0, uint8_t *VAR_1, size_t VAR_2)

{

    char VAR_3[13];



    memcpy(VAR_3, VAR_1, 12);

    VAR_3[12] = 0;



    if (sscanf(VAR_3, "RFB %03d.%03d\n", &VAR_0->major, &VAR_0->minor) != 2) {

        VNC_DEBUG("Malformed protocol VAR_1 %s\n", VAR_3);

        vnc_client_error(VAR_0);

        return 0;

    }

    VNC_DEBUG("Client request protocol VAR_1 %d.%d\n", VAR_0->major, VAR_0->minor);

    if (VAR_0->major != 3 ||

        (VAR_0->minor != 3 &&

         VAR_0->minor != 4 &&

         VAR_0->minor != 5 &&

         VAR_0->minor != 7 &&

         VAR_0->minor != 8)) {

        VNC_DEBUG("Unsupported client VAR_1\n");

        vnc_write_u32(VAR_0, VNC_AUTH_INVALID);

        vnc_flush(VAR_0);

        vnc_client_error(VAR_0);

        return 0;

    }

    





    if (VAR_0->minor == 4 || VAR_0->minor == 5)

        VAR_0->minor = 3;



    if (VAR_0->minor == 3) {

        if (VAR_0->auth == VNC_AUTH_NONE) {

            VNC_DEBUG("Tell client auth none\n");

            vnc_write_u32(VAR_0, VAR_0->auth);

            vnc_flush(VAR_0);

            start_client_init(VAR_0);

       } else if (VAR_0->auth == VNC_AUTH_VNC) {

            VNC_DEBUG("Tell client VNC auth\n");

            vnc_write_u32(VAR_0, VAR_0->auth);

            vnc_flush(VAR_0);

            start_auth_vnc(VAR_0);

       } else {

            VNC_DEBUG("Unsupported auth %d for protocol 3.3\n", VAR_0->auth);

            vnc_write_u32(VAR_0, VNC_AUTH_INVALID);

            vnc_flush(VAR_0);

            vnc_client_error(VAR_0);

       }

    } else {

        VNC_DEBUG("Telling client we support auth %d\n", VAR_0->auth);

        vnc_write_u8(VAR_0, 1); 

        vnc_write_u8(VAR_0, VAR_0->auth);

        vnc_read_when(VAR_0, protocol_client_auth, 1);

        vnc_flush(VAR_0);

    }



    return 0;

}

static int FUNC_0(VncState *VAR_0, uint8_t *VAR_1, size_t VAR_2)
{ char VAR_3[13]; memcpy(VAR_3, VAR_1, 12); VAR_3[12] = 0; if (sscanf(VAR_3, "RFB %03d.%03d\n", &VAR_0->major, &VAR_0->minor) != 2) { VNC_DEBUG("Malformed protocol VAR_1 %s\n", VAR_3); vnc_client_error(VAR_0); return 0; } VNC_DEBUG("Client request protocol VAR_1 %d.%d\n", VAR_0->major, VAR_0->minor); if (VAR_0->major != 3 ||
(VAR_0->minor != 3 &&
VAR_0->minor != 4 &&
VAR_0->minor != 5 &&
VAR_0->minor != 7 &&
VAR_0->minor != 8)) { VNC_DEBUG("Unsupported client VAR_1\n"); vnc_write_u32(VAR_0, VNC_AUTH_INVALID); vnc_flush(VAR_0); vnc_client_error(VAR_0); return 0; } if (VAR_0->minor == 4 || VAR_0->minor == 5)
VAR_0->minor = 3; if (VAR_0->minor == 3) { if (VAR_0->auth == VNC_AUTH_NONE) { VNC_DEBUG("Tell client auth none\n"); vnc_write_u32(VAR_0, VAR_0->auth); vnc_flush(VAR_0); start_client_init(VAR_0); } else if (VAR_0->auth == VNC_AUTH_VNC) { VNC_DEBUG("Tell client VNC auth\n"); vnc_write_u32(VAR_0, VAR_0->auth); vnc_flush(VAR_0); start_auth_vnc(VAR_0); } else { VNC_DEBUG("Unsupported auth %d for protocol 3.3\n", VAR_0->auth); vnc_write_u32(VAR_0, VNC_AUTH_INVALID); vnc_flush(VAR_0); vnc_client_error(VAR_0); } } else { VNC_DEBUG("Telling client we support auth %d\n", VAR_0->auth); vnc_write_u8(VAR_0, 1); vnc_write_u8(VAR_0, VAR_0->auth); vnc_read_when(VAR_0, protocol_client_auth, 1); vnc_flush(VAR_0); } return 0; }