void print(struct v4l2_pix_format pix) { fprintf(stderr, "width: %d\n", pix.width); fprintf(stderr, "height: %d\n", pix.height); printPixelFormat(pix.pixelformat); print(pix.field); fprintf(stderr, "bytesperline: %d\n", pix.bytesperline); fprintf(stderr, "sizeimage: %d\n", pix.sizeimage); print(pix.colorspace); fprintf(stderr, "priv: %d\n", pix.priv); }
bool VNCRFBproto::initialiseRFBConnection() { rfbProtocolVersionMsg pv; rfbClientInitMsg ci; int major, minor; char *reason, *passwd = NULL; CARD32 authScheme, reasonLen, authResult; CARD8 challenge[CHALLENGESIZE]; // was trace fprintf(stderr, "VNCRFBproto::initialiseRFBConnection(): initializing RFB connection\n"); if (!VNC_sock.ReadFromRFBServer(pv, sz_rfbProtocolVersionMsg)) return false; pv[sz_rfbProtocolVersionMsg] = 0; if (sscanf(pv, rfbProtocolVersionFormat, &major, &minor) != 2) { // was error fprintf(stderr, "VNCRFBproto::initialiseRFBConnection() err: not a valid VNC server\n"); return false; } // was trace fprintf(stderr, "VNCRFBproto::initialiseRFBConnection(): VNC server supports protocol version %d.%d (viewer %d.%d)\n", major, minor, rfbProtocolMajorVersion, rfbProtocolMinorVersion); major = rfbProtocolMajorVersion; minor = rfbProtocolMinorVersion; sprintf(pv, rfbProtocolVersionFormat, major, minor); if (!VNC_sock.WriteExact(pv, sz_rfbProtocolVersionMsg)) return false; if (!VNC_sock.ReadFromRFBServer((char *)&authScheme, 4)) return false; authScheme = (CARD32)swap32IfLE(authScheme); switch (authScheme) { case rfbConnFailed: if (!VNC_sock.ReadFromRFBServer((char *)&reasonLen, 4)) return false; reasonLen = swap32IfLE(reasonLen); reason = new char[reasonLen]; if (!VNC_sock.ReadFromRFBServer(reason, reasonLen)) return false; // error fprintf(stderr, "VNCRFBproto::initialiseRFBConnection() err: VNC connection failed: %.*s\n", (int)reasonLen, reason); delete[] reason; return false; case rfbNoAuth: // was trace fprintf(stderr, "VNCRFBproto::initialiseRFBConnection(): No authentication needed\n"); break; case rfbVncAuth: if (!VNC_sock.ReadFromRFBServer((char *)challenge, CHALLENGESIZE)) return false; #if 0 if (passwordFile) {//look for a password stored in passwordFile passwd = vncDecryptPasswdFromFile(passwordFile); if (!passwd) { // was error fprintf(stderr, "VNCRFBproto::initialiseRFBConnection() err: Cannot read valid password from file \"%s\"\n", passwordFile); return false; } } if (! passwd || (! strlen(passwd))) { // was error fprintf(stderr, "VNCRFBproto::initialiseRFBConnection() err: initialiseRFBConnection: reading password failed\n"); return false; } if (strlen(passwd) > 8) passwd[8] = '\0'; #endif //vncEncryptBytes(challenge, passwd); if (strlen(passwordFile) > 8) passwordFile[8] = '\0'; vncEncryptBytes(challenge, passwordFile); /* Lose the password from memory */ //for (int i = strlen(passwd); i >= 0; i--) // passwd[i] = '\0'; passwd = passwd; if (!VNC_sock.WriteExact((char *)challenge, CHALLENGESIZE)) return false; if (!VNC_sock.ReadFromRFBServer((char *)&authResult, 4)) return false; authResult = swap32IfLE(authResult); switch (authResult) { case rfbVncAuthOK: // was trace fprintf(stderr, "VNCRFBproto::initialiseRFBConnection(): VNC authentication succeeded\n"); break; case rfbVncAuthFailed: // was error fprintf(stderr, "VNCRFBproto::initialiseRFBConnection() err: VNC authentication failed\n"); return false; case rfbVncAuthTooMany: // was error fprintf(stderr, "VNCRFBproto::initialiseRFBConnection() err: VNC authentication failed - too many tries\n"); return false; default: // was error fprintf(stderr, "VNCRFBproto::initialiseRFBConnection() err: Unknown VNC authentication result: %d\n", (int)authResult); return false; } break; default: // was error fprintf(stderr, "VNCRFBproto::initialiseRFBConnection() err: Unknown authentication scheme from VNC server: %d\n", (int)authScheme); return false; } ci.shared = (ShareDesktop ? 1 : 0); if (!VNC_sock.WriteExact((char *)&ci, sz_rfbClientInitMsg)) return false; if (!VNC_sock.ReadFromRFBServer((char *)&si, sz_rfbServerInitMsg)) return false; si.framebufferWidth = swap16IfLE(si.framebufferWidth); si.framebufferHeight = swap16IfLE(si.framebufferHeight); si.format.redMax = swap16IfLE(si.format.redMax); si.format.greenMax = swap16IfLE(si.format.greenMax); si.format.blueMax = swap16IfLE(si.format.blueMax); si.nameLength = swap32IfLE(si.nameLength); desktopName = new char[si.nameLength + 1]; if (!VNC_sock.ReadFromRFBServer(desktopName, si.nameLength)) { delete[] desktopName; desktopName = NULL; return false; } desktopName[si.nameLength] = 0; // was notice fprintf(stderr, "VNCRFBproto::initialiseRFBConnection(): Using desktop: %s\n", desktopName); delete[] desktopName; desktopName = NULL; // was 2x trace fprintf(stderr, "VNCRFBproto::initialiseRFBConnection(): connected to VNC server, using protocol version %d.%d\n", rfbProtocolMajorVersion, rfbProtocolMinorVersion); fprintf(stderr, "VNCRFBproto::initialiseRFBConnection(): VNC server default format:\n"); printPixelFormat(&si.format); return true; }