summaryrefslogtreecommitdiff
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
parent95e8f09f6ea2a26bb552e351d6fc9a9d31cece62 (diff)
downloadsamba-cca96e47268d32e12e1b6b9a187f3096efa12b29.tar.gz
samba-cca96e47268d32e12e1b6b9a187f3096efa12b29.tar.bz2
samba-cca96e47268d32e12e1b6b9a187f3096efa12b29.zip
s3-rpc_server: Added common function to create tcpip socket.
-rw-r--r--source3/include/proto.h1
-rw-r--r--source3/rpc_server/rpc_server.c59
2 files changed, 37 insertions, 23 deletions
diff --git a/source3/include/proto.h b/source3/include/proto.h
index 095c52c7c0..2619e7bbde 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -793,6 +793,7 @@ int get_remote_hostname(const struct tsocket_address *remote_address,
int create_pipe_sock(const char *socket_dir,
const char *socket_name,
mode_t dir_perms);
+int create_tcpip_socket(const struct sockaddr_storage *ifss, uint16_t *port);
const char *get_mydnsfullname(void);
bool is_myname_or_ipaddr(const char *s);
struct tevent_req *getaddrinfo_send(TALLOC_CTX *mem_ctx,
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;
}