Created
June 14, 2015 17:59
-
-
Save devendranaga/203dbbdcc6dc9238edef to your computer and use it in GitHub Desktop.
get a unix socket name by fd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <sys/un.h> | |
#include <sys/socket.h> | |
int get_sock_name(int fd, char *name, int name_len) | |
{ | |
int ret | |
socklen_t len = sizeof(struct sockaddr_un); | |
struct sockaddr_un s; | |
ret = getsockname(fd, (struct sockaddr *)&s, &len); | |
if (!ret) { | |
if (s.sun_path[0]) | |
strncpy(name, s.sun_path, name_len) | |
} | |
return ret | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment