Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
739c23cc
Commit
739c23cc
authored
Feb 24, 2009
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
listen: moved code to listen_add_host()
Split code from the rather large function listen_add_config_param(), part 3.
parent
33749e7e
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
72 additions
and
52 deletions
+72
-52
listen.c
src/listen.c
+72
-52
No files found.
src/listen.c
View file @
739c23cc
...
...
@@ -214,64 +214,26 @@ listen_add_port(unsigned int port, GError **error)
#endif
/* HAVE_TCP */
}
#ifdef HAVE_UN
/**
* Add a listener on a Unix domain socket.
* Resolves a host name, and adds listeners on all addresses in the
* result set.
*
* @param path the absolute socket path
* @param hostname the host name to be resolved
* @param port the TCP port
* @param error location to store the error occuring, or NULL to ignore errors
* @return true on success
*/
static
bool
listen_add_
path
(
const
char
*
path
,
GError
**
error
)
listen_add_
host
(
const
char
*
hostname
,
unsigned
port
,
GError
**
error
)
{
size_t
path_length
;
struct
sockaddr_un
s_un
;
const
struct
sockaddr
*
addrp
=
(
const
struct
sockaddr
*
)
&
s_un
;
socklen_t
addrlen
=
sizeof
(
s_un
);
bool
success
;
path_length
=
strlen
(
path
);
if
(
path_length
>=
sizeof
(
s_un
.
sun_path
))
g_error
(
"unix socket path is too long"
);
unlink
(
path
);
s_un
.
sun_family
=
AF_UNIX
;
memcpy
(
s_un
.
sun_path
,
path
,
path_length
+
1
);
success
=
listen_add_address
(
PF_UNIX
,
addrp
,
addrlen
,
error
);
if
(
!
success
)
return
false
;
/* allow everybody to connect */
chmod
(
path
,
0666
);
return
true
;
}
#endif
/* HAVE_UN */
static
bool
listen_add_config_param
(
unsigned
int
port
,
const
struct
config_param
*
param
,
GError
**
error
)
{
bool
success
;
if
(
!
param
||
0
==
strcmp
(
param
->
value
,
"any"
))
{
return
listen_add_port
(
port
,
error
);
#ifdef HAVE_UN
}
else
if
(
param
->
value
[
0
]
==
'/'
)
{
return
listen_add_path
(
param
->
value
,
error
);
#endif
/* HAVE_UN */
}
else
{
#ifdef HAVE_TCP
#ifndef WIN32
struct
addrinfo
hints
,
*
ai
,
*
i
;
char
service
[
20
];
int
ret
;
bool
success
;
g_debug
(
"binding to address for %s"
,
param
->
valu
e
);
g_debug
(
"binding to address for %s"
,
hostnam
e
);
memset
(
&
hints
,
0
,
sizeof
(
hints
));
hints
.
ai_flags
=
AI_PASSIVE
;
...
...
@@ -284,10 +246,13 @@ listen_add_config_param(unsigned int port,
g_snprintf
(
service
,
sizeof
(
service
),
"%u"
,
port
);
ret
=
getaddrinfo
(
param
->
value
,
service
,
&
hints
,
&
ai
);
if
(
ret
!=
0
)
g_error
(
"can't lookup host
\"
%s
\"
at line %i: %s"
,
param
->
value
,
param
->
line
,
gai_strerror
(
ret
));
ret
=
getaddrinfo
(
hostname
,
service
,
&
hints
,
&
ai
);
if
(
ret
!=
0
)
{
g_set_error
(
error
,
listen_quark
(),
ret
,
"Failed to look up host
\"
%s
\"
: %s"
,
hostname
,
gai_strerror
(
ret
));
return
false
;
}
for
(
i
=
ai
;
i
!=
NULL
;
i
=
i
->
ai_next
)
{
success
=
listen_add_address
(
i
->
ai_family
,
i
->
ai_addr
,
...
...
@@ -305,9 +270,11 @@ listen_add_config_param(unsigned int port,
g_debug
(
"binding to address for %s"
,
param
->
value
);
he
=
gethostbyname
(
param
->
value
);
if
(
he
==
NULL
)
g_error
(
"can't lookup host
\"
%s
\"
at line %i"
,
param
->
value
,
param
->
line
);
if
(
he
==
NULL
)
{
g_set_error
(
error
,
listen_quark
(),
0
,
"Failed to look up host
\"
%s
\"
"
,
hostname
);
return
false
;
}
if
(
he
->
h_addrtype
!=
AF_INET
)
g_error
(
"IPv4 address expected for host
\"
%s
\"
at line %i"
,
...
...
@@ -317,10 +284,63 @@ listen_add_config_param(unsigned int port,
error
);
#endif
/* !WIN32 */
#else
/* HAVE_TCP */
g_set_error
(
error
,
listen_quark
(),
0
,
"TCP support is disabled"
);
return
false
;
#endif
/* HAVE_TCP */
}
#ifdef HAVE_UN
/**
* Add a listener on a Unix domain socket.
*
* @param path the absolute socket path
* @param error location to store the error occuring, or NULL to ignore errors
* @return true on success
*/
static
bool
listen_add_path
(
const
char
*
path
,
GError
**
error
)
{
size_t
path_length
;
struct
sockaddr_un
s_un
;
const
struct
sockaddr
*
addrp
=
(
const
struct
sockaddr
*
)
&
s_un
;
socklen_t
addrlen
=
sizeof
(
s_un
);
bool
success
;
path_length
=
strlen
(
path
);
if
(
path_length
>=
sizeof
(
s_un
.
sun_path
))
g_error
(
"unix socket path is too long"
);
unlink
(
path
);
s_un
.
sun_family
=
AF_UNIX
;
memcpy
(
s_un
.
sun_path
,
path
,
path_length
+
1
);
success
=
listen_add_address
(
PF_UNIX
,
addrp
,
addrlen
,
error
);
if
(
!
success
)
return
false
;
/* allow everybody to connect */
chmod
(
path
,
0666
);
return
true
;
}
#endif
/* HAVE_UN */
static
bool
listen_add_config_param
(
unsigned
int
port
,
const
struct
config_param
*
param
,
GError
**
error
)
{
if
(
!
param
||
0
==
strcmp
(
param
->
value
,
"any"
))
{
return
listen_add_port
(
port
,
error
);
#ifdef HAVE_UN
}
else
if
(
param
->
value
[
0
]
==
'/'
)
{
return
listen_add_path
(
param
->
value
,
error
);
#endif
/* HAVE_UN */
}
else
{
return
listen_add_host
(
param
->
value
,
port
,
error
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment