Why, after starting the server socket and using shutdown (), do I have a file in this directory?

So, I make the basic server and client program in C, and after starting the program, the result is a really strange named file, which I have to delete in order for the program to work again. I assume that I am not closing sockets correctly. I am currently closing sockets as follows:

shutdown(serverSocket, SHUT_RDWR);
shutdown(clientSocket, SHUT_RDWR);

Any idea on why this is happening?

Edit: both of these functions return 0

Here is the code causing the problem:

    char buf[1024];
    struct sockaddr_in server, client;

    int serverSocket = socket(PF_LOCAL, SOCK_STREAM, 0);

    server.sin_family = AF_LOCAL;
    server.sin_port = htons(54164);
    server.sin_addr.s_addr = inet_addr("127.0.0.1");

    bind(serverSocket, (struct sockaddr *) &server, sizeof(server));

The file does not appear until I ran the bind function.

+4
source share
1 answer

, . struct sockaddr_in ( AF_INET).

AF_LOCAL (a.k.a. AF_UNIX) bind , struct sockaddr_un, ( ).

manpage unix-:

UNIX :

struct sockaddr_un {
    sa_family_t sun_family;               /* AF_UNIX */
    char        sun_path[108];            /* pathname */
};

sun_family AF_UNIX. Linux sun_path 108 .

:

        , ,        ( unlink (2)). UNIX         ;         , .

+4

Source: https://habr.com/ru/post/1626946/


All Articles