Untitled

                Never    
C
       
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <limits.h>
#include <string.h>
#include <unistd.h>
#include <stdint.h>
#include <inttypes.h>

int main(int argc, char **argv) {
    int fd = socket(PF_INET, SOCK_STREAM, 0);
    int port;
    sscanf(argv[1], "%d", &port);
    struct sockaddr_in sin = {
            .sin_family = AF_INET,
            .sin_port = htons(port),
            .sin_addr.s_addr = INADDR_ANY};
    bind(fd, (struct sockaddr *) &sin, sizeof(sin));
    listen(fd, 5);
    struct sockaddr_in scl;
    socklen_t len = sizeof(scl);
    int32_t res = 0;
    while (1) {
        int fd_c = accept(fd, (struct sockaddr *) &scl, &len);
        int32_t num = 0;
        while (read(fd_c, &num, sizeof(num)) != 0) {}
        close(fd_c);
        if (!num) {
            break;
        }
        res += (int32_t) ntohl(num);
    }
    printf("%" PRId32 "\n", res);
    close(fd);
    return 0;
}

Raw Text