[mpd] support for ipv6
This commit is contained in:
parent
34d815a130
commit
5b0cb6588b
33
src/mpd.c
33
src/mpd.c
|
@ -3673,10 +3673,15 @@ mpd_accept_error_cb(struct evconnlistener *listener, void *ctx)
|
|||
int mpd_init(void)
|
||||
{
|
||||
struct evconnlistener *listener;
|
||||
struct sockaddr *saddr;
|
||||
size_t saddr_length;
|
||||
struct sockaddr_in sin;
|
||||
struct sockaddr_in6 sin6;
|
||||
unsigned short port;
|
||||
int v6enabled;
|
||||
int ret;
|
||||
|
||||
|
||||
port = cfg_getint(cfg_getsec(cfg, "mpd"), "port");
|
||||
if (port <= 0)
|
||||
{
|
||||
|
@ -3684,6 +3689,8 @@ int mpd_init(void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
v6enabled = cfg_getbool(cfg_getsec(cfg, "general"), "ipv6");
|
||||
|
||||
# if defined(__linux__)
|
||||
ret = pipe2(g_exit_pipe, O_CLOEXEC);
|
||||
# else
|
||||
|
@ -3711,11 +3718,23 @@ int mpd_init(void)
|
|||
|
||||
event_add(g_exitev, NULL);
|
||||
|
||||
//TODO ipv6
|
||||
memset(&sin, 0, sizeof(sin));
|
||||
sin.sin_family = AF_INET;
|
||||
sin.sin_addr.s_addr = htonl(0);
|
||||
sin.sin_port = htons(port);
|
||||
if (v6enabled)
|
||||
{
|
||||
saddr_length = sizeof(sin6);
|
||||
memset(&sin6, 0, saddr_length);
|
||||
sin6.sin6_family = AF_INET6;
|
||||
sin6.sin6_port = htons(port);
|
||||
saddr = (struct sockaddr *)&sin6;
|
||||
}
|
||||
else
|
||||
{
|
||||
saddr_length = sizeof(struct sockaddr_in);
|
||||
memset(&sin, 0, saddr_length);
|
||||
sin.sin_family = AF_INET;
|
||||
sin.sin_addr.s_addr = htonl(0);
|
||||
sin.sin_port = htons(port);
|
||||
saddr = (struct sockaddr *)&sin;
|
||||
}
|
||||
|
||||
listener = evconnlistener_new_bind(
|
||||
evbase_mpd,
|
||||
|
@ -3723,8 +3742,8 @@ int mpd_init(void)
|
|||
NULL,
|
||||
LEV_OPT_CLOSE_ON_FREE | LEV_OPT_REUSEABLE,
|
||||
-1,
|
||||
(struct sockaddr*) &sin,
|
||||
sizeof(sin));
|
||||
saddr,
|
||||
saddr_length);
|
||||
|
||||
if (!listener)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue