summaryrefslogtreecommitdiff
path: root/source3/rpc_server
diff options
context:
space:
mode:
authorAndreas Schneider <asn@samba.org>2011-05-23 16:00:30 +0200
committerAndreas Schneider <asn@samba.org>2011-08-01 08:50:34 +0200
commitcca96e47268d32e12e1b6b9a187f3096efa12b29 (patch)
tree7b291ab736ff25df6526ae080c3625ea1c77b092 /source3/rpc_server
parent95e8f09f6ea2a26bb552e351d6fc9a9d31cece62 (diff)
downloadsamba-cca96e47268d32e12e1b6b9a187f3096efa12b29.tar.gz
samba-cca96e47268d32e12e1b6b9a187f3096efa12b29.tar.bz2
samba-cca96e47268d32e12e1b6b9a187f3096efa12b29.zip
s3-rpc_server: Added common function to create tcpip socket.
Diffstat (limited to 'source3/rpc_server')
-rw-r--r--source3/rpc_server/rpc_server.c59
1 files changed, 36 insertions, 23 deletions
diff --git a/source3/rpc_server/rpc_server.c b/source3/rpc_server/rpc_server.c
index 2e109a5a9c..0caf20a990 100644
--- a/source3/rpc_server/rpc_server.c
+++ b/source3/rpc_server/rpc_server.c
@@ -625,6 +625,41 @@ static void dcerpc_ncacn_tcpip_listener(struct tevent_context *ev,
uint16_t flags,
void *private_data);
+int create_tcpip_socket(const struct sockaddr_storage *ifss, uint16_t *port)
+{
+ int fd = -1;
+
+ if (*port == 0) {
+ uint16_t i;
+
+ for (i = SERVER_TCP_LOW_PORT; i <= SERVER_TCP_HIGH_PORT; i++) {
+ fd = open_socket_in(SOCK_STREAM,
+ i,
+ 0,
+ ifss,
+ false);
+ if (fd > 0) {
+ *port = i;
+ break;
+ }
+ }
+ } else {
+ fd = open_socket_in(SOCK_STREAM,
+ *port,
+ 0,
+ ifss,
+ true);
+ }
+ if (fd == -1) {
+ DEBUG(0, ("Failed to create socket on port %u!\n", *port));
+ return -1;
+ }
+
+ DEBUG(10, ("Opened tcpip socket fd %d for port %u\n", fd, *port));
+
+ return fd;
+}
+
uint16_t setup_dcerpc_ncacn_tcpip_socket(struct tevent_context *ev_ctx,
struct messaging_context *msg_ctx,
const struct sockaddr_storage *ifss,
@@ -644,30 +679,8 @@ uint16_t setup_dcerpc_ncacn_tcpip_socket(struct tevent_context *ev_ctx,
state->ep.port = port;
state->disconnect_fn = NULL;
- if (state->ep.port == 0) {
- uint16_t i;
-
- for (i = SERVER_TCP_LOW_PORT; i <= SERVER_TCP_HIGH_PORT; i++) {
- state->fd = open_socket_in(SOCK_STREAM,
- i,
- 0,
- ifss,
- false);
- if (state->fd > 0) {
- state->ep.port = i;
- break;
- }
- }
- } else {
- state->fd = open_socket_in(SOCK_STREAM,
- state->ep.port,
- 0,
- ifss,
- true);
- }
+ state->fd = create_tcpip_socket(ifss, &state->ep.port);
if (state->fd == -1) {
- DEBUG(0, ("setup_dcerpc_ncacn_tcpip_socket: Failed to create "
- "socket on port %u!\n", state->ep.port));
goto out;
}