diff --git a/bin/ax25dump.c b/bin/ax25dump.c index f3df769..8f35455 100644 --- a/bin/ax25dump.c +++ b/bin/ax25dump.c @@ -13,7 +13,6 @@ #include #include -#include #include @@ -48,7 +47,7 @@ int main(int argc, char **argv) { void *buf; ssize_t readlen; - char *sock = PATTY_DAEMON_DEFAULT_SOCK, + char *sock = NULL, *ifname = NULL; patty_kiss_tnc_info info; diff --git a/bin/tncd.c b/bin/tncd.c index 9f55fc6..080bed5 100644 --- a/bin/tncd.c +++ b/bin/tncd.c @@ -13,7 +13,6 @@ #include #include -#include #include #include @@ -167,7 +166,7 @@ int main(int argc, char **argv) { { NULL, 0, NULL, 0 } }; - char *sock = PATTY_DAEMON_DEFAULT_SOCK, + char *sock = NULL, *ifname = NULL; int ch, diff --git a/include/patty/client.h b/include/patty/client.h index e804f28..7059542 100644 --- a/include/patty/client.h +++ b/include/patty/client.h @@ -1,6 +1,8 @@ #ifndef _PATTY_CLIENT_H #define _PATTY_CLIENT_H +#define PATTY_CLIENT_DEFAULT_SOCK_NAME "patty.sock" + enum patty_client_call { PATTY_CLIENT_NONE, PATTY_CLIENT_PING, diff --git a/src/client.c b/src/client.c index 533b138..5db87cb 100644 --- a/src/client.c +++ b/src/client.c @@ -4,10 +4,12 @@ #include #include #include +#include #include #include #include +#include struct _patty_client_sock { int fd; @@ -19,6 +21,15 @@ struct _patty_client { patty_dict *socks; }; +static const char *find_sock(const char *path) { + struct stat st; + + return path? + path: stat(PATTY_CLIENT_DEFAULT_SOCK_NAME, &st) == 0? + PATTY_CLIENT_DEFAULT_SOCK_NAME: + PATTY_DAEMON_DEFAULT_SOCK; +} + patty_client *patty_client_new(const char *path) { patty_client *client; struct sockaddr_un addr; @@ -37,7 +48,8 @@ patty_client *patty_client_new(const char *path) { memset(&addr, '\0', sizeof(addr)); addr.sun_family = AF_UNIX; - strncpy(addr.sun_path, path, sizeof(addr.sun_path)-1); + + strncpy(addr.sun_path, find_sock(path), sizeof(addr.sun_path)-1); if (connect(client->fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) { goto error_connect;