mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-12-28 04:55:08 +00:00
Added AF_UNIX socket support.
Signed-off-by: Brenden Matthews <brenden@diddyinc.com>
This commit is contained in:
parent
2c33e6e565
commit
edaf742295
@ -52,6 +52,7 @@
|
|||||||
# include <netinet/in.h>
|
# include <netinet/in.h>
|
||||||
# include <arpa/inet.h>
|
# include <arpa/inet.h>
|
||||||
# include <sys/socket.h>
|
# include <sys/socket.h>
|
||||||
|
# include <sys/un.h>
|
||||||
# include <netdb.h>
|
# include <netdb.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -119,6 +120,38 @@ static int do_connect_fail(mpd_Connection *connection,
|
|||||||
}
|
}
|
||||||
#endif /* !WIN32 */
|
#endif /* !WIN32 */
|
||||||
|
|
||||||
|
static int uds_connect(mpd_Connection *connection, const char *host,
|
||||||
|
float timeout)
|
||||||
|
{
|
||||||
|
struct sockaddr_un addr;
|
||||||
|
|
||||||
|
strncpy(addr.sun_path, host, sizeof(addr.sun_path)-1);
|
||||||
|
addr.sun_family = AF_UNIX;
|
||||||
|
addr.sun_path[sizeof(addr.sun_path)-1] = 0;
|
||||||
|
connection->sock = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||||
|
|
||||||
|
if (connection->sock < 0) {
|
||||||
|
snprintf(connection->errorStr, MPD_ERRORSTR_MAX_LENGTH,
|
||||||
|
"problems creating socket: %s", strerror(errno));
|
||||||
|
connection->error = MPD_ERROR_SYSTEM;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
mpd_setConnectionTimeout(connection, timeout);
|
||||||
|
|
||||||
|
/* connect stuff */
|
||||||
|
if (do_connect_fail(connection, (struct sockaddr *)&addr, SUN_LEN(&addr))) {
|
||||||
|
snprintf(connection->errorStr, MPD_ERRORSTR_MAX_LENGTH,
|
||||||
|
"problems cconnecting socket: %s", strerror(errno));
|
||||||
|
closesocket(connection->sock);
|
||||||
|
connection->sock = -1;
|
||||||
|
connection->error = MPD_ERROR_SYSTEM;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef MPD_HAVE_GAI
|
#ifdef MPD_HAVE_GAI
|
||||||
static int mpd_connect(mpd_Connection *connection, const char *host, int port,
|
static int mpd_connect(mpd_Connection *connection, const char *host, int port,
|
||||||
float timeout)
|
float timeout)
|
||||||
@ -129,6 +162,9 @@ static int mpd_connect(mpd_Connection *connection, const char *host, int port,
|
|||||||
struct addrinfo *res = NULL;
|
struct addrinfo *res = NULL;
|
||||||
struct addrinfo *addrinfo = NULL;
|
struct addrinfo *addrinfo = NULL;
|
||||||
|
|
||||||
|
if (*host == '/')
|
||||||
|
return uds_connect(connection, host, timeout);
|
||||||
|
|
||||||
/* Setup hints */
|
/* Setup hints */
|
||||||
hints.ai_flags = AI_ADDRCONFIG;
|
hints.ai_flags = AI_ADDRCONFIG;
|
||||||
hints.ai_family = AF_UNSPEC;
|
hints.ai_family = AF_UNSPEC;
|
||||||
@ -200,6 +236,9 @@ static int mpd_connect(mpd_Connection *connection, const char *host, int port,
|
|||||||
int destlen;
|
int destlen;
|
||||||
struct sockaddr_in sin;
|
struct sockaddr_in sin;
|
||||||
|
|
||||||
|
if (*host == '/')
|
||||||
|
return uds_connect(connection, host, timeout);
|
||||||
|
|
||||||
#ifdef HAVE_GETHOSTBYNAME_R
|
#ifdef HAVE_GETHOSTBYNAME_R
|
||||||
if (gethostbyname_r(rhost, &he, hostbuff, sizeof(hostbuff), &he_res, &he_errno)) { // get the host info
|
if (gethostbyname_r(rhost, &he, hostbuff, sizeof(hostbuff), &he_res, &he_errno)) { // get the host info
|
||||||
snprintf(connection->errorStr, MPD_ERRORSTR_MAX_LENGTH,
|
snprintf(connection->errorStr, MPD_ERRORSTR_MAX_LENGTH,
|
||||||
|
Loading…
Reference in New Issue
Block a user