#include #include #include #include #include #include #include #include #include // Server starten: nc -lp1337 // Dann Client (dieses Programm) starten int main() { int sock = socket(AF_INET6, SOCK_STREAM, 0); // Fehlerbehandlung struct sockaddr_in6 addr = { .sin6_family = AF_INET6, .sin6_port = htons(1337), .sin6_addr = in6addr_any, }; int flag = 1; setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &flag, sizeof(flag)); // Fehlerbehandlung (void)bind(sock, (struct sockaddr*)&addr, sizeof(addr)); listen(sock, SOMAXCONN); while (1) { int client = accept(sock, NULL, NULL); /* /\* printf("Client connected.\n"); *\/ */ /* /\* FILE *rx = fdopen(client, "r"); *\/ */ /* /\* // Fehlerbehandlung *\/ */ /* /\* int copy = dup(client); *\/ */ /* /\* // Fehlerbehandlung *\/ */ /* /\* FILE *tx = fdopen(copy, "w"); *\/ */ /* /\* // Fehlerbehandlung *\/ */ /* /\* int upper = 2; *\/ */ /* /\* int read; *\/ */ /* /\* while ((read = fgetc(rx)) != EOF) { *\/ */ /* /\* if (upper == 2) { *\/ */ /* /\* if (read == 'u') { *\/ */ /* /\* upper = 1; *\/ */ /* /\* } else if (read == 'l') { *\/ */ /* /\* upper = 0; *\/ */ /* /\* } else { *\/ */ /* /\* fprintf(stderr, "Invalid char from client"); *\/ */ /* /\* // FILE* schließen, weitermachen *\/ */ // nicht // exit(EXIT_FAILURE); } continue; } if (upper) { fputc(toupper(read), tx); } else { fputc(tolower(read), tx); // FB } fflush(tx); // Fehlerbehandlung aller IO-Funktion } // Ressourcen freigeben } }