aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAris Adamantiadis <aris@0xbadc0de.be>2011-10-13 22:30:27 +0200
committerAris Adamantiadis <aris@0xbadc0de.be>2011-10-13 22:30:27 +0200
commit1fcddebadc178670e49447d4e7f07804add15a46 (patch)
treef57553200e04b6d892ad0720dd153c73186cc951
parent551a0c855b689cb959ff2a6ad2f5fcb1bba407d0 (diff)
downloadlibssh-1fcddebadc178670e49447d4e7f07804add15a46.tar.gz
libssh-1fcddebadc178670e49447d4e7f07804add15a46.tar.xz
libssh-1fcddebadc178670e49447d4e7f07804add15a46.zip
server: use app-provided bind socket when available
-rw-r--r--src/bind.c36
1 files changed, 19 insertions, 17 deletions
diff --git a/src/bind.c b/src/bind.c
index 22aa3da..3077df8 100644
--- a/src/bind.c
+++ b/src/bind.c
@@ -208,25 +208,27 @@ int ssh_bind_listen(ssh_bind sshbind) {
if (host == NULL) {
host = "0.0.0.0";
}
+ if (sshbind->bindfd != SSH_INVALID_SOCKET){
+ fd = bind_socket(sshbind, host, sshbind->bindport);
+ if (fd == SSH_INVALID_SOCKET) {
+ ssh_key_free(sshbind->dsa);
+ ssh_key_free(sshbind->rsa);
+ return -1;
+ }
+ sshbind->bindfd = fd;
- fd = bind_socket(sshbind, host, sshbind->bindport);
- if (fd == SSH_INVALID_SOCKET) {
- ssh_key_free(sshbind->dsa);
- ssh_key_free(sshbind->rsa);
- return -1;
- }
- sshbind->bindfd = fd;
-
- if (listen(fd, 10) < 0) {
- ssh_set_error(sshbind, SSH_FATAL,
- "Listening to socket %d: %s",
- fd, strerror(errno));
- close(fd);
- ssh_key_free(sshbind->dsa);
- ssh_key_free(sshbind->rsa);
- return -1;
+ if (listen(fd, 10) < 0) {
+ ssh_set_error(sshbind, SSH_FATAL,
+ "Listening to socket %d: %s",
+ fd, strerror(errno));
+ close(fd);
+ ssh_key_free(sshbind->dsa);
+ ssh_key_free(sshbind->rsa);
+ return -1;
+ }
+ } else {
+ SSH_LOG(sshbind, SSH_LOG_INFO, "Using app-provided bind socket");
}
-
return 0;
}