- fprintf(f, "%s %s %d\n", controlcookie, myport, getpid());
+ char *localhost = NULL;
+ sockaddr_t sa;
+ socklen_t len = sizeof sa;
+
+ if(getsockname(listen_socket[0].tcp, (struct sockaddr *)&sa, &len))
+ xasprintf(&localhost, "127.0.0.1 port %d", myport);
+ else
+ localhost = sockaddr2hostname(&sa);
+
+ fprintf(f, "%d %s %s\n", (int)getpid(), controlcookie, localhost);
+
+ free(localhost);