int server_sockfd, client_sockfd; //server and client filedescriptors
    socklen_t server_len, client_len;
    struct sockaddr_in server_address; //server address
    struct sockaddr_in client_address; //client address
    int server_port = 10000;
    char *def_server_address ="127.0.0.1";

    server_len = sizeof(server_address);
    memset(&server_address, 0, server_len );
    server_address.sin_family = AF_INET;

    if (x == 1) {
        server_address.sin_addr.s_addr = INADDR_ANY;}
    else {
        server_address.sin_addr.s_addr = inet_addr(def_server_address);
    }
    server_address.sin_port = htons(server_port);

我应该如何从server_address打印服务器的地址?使用printf。

最佳答案

使用 inet_ntop() 将其转换为字符串

关于c - 我应该如何打印服务器地址,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9590529/

10-10 12:50