commit 2b9a557346004b780dee04f276d79626380a19be Author: xfnw Date: Wed Aug 18 21:32:56 2021 -0400 init diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a4879f3 --- /dev/null +++ b/Makefile @@ -0,0 +1,9 @@ +CC=c99 + +all: fbflut + +fbflut: fbflut.o + ${CC} -lpthread -o fbflut fbflut.o + +clean: + rm -f fbflut.o fbflut diff --git a/README.md b/README.md new file mode 100644 index 0000000..50d7e7e --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ +# fbflut + +framebuffer pixelflut server in C. + +## running + +- compile with `make` +- make sure you have read/write access + to the framebuffer (ie put yourself in the `video` group) +- go in something that wont fight you for the framebuffer, + ie a tty +- do `./fbflut` diff --git a/fbflut.c b/fbflut.c new file mode 100644 index 0000000..ec02e0c --- /dev/null +++ b/fbflut.c @@ -0,0 +1,80 @@ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int fbfd, fb_width, fb_height, fb_bytes; +uint32_t *fbdata; + +void *handle_connection(void *socket_desc) { + int sock = *(int*)socket_desc; + int read_size; + char *message, client_message[25]; + + message = "doug doug doug"; + write(sock, message, strlen(message)); + + return 0; +} + +int main(int argc, char *argv[]) { + int port; + + port = argc > 1 ? atoi(argv[1]) : 0; + if (!port) + port = 1234; + + fbfd = open("/dev/fb0", O_RDWR); + if (fbfd >= 0) { + struct fb_var_screeninfo vinfo; + + ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo); + + fb_width = vinfo.xres; + fb_height = vinfo.yres; + fb_bytes = vinfo.bits_per_pixel / 8; + + printf("width: %i, height: %i, bpp: %i\n", fb_width, fb_height, fb_bytes); + + int fb_data_size = fb_width * fb_height * fb_bytes; + + fbdata = mmap(0, fb_data_size, PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, (off_t)0); + + memset(fbdata, 0, fb_data_size); // clear the screen + + + int socket_desc, client_sock, c; + struct sockaddr_in server, client; + + socket_desc = socket(AF_INET, SOCK_STREAM, 0); + + server.sin_family = AF_INET; + server.sin_addr.s_addr = INADDR_ANY; + server.sin_port = htons(port); + + if (bind(socket_desc, (struct sockaddr *)&server, sizeof(server)) < 0) + return 15; + + listen(socket_desc, 100); + c = sizeof(struct sockaddr_in); + pthread_t thread_id; + + while (client_sock = accept(socket_desc, (struct sockaddr *)&client, (socklen_t*)&c)) { + + pthread_create(&thread_id, NULL, handle_connection, (void*) &client_sock); + + } + + return 0; + } + +} +