static void server_run(void) { struct sockaddr_in client_addr; socklen_t addr_size = sizeof(client_addr); pthread_attr_init(&attr); /* * detaching threads allow to reclaim thread's resources * once a thread finishes its work. */ if (pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED) != 0) tst_brkm(TBROK | TERRNO, cleanup, "setdetachstate failed"); while (1) { int client_fd = accept(sfd, (struct sockaddr *) &client_addr, &addr_size); if (client_fd == -1) tst_brkm(TBROK, cleanup, "Can't create client socket"); if (client_addr.sin_family == AF_INET) { if (verbose) { tst_resm(TINFO, "conn: port '%d', addr '%s'", client_addr.sin_port, inet_ntoa(client_addr.sin_addr)); } } server_thread_add(client_fd); } }
static void server_run(void) { /* IPv4 source address will be mapped to IPv6 address */ struct sockaddr_in6 addr6; socklen_t addr_size = sizeof(addr6); pthread_attr_init(&attr); /* * detaching threads allow to reclaim thread's resources * once a thread finishes its work. */ if (pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED) != 0) tst_brkm(TBROK | TERRNO, cleanup, "setdetachstate failed"); while (1) { int client_fd = accept(sfd, (struct sockaddr *)&addr6, &addr_size); if (client_fd == -1) tst_brkm(TBROK, cleanup, "Can't create client socket"); if (verbose) { char addr_buf[INET6_ADDRSTRLEN]; tst_resm(TINFO, "conn: port '%d', addr '%s'", addr6.sin6_port, inet_ntop(AF_INET6, &addr6.sin6_addr, addr_buf, INET6_ADDRSTRLEN)); } server_thread_add(client_fd); } }