### Initialize and Run VNC Server Source: https://libvnc.github.io/doc/html/example_8c_source.html Sets up the VNC screen, draws a string, initializes the server, and runs the event loop. This is a basic example for starting a VNC server. ```c int main(int argc, char **argv) { rfbScreenInfoPtr rfbScreen; /* get a screen, default is 640x480, 16 bpp */ rfbScreen=rfbGetScreen(&argc,argv,640,480,8,8,4); rfbScreen->desktopName = "LibVNCServer Example"; rfbScreen->frameBuffer = (char*)malloc(maxx*maxy*bpp); rfbScreen->alwaysShared = TRUE; rfbScreen->ptrAddEvent = doptr; rfbScreen->kbdAddEvent = dokey; rfbScreen->newClientHook = newclient; rfbScreen->httpDir = "../webclients"; rfbScreen->httpEnableProxyConnect = TRUE; initBuffer((unsigned char*)rfbScreen->frameBuffer); rfbDrawString(rfbScreen,&radonFont,20,100,"Hello, World!",0xffffff); /* This call creates a mask and then a cursor: */ /* rfbScreen->defaultCursor = rfbMakeXCursor(exampleCursorWidth,exampleCursorHeight,exampleCursor,0); */ MakeRichCursor(rfbScreen); /* initialize the server */ rfbInitServer(rfbScreen); #ifndef BACKGROUND_LOOP_TEST #ifdef USE_OWN_LOOP { int i; for(i=0;rfbIsActive(rfbScreen);i++) { fprintf(stderr,"%d\r",i); rfbProcessEvents(rfbScreen,100000); } } #else /* this is the blocking event loop, i.e. it never returns */ /* 40000 are the microseconds to wait on select(), i.e. 0.04 seconds */ rfbRunEventLoop(rfbScreen,40000,FALSE); #endif /* OWN LOOP */ #else #if !defined(LIBVNCSERVER_HAVE_LIBPTHREAD) && !defined(LIBVNCSERVER_HAVE_WIN32THREADS) #error "I need pthreads or win32 threads for that." #endif /* catch Ctrl-C to set a flag for the main thread */ signal(SIGINT, intHandler); /* this is the non-blocking event loop; a background thread is started */ rfbRunEventLoop(rfbScreen,-1,TRUE); fprintf(stderr, "Running background loop...\n"); /* now we could do some cool things like rendering in idle time */ while (maintain_connection) { sleep(5); /* render(); */ } fprintf(stderr, "\nShutting down...\n"); rfbShutdownServer(rfbScreen, TRUE); #endif /* BACKGROUND_LOOP */ free(rfbScreen->frameBuffer); rfbScreenCleanup(rfbScreen); return(0); } ``` -------------------------------- ### Initialize and Run VNC Server Source: https://libvnc.github.io/doc/html/example_8c-example.html Initializes the VNC server and runs the main event loop. This example shows the basic setup for starting a VNC server and includes different event loop implementations. ```c rfbScreen->kbdAddEvent = dokey; rfbScreen->newClientHook = newclient; rfbScreen->httpDir = "../webclients"; rfbScreen->httpEnableProxyConnect = TRUE; initBuffer((unsigned char*)rfbScreen->frameBuffer); rfbDrawString(rfbScreen,&radonFont,20,100,"Hello, World!",0xffffff); /* This call creates a mask and then a cursor: */ /* rfbScreen->defaultCursor = rfbMakeXCursor(exampleCursorWidth,exampleCursorHeight,exampleCursor,0); */ MakeRichCursor(rfbScreen); /* initialize the server */ rfbInitServer(rfbScreen); #ifndef BACKGROUND_LOOP_TEST #ifdef USE_OWN_LOOP { int i; for(i=0;rfbIsActive(rfbScreen);i++) { fprintf(stderr,"%d\r",i); rfbProcessEvents(rfbScreen,100000); } } #else /* this is the blocking event loop, i.e. it never returns */ /* 40000 are the microseconds to wait on select(), i.e. 0.04 seconds */ rfbRunEventLoop(rfbScreen,40000,FALSE); #endif /* OWN LOOP */ #else #if !defined(LIBVNCSERVER_HAVE_LIBPTHREAD) && !defined(LIBVNCSERVER_HAVE_WIN32THREADS) #error "I need pthreads or win32 threads for that." #endif /* catch Ctrl-C to set a flag for the main thread */ signal(SIGINT, intHandler); /* this is the non-blocking event loop; a background thread is started */ rfbRunEventLoop(rfbScreen,-1,TRUE); fprintf(stderr, "Running background loop...\n"); /* now we could do some cool things like rendering in idle time */ while (maintain_connection) { sleep(5); /* render(); */ } fprintf(stderr, "\nShutting down...\n"); rfbShutdownServer(rfbScreen, TRUE); #endif /* BACKGROUND_LOOP */ free(rfbScreen->frameBuffer); rfbScreenCleanup(rfbScreen); return(0); } ``` -------------------------------- ### Initialize and Run VNC Server with Camera Feed Source: https://libvnc.github.io/doc/html/camera_8c_source.html This is the main function that sets up the VNC server, initializes it, and enters a loop to process events and capture camera frames. It uses `rfbGetScreen` to initialize the server, `rfbInitServer` to start it, and then continuously checks `rfbIsActive` to keep the server running. Inside the loop, it calls `TimeToTakePicture` and `TakePicture` to get new frames, updates the modified rectangle with `rfbMarkRectAsModified`, and processes VNC events using `rfbProcessEvents`. ```c int main(int argc,char** argv) { long usec; rfbScreenInfoPtr server=rfbGetScreen(&argc,argv,WIDTH,HEIGHT,8,3,BPP); if(!server) return 1; server->desktopName = "Live Video Feed Example"; server->frameBuffer=(char*)malloc(WIDTH*HEIGHT*BPP); server->alwaysShared=(1==1); /* Initialize the server */ rfbInitServer(server); /* Loop, processing clients and taking pictures */ while (rfbIsActive(server)) { if (TimeToTakePicture()) if (TakePicture((unsigned char *)server->frameBuffer)) rfbMarkRectAsModified(server,0,0,WIDTH,HEIGHT); usec = server->deferUpdateTime*1000; rfbProcessEvents(server,usec); } return(0); } ``` -------------------------------- ### Initialize VNC Server and Register File Transfer Extension Source: https://libvnc.github.io/doc/html/filetransfer_8c_source.html This snippet demonstrates the main function for the filetransfer example. It registers the TightVNC file transfer extension, initializes a VNC server with specified dimensions and color depth, and then starts the VNC event loop. Ensure rfb.h is included for VNC functions. ```c #include int main(int argc,char** argv) { rfbRegisterTightVNCFileTransferExtension(); rfbScreenInfoPtr server=rfbGetScreen(&argc,argv,400,300,8,3,4); if(!server) return 1; server->frameBuffer=(char*)malloc(400*300*4); rfbInitServer(server); rfbRunEventLoop(server,-1,FALSE); return(0); } ``` -------------------------------- ### Initialize and Run VNC Server Source: https://libvnc.github.io/doc/html/vncev_8c_source.html This is the main function that initializes the VNC server. It gets screen information, sets up callbacks for keyboard and pointer events, and starts the server event loop. The server processes events indefinitely. ```c int main(int argc,char** argv) { rfbScreenInfoPtr s=rfbGetScreen(&argc,argv,width,height,8,1,1); if(!s) return 1; s->colourMap.is16=FALSE; s->colourMap.count=2; s->colourMap.data.bytes=(unsigned char*)"\xd0\xd0\xd0\x30\x01\xe0"; s->serverFormat.trueColour=FALSE; s->frameBuffer=f; s->kbdAddEvent=dokey; s->ptrAddEvent=doptr; s->newClientHook=newclient; memset(f,0,width*height); read_keys(); rfbInitServer(s); while(1) { rfbProcessEvents(s,999999); } } ``` -------------------------------- ### VNC Framebuffer Padding Example Source: https://libvnc.github.io/doc/html/pnmshow24_8c_source.html Example code demonstrating how to pad the VNC framebuffer to ensure correct alignment, likely for specific pixel formats or screen resolutions. ```c memset(rfbScreen->frameBuffer+3*paddedWidth*(j+1)-padCount, 0,padCount); ``` -------------------------------- ### rfbStartOnHoldClient Source: https://libvnc.github.io/doc/html/group__libvncserver__api.html Starts a VNC client that is currently on hold. ```APIDOC ## rfbStartOnHoldClient() ### Description Starts a VNC client that is currently on hold. ### Signature `void rfbStartOnHoldClient(rfbClientPtr _cl_)` ``` -------------------------------- ### Initialize VNC Server Source: https://libvnc.github.io/doc/html/libvncserver_doc.html Call rfbInitServer with the initialized screen structure to start the VNC server. This function prepares the server to accept connections. ```c rfbInitServer(screen); ``` -------------------------------- ### FFmpeg Initialization Source: https://libvnc.github.io/doc/html/vnc2mpg_8c-example.html Initializes the FFmpeg libraries by registering all codecs and formats. This is a standard setup step for media processing. ```c /* Initialize libavcodec, and register all codecs and formats. */ #if LIBAVUTIL_VERSION_MAJOR < 56 /* deprecrated in FFMPEG 4.0 */ av_register_all(); #endif ``` -------------------------------- ### Main Function for VNC Client Example Source: https://libvnc.github.io/doc/html/ppmtest_8c_source.html Initializes the VNC client, sets up authentication callbacks if SASL is available, and assigns a callback for handling framebuffer updates based on command-line arguments. It prepares the client to either log rectangle updates or save the framebuffer as a PPM image. ```c int main(int argc, char **argv) { rfbClient* client = rfbGetClient(8,3,4); time_t t=time(NULL); #ifdef LIBVNCSERVER_HAVE_SASL client->GetUser = getuser; client->GetPassword = getpassword; #endif if(argc>1 && !strcmp("-print",argv[1])) { client->GotFrameBufferUpdate = PrintRect; argv[1]=argv[0]; argv++; argc--; } else client->GotFrameBufferUpdate = SaveFramebufferAsPPM; /* The -listen option is used to make us a daemon process which listens for incoming connections from servers, rather than actively connecting to a given server. The -tunnel and -via options are useful to create connections tunneled via SSH port forwarding. We must test for the -listen option before invoking any Xt functions - this is because we use forking, and Xt doesn't seem to cope with forking very well. For -listen ``` -------------------------------- ### Include Example Code Source: https://libvnc.github.io/doc/html/blooptest_8c_source.html This directive includes the content of 'example.c' into the current file, likely for testing or integration purposes. ```c #include "example.c" ``` -------------------------------- ### Include Headers for VNC Example Source: https://libvnc.github.io/doc/html/example_8c.html Includes necessary headers for VNC client/server operations and custom Radon functionality. Ensure these are available in your project. ```c #include #include #include #include #include "radon.h" ``` -------------------------------- ### main() function Source: https://libvnc.github.io/doc/html/storepasswd_8c.html The main entry point for the storepasswd example program. It handles command-line arguments and initiates the password storage process. ```APIDOC ## main() ### Description This function serves as the entry point for the `storepasswd` example. It processes command-line arguments and is responsible for the core logic of storing a VNC password. ### Method int main(int argc, char *argv[]) ### Parameters - **argc** (int) - The number of command-line arguments. - **argv[]** (char *) - An array of strings representing the command-line arguments. ### Definition Defined in `storepasswd.c` at line 42. ### Example Usage This function is part of the `storepasswd.c` example file. ``` -------------------------------- ### Include Headers for pnmshow24.c Source: https://libvnc.github.io/doc/html/pnmshow24_8c.html Includes standard C libraries and the LibVNCServer library headers required for the pnmshow24.c example. ```c #include ``` ```c #include ``` ```c #include ``` -------------------------------- ### Main Function in filetransfer.c Source: https://libvnc.github.io/doc/html/filetransfer_8c.html The main entry point for the filetransfer example. It demonstrates the basic structure of a C program using the RFB library. ```c int main (int _argc_ , char ** _argv_ ) { } ``` -------------------------------- ### Main Function Signature in pnmshow.c Source: https://libvnc.github.io/doc/html/pnmshow_8c.html The main function signature for the pnmshow.c example. It accepts command-line arguments. ```c int main (int argc, char **argv) ``` -------------------------------- ### VNC Server Initialization Source: https://libvnc.github.io/doc/html/example_8c_source.html Initializes the VNC server by obtaining a screen structure with specified dimensions, color depth, and bits per pixel. This is a fundamental step before starting the VNC server. ```c int main(int argc,char** argv) { rfbScreenInfoPtr rfbScreen = rfbGetScreen(&argc,argv,maxx,maxy,8,3,bpp); if(!rfbScreen) ``` -------------------------------- ### ListenAtTcpPortAndAddress Source: https://libvnc.github.io/doc/html/globals_func_l.html Starts listening for incoming VNC connections on a specified TCP port and network address. ```APIDOC ## ListenAtTcpPortAndAddress ### Description Starts listening for incoming VNC connections on a specified TCP port and network address. ### Method [Not specified, likely a C function call] ### Endpoint [Not applicable, this is an SDK function] ### Parameters [Parameters not detailed in the source] ### Request Example [Not applicable] ### Response [Response details not detailed in the source] ### File rfbclient.h ``` -------------------------------- ### Main Function Definition in pnmshow24.c Source: https://libvnc.github.io/doc/html/pnmshow24_8c.html Defines the main function for the pnmshow24.c example. This is the entry point of the program. ```c int main () ``` -------------------------------- ### SDL Renderer Setup and Texture Creation Source: https://libvnc.github.io/doc/html/_s_d_lvncviewer_8c_source.html Initializes SDL logical size for aspect ratio and recreates the texture used for streaming pixel data to the renderer. Handles potential errors during texture creation. ```c SDL_RenderSetLogicalSize(sdlRenderer, width, height); /* this is a departure from the SDL1.2-based version, but more in the sense of a VNC viewer in keeeping aspect ratio */ /* (re)create the texture that sits in between the surface->pixels and the renderer */ if(sdlTexture) SDL_DestroyTexture(sdlTexture); sdlTexture = SDL_CreateTexture(sdlRenderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, width, height); if(!sdlTexture) rfbClientErr("resize: error creating texture: %s\n", SDL_GetError()); return TRUE; } ``` -------------------------------- ### storepasswd C Example Source: https://libvnc.github.io/doc/html/storepasswd_8c-example.html This C code implements the storepasswd program. It takes a password and a filename as arguments, encrypts the password using rfbEncryptAndStorePasswd, and stores it in the specified file. The resulting file can be used with the -rfbauth argument for OSXvnc. Ensure correct arguments are provided; otherwise, a usage message is displayed. ```c #include #include static void usage(void) { printf("\nusage: storepasswd \n\n"); printf("Stores a password in encrypted format.\n"); printf("The resulting file can be used with the -rfbauth argument to OSXvnc.\n\n"); exit(1); } int main(int argc, char *argv[]) { if (argc != 3) usage(); if (rfbEncryptAndStorePasswd(argv[1], argv[2]) != 0) { printf("storing password failed.\n"); return 1; } else { printf("storing password succeeded.\n"); return 0; } } ``` -------------------------------- ### Main Function - VNC to MPG Conversion Source: https://libvnc.github.io/doc/html/vnc2mpg_8c_source.html Initializes the VNC client, parses command-line arguments for output file and time limits, and starts the main loop to capture and encode VNC frames. Registers FFmpeg codecs and formats. ```c int main(int argc, char **argv) { int i,j; /* Initialize vnc client structure (don't connect yet). */ client = rfbGetClient(5,3,2); client->format.redShift=11; client->format.redMax=31; client->format.greenShift=5; client->format.greenMax=63; client->format.blueShift=0; client->format.blueMax=31; /* Initialize libavcodec, and register all codecs and formats. */ #if LIBAVUTIL_VERSION_MAJOR < 56 /* deprecrated in FFMPEG 4.0 */ av_register_all(); #endif /* Parse command line. */ for(i=1;ii+1 && !strcmp("-o",argv[i])) { filename=argv[i+1]; j+=2; } else if(argc>i+1 && !strcmp("-t",argv[i])) { max_time=atol(argv[i+1]); if (max_time < 10 || max_time > 100000000) { fprintf(stderr, "Warning: Nonsensical time-per-file %li, resetting to default.\n", max_time); max_time = 0; } j+=2; } /* This is so that argc/argv are ready for passing to rfbInitClient */ if(j>i) { argc-=j-i; memmove(argv+i,argv+j,(argc-i)*sizeof(char*)); i--; } } /* default filename. */ if (!filename) { fprintf(stderr, "Warning: No filename specified. Using output.mp4\n"); filename = "output.mp4"; } /* open VNC connection. */ client->MallocFrameBuffer=vnc_malloc_fb; client->GotFrameBufferUpdate=vnc_update; if(!rfbInitClient(client,&argc,argv)) { printf("usage: %s [-o output_file] [-t seconds-per-file] server:port\n", argv[0]); return 1; } /* main loop */ clock_gettime(CLOCK_MONOTONIC, &start_time); while(!quit) { int i=WaitForMessage(client,10000/framerate); /* useful for timeout to be no more than 10 msec per second (=10000/framerate usec) */ if (i>0) { if(!HandleRFBServerMessage(client)) quit=TRUE; } else if (i<0) { quit=TRUE; } if (!quit) { clock_gettime(CLOCK_MONOTONIC, &cur_time); write_video_frame(oc, &video_st, time_to_pts(framerate, &start_time, &cur_time)); if ((cur_time.tv_sec - start_time.tv_sec) > max_time && max_time > 0) { quit = TRUE; } } } movie_close(&oc,&video_st); return 0; } ``` -------------------------------- ### Creating a Custom X Cursor Source: https://libvnc.github.io/doc/html/libvncserver_doc.html This example demonstrates how to create a custom cursor using character strings for the cursor shape and mask. The rfbMakeXCursor function generates a cursor pointer. ```c char* cur=" " " xx " " x " " "; char* mask="xxxx" "xxxx" "xxxx" "xxx "; rfbCursorPtr c=rfbMakeXCursor(4,4,cur,mask); ``` -------------------------------- ### Get VNC Screen Information Source: https://libvnc.github.io/doc/html/pnmshow24_8c_source.html Retrieves VNC screen information, including dimensions and pixel format. This function is typically used during server setup. ```c rfbScreenInfoPtr rfbGetScreen(int *argc, char **argv, int width, int height, int bitsPerSample, int samplesPerPixel, int bytesPerPixel) ``` -------------------------------- ### Creating a Server Instance Source: https://libvnc.github.io/doc/html/libvncserver_doc.html This section details how to initialize a VNC server structure using `rfbGetScreen()` and `rfbInitServer()`. ```APIDOC ## Creating a server instance To make a server, you just have to initialise a server structure using the function rfbGetScreen(), like ```c rfbScreenInfoPtr screen = rfbGetScreen(argc,argv,screenwidth,screenheight,8,3,bpp); ``` where byte per pixel should be 1, 2 or 4. If performance doesn't matter, you may try bpp=3 (internally one cannot use native data types in this case; if you want to use this, look at pnmshow24.c). You then can set hooks and io functions (see Making it interactive) or other options (see Optional Server Features). And you allocate the frame buffer like this: ```c screen->frameBuffer = (char*)malloc(screenwidth*screenheight*bpp); ``` After that, you initialize the server, like ```c rfbInitServer(screen); ``` You can use a blocking event loop, a background (pthread based) event loop, or implement your own using the rfbProcessEvents() function. ## Optional Server Features These options have to be set between `rfbGetScreen()` and `rfbInitServer()`. If you already have a socket to talk to, just set `rfbScreenInfo::inetdSock` (originally this is for inetd handling, but why not use it for your purpose?). To also start an HTTP server (running on port 5800+display_number), you have to set `rfbScreenInfo::httpDir` to a directory containing vncviewer.jar and index.vnc (like the included "webclients" directory). ``` -------------------------------- ### Font Selection Example Source: https://libvnc.github.io/doc/html/fontsel_8c-example.html This C code demonstrates how to load and display console fonts using LibVNCServer. It initializes a VNC screen, loads a default font, and then presents a selectable list of fonts to the user. The `rfbSelectBox` function is used to create an interactive font selection UI. ```c #include #define FONTDIR "/usr/lib/kbd/consolefonts/" #define DEFAULTFONT FONTDIR "default8x16" static char *fontlist[50]={ "8x16alt", "b.fnt", "c.fnt", "default8x16", "m.fnt", "ml.fnt", "mod_d.fnt", "mod_s.fnt", "mr.fnt", "mu.fnt", "r.fnt", "rl.fnt", "ro.fnt", "s.fnt", "sc.fnt", "scrawl_s.fnt", "scrawl_w.fnt", "sd.fnt", "t.fnt", NULL }; static rfbScreenInfoPtr rfbScreen = NULL; static rfbFontDataPtr curFont = NULL; static void showFont(int index) { char buffer[1024]; if(!rfbScreen) return; if(curFont) rfbFreeFont(curFont); strcpy(buffer,FONTDIR); strcat(buffer,fontlist[index]); curFont = rfbLoadConsoleFont(buffer); rfbFillRect(rfbScreen,210,30-20,210+10*16,30-20+256*20/16,0xb77797); if(curFont) { int i,j; for(j=0;j<256;j+=16) for(i=0;i<16;i++) rfbDrawCharWithClip(rfbScreen,curFont,210+10*i,30+j*20/16,j+i, 0,0,640,480,0xffffff,0x000000); } } int main(int argc,char** argv) { rfbFontDataPtr font; rfbScreenInfoPtr s=rfbGetScreen(&argc,argv,640,480,8,3,3); int i,j; if(!s) return 1; s->frameBuffer=(char*)malloc(640*480*3); if(!s->frameBuffer) return 1; rfbInitServer(s); for(j=0;j<480;j++) for(i=0;i<640;i++) { s->frameBuffer[(j*640+i)*3+0]=j*256/480; s->frameBuffer[(j*640+i)*3+1]=i*256/640; s->frameBuffer[(j*640+i)*3+2]=(i+j)*256/(480+640); } rfbScreen = s; font=rfbLoadConsoleFont(DEFAULTFONT); if(!font) { rfbErr("Couldn't find %s\n",DEFAULTFONT); exit(1); } for(j=0;j<10 && rfbIsActive(s);j++) rfbProcessEvents(s,900000); i = rfbSelectBox(s,font,fontlist,10,20,200,300,0xffdfdf,0x602040,2,showFont); rfbLog("Selection: %d: %s\n",i,(i>=0)?fontlist[i]:"cancelled"); rfbFreeFont(font); free(s->frameBuffer); rfbScreenCleanup(s); return(0); } ``` -------------------------------- ### Main Application Entry Point Source: https://libvnc.github.io/doc/html/_s_d_lvncviewer_8c_source.html Initializes SDL, sets up signal handling, parses command-line arguments, and enters the main client loop. It configures the RFB client with various callbacks for frame buffer updates, keyboard LEDs, text chat, and clipboard handling. ```c #ifdef mac #define main SDLmain #endif int main(int argc,char** argv) { rfbClient* cl; int i, j; SDL_Event e; #ifdef LOG_TO_FILE rfbClientLog=rfbClientErr=log_to_file; #endif for (i = 1, j = 1; i < argc; i++) if (!strcmp(argv[i], "-viewonly")) viewOnly = 1; else if (!strcmp(argv[i], "-resizable")) enableResizable = 1; else if (!strcmp(argv[i], "-no-resizable")) enableResizable = 0; else if (!strcmp(argv[i], "-listen")) { listenLoop = 1; argv[i] = "-listennofork"; ++j; } else { if (i != j) argv[j] = argv[i]; j++; } argc = j; SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE); atexit(SDL_Quit); signal(SIGINT, exit); do { /* 16-bit: cl=rfbGetClient(5,3,2); */ cl=rfbGetClient(8,3,4); cl->MallocFrameBuffer=resize; cl->canHandleNewFBSize = TRUE; cl->GotFrameBufferUpdate=update; cl->HandleKeyboardLedState=kbd_leds; cl->HandleTextChat=text_chat; /* two different cut text handlers here for demo purposes, you might as well use the same callback for both if it doesn't matter for your application */ cl->GotXCutText = got_selection_latin1; cl->GotXCutTextUTF8 = got_selection_utf8; cl->GetCredential = get_credential; cl->listenPort = LISTEN_PORT_OFFSET; cl->listen6Port = LISTEN_PORT_OFFSET; if(!rfbInitClient(cl,&argc,argv)) { cl = NULL; /* rfbInitClient has already freed the client struct */ cleanup(cl); break; } while(1) { if(SDL_PollEvent(&e)) { /* handleSDLEvent() return 0 if user requested window close. In this case, handleSDLEvent() will have called cleanup(). */ if(!handleSDLEvent(cl, &e)) break; } else { i=WaitForMessage(cl,500); if(i<0) { cleanup(cl); break; } if(i) if(!HandleRFBServerMessage(cl)) { cleanup(cl); break; } } } } while(listenLoop); return 0; } ``` -------------------------------- ### Main Server Initialization Source: https://libvnc.github.io/doc/html/example_8c-example.html Initializes the LibVNCServer, sets up the screen properties, allocates the framebuffer, and assigns event handlers for pointer and keyboard input. ```c int main(int argc,char** argv) { rfbScreenInfoPtr rfbScreen = rfbGetScreen(&argc,argv,maxx,maxy,8,3,bpp); if(!rfbScreen) return 1; rfbScreen->desktopName = "LibVNCServer Example"; rfbScreen->frameBuffer = (char*)malloc(maxx*maxy*bpp); rfbScreen->alwaysShared = TRUE; rfbScreen->ptrAddEvent = doptr; ``` -------------------------------- ### Variables starting with 'h' Source: https://libvnc.github.io/doc/html/functions_vars_h.html This section details variables that start with the letter 'h'. ```APIDOC ## Variables ### h - **h** : rfbClient, rfbCoRRERectangle, rfbFramebufferUpdateRequestMsg, rfbRectangle - **handleAuthentication** : rfbClientProtocolExtension - **HandleCursorPos** : rfbClient - **handleEncoding** : rfbClientProtocolExtension - **handleEventsEagerly** : rfbScreenInfoPtr - **HandleKeyboardLedState** : rfbClient - **handleMessage** : rfbClientProtocolExtension, rfbProtocolExtension - **handler** : rfbSecurityHandler - **HandleTextChat** : rfbClient - **HandleXvpMsg** : rfbClient - **height** : rfbClient, rfbCursorPtr, rfbExtDesktopScreen, rfbScreenInfoPtr, rfbSetDesktopSizeMsg - **host** : rfbClientPtr - **http6Port** : rfbScreenInfoPtr - **httpDir** : rfbScreenInfoPtr - **httpEnableProxyConnect** : rfbScreenInfoPtr - **httpInitDone** : rfbScreenInfoPtr - **httpListen6Sock** : rfbScreenInfoPtr - **httpListenSock** : rfbScreenInfoPtr - **httpPort** : rfbScreenInfoPtr - **httpSock** : rfbScreenInfoPtr ``` -------------------------------- ### Main VNC Viewer Loop Source: https://libvnc.github.io/doc/html/_s_d_lvncviewer_8c-example.html Initializes the SDL library, sets up signal handling, and enters the main loop for connecting to and interacting with a VNC server. Handles command-line arguments for viewer options. ```c #ifdef mac #define main SDLmain #endif int main(int argc,char** argv) { rfbClient* cl; int i, j; SDL_Event e; #ifdef LOG_TO_FILE rfbClientLog=rfbClientErr=log_to_file; #endif for (i = 1, j = 1; i < argc; i++) if (!strcmp(argv[i], "-viewonly")) viewOnly = 1; else if (!strcmp(argv[i], "-resizable")) enableResizable = 1; else if (!strcmp(argv[i], "-no-resizable")) enableResizable = 0; else if (!strcmp(argv[i], "-listen")) { listenLoop = 1; argv[i] = "-listennofork"; ++j; } else { if (i != j) argv[j] = argv[i]; j++; } argc = j; SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE); atexit(SDL_Quit); signal(SIGINT, exit); do { /* 16-bit: cl=rfbGetClient(5,3,2); */ cl=rfbGetClient(8,3,4); cl->MallocFrameBuffer=resize; cl->canHandleNewFBSize = TRUE; cl->GotFrameBufferUpdate=update; cl->HandleKeyboardLedState=kbd_leds; cl->HandleTextChat=text_chat; /* two different cut text handlers here for demo purposes, you might as well use the same callback for both if it doesn't matter for your application */ cl->GotXCutText = got_selection_latin1; cl->GotXCutTextUTF8 = got_selection_utf8; cl->GetCredential = get_credential; cl->listenPort = LISTEN_PORT_OFFSET; cl->listen6Port = LISTEN_PORT_OFFSET; if(!rfbInitClient(cl,&argc,argv)) { cl = NULL; /* rfbInitClient has already freed the client struct */ cleanup(cl); break; } while(1) { if(SDL_PollEvent(&e)) { /* handleSDLEvent() return 0 if user requested window close. In this case, handleSDLEvent() will have called cleanup(). */ if(!handleSDLEvent(cl, &e)) break; } else { i=WaitForMessage(cl,500); if(i<0) { cleanup(cl); break; } if(i) if(!HandleRFBServerMessage(cl)) { cleanup(cl); break; } } } } while(listenLoop); return 0; } ``` -------------------------------- ### Global Functions Starting with 't' Source: https://libvnc.github.io/doc/html/globals_func_t.html This section lists global functions that start with the letter 't'. ```APIDOC ## Global Functions ### TakePicture() * **File:** camera.c * **Description:** Captures a picture. ### TextChatClose() * **File:** rfbclient.h * **Description:** Closes the text chat session. ### TextChatFinish() * **File:** rfbclient.h * **Description:** Finishes the text chat session. ### TextChatOpen() * **File:** rfbclient.h * **Description:** Opens a text chat session. ### TextChatSend() * **File:** rfbclient.h * **Description:** Sends a message through the text chat session. ### time_to_pts() * **File:** vnc2mpg.c * **Description:** Converts time to presentation timestamp (PTS). ### TimeToTakePicture() * **File:** camera.c * **Description:** Determines the time to capture a picture. ``` -------------------------------- ### Initialize and Configure VNC Server for 24bpp Images Source: https://libvnc.github.io/doc/html/pnmshow24_8c-example.html This section initializes the LibVNCServer, sets up the screen dimensions, pixel format (8 bits, 3 bytes/pixel), and configures event handlers and HTTP directory. It also allocates memory for the framebuffer. ```c int main(int argc,char** argv) { FILE* in=stdin; int j,width,height,paddedWidth; char buffer[1024]; rfbScreenInfoPtr rfbScreen; if(argc>1) { in=fopen(argv[1],"rb"); if(!in) { printf("Couldn't find file %s.\n",argv[1]); exit(1); } } fgets(buffer,1024,in); if(strncmp(buffer,"P6",2)) { printf("Not a ppm.\n"); exit(2); } /* skip comments */ do { fgets(buffer,1024,in); } while(buffer[0]=='#'); /* get width & height */ if(sscanf(buffer,"%d %d",&width,&height) != 2) { printf("Failed to get width or height.\n"); exit(3); } rfbLog("Got width %d and height %d.\n",width,height); fgets(buffer,1024,in); /* vncviewers have problems with widths which are no multiple of 4. */ paddedWidth = width; /* if your vncviewer doesn't have problems with a width which is not a multiple of 4, you can comment this. */ if(width&3) paddedWidth+=4-(width&3); /* initialize data for vnc server */ rfbScreen = rfbGetScreen(&argc,argv,paddedWidth,height,8,3,3); if(!rfbScreen) return 1; if(argc>1) rfbScreen->desktopName = argv[1]; else rfbScreen->desktopName = "Picture"; rfbScreen->alwaysShared = TRUE; rfbScreen->kbdAddEvent = HandleKey; /* enable http */ rfbScreen->httpDir = "../webclients"; /* allocate picture and read it */ if (paddedWidth>SIZE_MAX/3 || (height!=0 && paddedWidth*3>SIZE_MAX/height)) return 1; rfbScreen->frameBuffer = (char*)malloc(paddedWidth*3*height); if(!rfbScreen->frameBuffer) return 1; fread(rfbScreen->frameBuffer,width*3,height,in); fclose(in); /* pad to paddedWidth */ if(width != paddedWidth) { int padCount = 3*(paddedWidth - width); for(j=height-1;j>=0;j--) { ``` -------------------------------- ### Global Functions Starting with 'a' Source: https://libvnc.github.io/doc/html/globals_a.html This section lists global functions in LibVNCServer/LibVNCClient whose names start with the letter 'a'. ```APIDOC ## AcceptTcpConnection() ### Description Accepts a new TCP connection for the VNC server. ### Method (Not specified, likely a C function call) ### Endpoint (Not applicable) ### Parameters (Not specified) ### Request Example (Not applicable) ### Response (Not specified) ### Source File rfbclient.h ``` ```APIDOC ## add_video_stream() ### Description Adds a video stream to the VNC client for encoding. ### Method (Not specified, likely a C function call) ### Endpoint (Not applicable) ### Parameters (Not specified) ### Request Example (Not applicable) ### Response (Not specified) ### Source File vnc2mpg.c ``` ```APIDOC ## alloc_picture() ### Description Allocates memory for a picture structure used in video encoding. ### Method (Not specified, likely a C function call) ### Endpoint (Not applicable) ### Parameters (Not specified) ### Request Example (Not applicable) ### Response (Not specified) ### Source File vnc2mpg.c ``` -------------------------------- ### rfbInitServer Source: https://libvnc.github.io/doc/html/group__libvncserver__api.html Initializes the VNC server with the provided screen information. ```APIDOC ## rfbInitServer() ### Description Initializes the VNC server with the provided screen information, preparing it for connections. ### Signature `void rfbInitServer(rfbScreenInfoPtr _rfbScreen_)` ### Examples `camera.c, example.c, filetransfer.c, fontsel.c, pnmshow.c, pnmshow24.c, and vncev.c.` ``` -------------------------------- ### rfbInitServer Source: https://libvnc.github.io/doc/html/rfb_8h.html Initializes the VNC server. This function sets up the server environment and prepares it for client connections. ```APIDOC ## rfbInitServer ### Description Initializes the VNC server. ### Method (Not specified, likely a function call) ### Endpoint (Not applicable, C function) ### Parameters (Not specified in the source) ### Request Example (Not applicable, C function) ### Response (Not specified in the source) ``` -------------------------------- ### Global Functions Starting with 'c' Source: https://libvnc.github.io/doc/html/globals_func_c.html This section lists global functions in LibVNCServer/LibVNCClient whose names start with the letter 'c'. ```APIDOC ## Global Functions ### close_video_stream() * Defined in: vnc2mpg.c ### ConnectClientToTcpAddr() * Defined in: rfbclient.h ### ConnectClientToTcpAddr6() * Defined in: rfbclient.h ### ConnectClientToTcpAddr6WithTimeout() * Defined in: rfbclient.h ### ConnectClientToTcpAddrWithTimeout() * Defined in: rfbclient.h ### ConnectClientToUnixSock() * Defined in: rfbclient.h ### ConnectClientToUnixSockWithTimeout() * Defined in: rfbclient.h ### ConnectToRFBRepeater() * Defined in: rfbclient.h ### ConnectToRFBServer() * Defined in: rfbclient.h ``` -------------------------------- ### Variables starting with 'g' Source: https://libvnc.github.io/doc/html/functions_vars_g.html This section details variables related to LibVNCServer/LibVNCClient functions and structures, specifically those starting with the letter 'g'. ```APIDOC ## Variables ### - g - * **GetCredential** : rfbClient * Description: Retrieves credentials for the client. * **getCursorPtr** : rfbScreenInfoPtr * Description: Gets the cursor pointer information. * **getExtDesktopScreenHook** : rfbScreenInfoPtr * Description: Retrieves the extended desktop screen hook. * **getFileTransferPermission** : rfbScreenInfoPtr * Description: Checks file transfer permissions. * **getKeyboardLedStateHook** : rfbScreenInfoPtr * Description: Gets the keyboard LED state hook. * **GetPassword** : rfbClient * Description: Retrieves the password for the client. * **GotBitmap** : rfbClient * Description: Indicates if a bitmap has been received. * **GotCopyRect** : rfbClient * Description: Indicates if a copy rectangle operation has been received. * **GotCursorShape** : rfbClient * Description: Indicates if a cursor shape has been received. * **GotFillRect** : rfbClient * Description: Indicates if a fill rectangle operation has been received. * **GotFrameBufferUpdate** : rfbClient * Description: Indicates if a framebuffer update has been received. * **GotJpeg** : rfbClient * Description: Indicates if JPEG data has been received. * **GotXCutText** : rfbClient * Description: Indicates if X cut text has been received. * **GotXCutTextUTF8** : rfbClient * Description: Indicates if UTF8 X cut text has been received. * **greenMax** : rfbPixelFormat * Description: Maximum value for the green color component. * **greenShift** : rfbPixelFormat * Description: Bit shift for the green color component. ``` -------------------------------- ### Global Functions Starting with 'g' Source: https://libvnc.github.io/doc/html/globals_g.html This section lists global functions in LibVNCServer/LibVNCClient whose names start with the letter 'g'. It includes their associated header files or source files. ```APIDOC ## GetCredentialProc ### Description Callback function type for retrieving credentials. ### File rfbclient.h ## getpassword() ### Description Retrieves a password from the user. ### File ppmtest.c ## GetPasswordProc ### Description Callback function type for retrieving a password. ### File rfbclient.h ## getuser() ### Description Retrieves the current user's name. ### File ppmtest.c ## GotBitmapProc ### Description Callback function type for handling received bitmaps. ### File rfbclient.h ## GotCopyRectProc ### Description Callback function type for handling received copy rectangle operations. ### File rfbclient.h ## GotCursorShapeProc ### Description Callback function type for handling received cursor shape updates. ### File rfbclient.h ## GotFillRectProc ### Description Callback function type for handling received fill rectangle operations. ### File rfbclient.h ## GotFrameBufferUpdateProc ### Description Callback function type for handling frame buffer updates. ### File rfbclient.h ## GotJpegProc ### Description Callback function type for handling JPEG encoded data. ### File rfbclient.h ## GotXCutTextProc ### Description Callback function type for handling X cut text. ### File rfbclient.h ## GotXCutTextUTF8Proc ### Description Callback function type for handling X cut text in UTF-8 encoding. ### File rfbclient.h ``` -------------------------------- ### PPM Image to VNC Server Initialization Source: https://libvnc.github.io/doc/html/pnmshow24_8c_source.html Reads a PPM image from stdin or a file, initializes the VNC server, and sets up the screen buffer. It handles image dimensions, padding for VNC compatibility, and basic server configuration. ```c int main(int argc,char** argv) { FILE* in=stdin; int j,width,height,paddedWidth; char buffer[1024]; rfbScreenInfoPtr rfbScreen; if(argc>1) { in=fopen(argv[1],"rb"); if(!in) { printf("Couldn't find file %s.\n",argv[1]); exit(1); } } fgets(buffer,1024,in); if(strncmp(buffer,"P6",2)) { printf("Not a ppm.\n"); exit(2); } /* skip comments */ do { fgets(buffer,1024,in); } while(buffer[0]=='#'); /* get width & height */ if(sscanf(buffer,"%d %d",&width,&height) != 2) { printf("Failed to get width or height.\n"); exit(3); } rfbLog("Got width %d and height %d.\n",width,height); fgets(buffer,1024,in); /* vncviewers have problems with widths which are not a multiple of 4. */ paddedWidth = width; /* if your vncviewer doesn't have problems with a width which is not a multiple of 4, you can comment this. */ if(width&3) paddedWidth+=4-(width&3); /* initialize data for vnc server */ rfbScreen = rfbGetScreen(&argc,argv,paddedWidth,height,8,3,3); if(!rfbScreen) return 1; if(argc>1) rfbScreen->desktopName = argv[1]; else rfbScreen->desktopName = "Picture"; rfbScreen->alwaysShared = TRUE; rfbScreen->kbdAddEvent = HandleKey; /* enable http */ rfbScreen->httpDir = "../webclients"; /* allocate picture and read it */ if (paddedWidth>SIZE_MAX/3 || (height!=0 && paddedWidth*3>SIZE_MAX/height)) return 1; rfbScreen->frameBuffer = (char*)malloc(paddedWidth*3*height); if(!rfbScreen->frameBuffer) return 1; fread(rfbScreen->frameBuffer,width*3,height,in); fclose(in); /* pad to paddedWidth */ if(width != paddedWidth) { int padCount = 3*(paddedWidth - width); for(j=height-1;j>=0;j--) { memmove(rfbScreen->frameBuffer+3*paddedWidth*j, rfbScreen->frameBuffer+3*width*j, 3*width); ``` -------------------------------- ### Global Symbols Starting with 'l' Source: https://libvnc.github.io/doc/html/globals_l.html This section lists global symbols (functions, variables, defines, etc.) that start with the letter 'l'. Each entry includes the symbol name and the header file where it is defined. ```APIDOC ## Global Symbols Starting with 'l' ### Description Lists global symbols starting with 'l'. ### Symbols - **LISTEN_PORT_OFFSET** : rfbclient.h - **ListenAtTcpPort()** : rfbclient.h - **ListenAtTcpPortAndAddress()** : rfbclient.h - **listenForIncomingConnections()** : rfbclient.h - **listenForIncomingConnectionsNoFork()** : rfbclient.h - **LOCK** : threading.h - **LockWriteToTLSProc** : rfbclient.h ``` -------------------------------- ### rfbInitServer Function Source: https://libvnc.github.io/doc/html/libvncserver_doc.html Initializes the VNC server. ```APIDOC ## rfbInitServer ```c void rfbInitServer(rfbScreenInfoPtr rfbScreen) ``` You can use a blocking event loop, a background (pthread based) event loop, or implement your own using the rfbProcessEvents() function. ```