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
adf044eb
Commit
adf044eb
authored
Feb 24, 2009
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
listen: splitted listen_add_port() into IPv4 and IPv6
Some more code simplification.
parent
d40c4394
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
20 deletions
+52
-20
listen.c
src/listen.c
+52
-20
No files found.
src/listen.c
View file @
adf044eb
...
...
@@ -149,6 +149,55 @@ is_ipv6_enabled(void)
}
#endif
#ifdef HAVE_TCP
/**
* Add a listener on a port on all IPv4 interfaces.
*
* @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_port_ipv4
(
unsigned
int
port
,
GError
**
error
)
{
struct
sockaddr_in
sin
;
const
struct
sockaddr
*
addrp
=
(
const
struct
sockaddr
*
)
&
sin
;
socklen_t
addrlen
=
sizeof
(
sin
);
memset
(
&
sin
,
0
,
sizeof
(
sin
));
sin
.
sin_port
=
htons
(
port
);
sin
.
sin_family
=
AF_INET
;
sin
.
sin_addr
.
s_addr
=
INADDR_ANY
;
return
listen_add_address
(
PF_INET
,
addrp
,
addrlen
,
error
);
}
#ifdef HAVE_IPV6
/**
* Add a listener on a port on all IPv6 interfaces.
*
* @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_port_ipv6
(
unsigned
int
port
,
GError
**
error
)
{
struct
sockaddr_in6
sin
;
const
struct
sockaddr
*
addrp
=
(
const
struct
sockaddr
*
)
&
sin
;
socklen_t
addrlen
=
sizeof
(
sin
);
memset
(
&
sin
,
0
,
sizeof
(
sin
));
sin
.
sin6_port
=
htons
(
port
);
sin
.
sin6_family
=
AF_INET6
;
return
listen_add_address
(
PF_INET6
,
addrp
,
addrlen
,
error
);
}
#endif
/* HAVE_IPV6 */
#endif
/* HAVE_TCP */
/**
* Add a listener on a port on all interfaces.
*
...
...
@@ -161,39 +210,22 @@ listen_add_port(unsigned int port, GError **error)
{
#ifdef HAVE_TCP
bool
success
;
const
struct
sockaddr
*
addrp
;
socklen_t
addrlen
;
struct
sockaddr_in
sin4
;
#ifdef HAVE_IPV6
struct
sockaddr_in6
sin6
;
int
ipv6_enabled
=
is_ipv6_enabled
();
memset
(
&
sin6
,
0
,
sizeof
(
struct
sockaddr_in6
));
sin6
.
sin6_port
=
htons
(
port
);
sin6
.
sin6_family
=
AF_INET6
;
#endif
memset
(
&
sin4
,
0
,
sizeof
(
struct
sockaddr_in
));
sin4
.
sin_port
=
htons
(
port
);
sin4
.
sin_family
=
AF_INET
;
g_debug
(
"binding to any address"
);
#ifdef HAVE_IPV6
if
(
ipv6_enabled
)
{
sin6
.
sin6_addr
=
in6addr_any
;
addrp
=
(
const
struct
sockaddr
*
)
&
sin6
;
addrlen
=
sizeof
(
struct
sockaddr_in6
);
success
=
listen_add_address
(
PF_INET6
,
addrp
,
addrlen
,
error
);
success
=
listen_add_port_ipv6
(
port
,
error
);
if
(
!
success
)
return
false
;
}
#endif
sin4
.
sin_addr
.
s_addr
=
INADDR_ANY
;
addrp
=
(
const
struct
sockaddr
*
)
&
sin4
;
addrlen
=
sizeof
(
struct
sockaddr_in
);
success
=
listen_add_
address
(
PF_INET
,
addrp
,
addrlen
,
error
);
success
=
listen_add_
port_ipv4
(
port
,
error
);
if
(
!
success
)
{
#ifdef HAVE_IPV6
if
(
ipv6_enabled
)
...
...
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