aboutsummaryrefslogtreecommitdiff
path: root/src/bind.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/bind.c')
-rw-r--r--src/bind.c53
1 files changed, 28 insertions, 25 deletions
diff --git a/src/bind.c b/src/bind.c
index fa8df9ea..b326a52b 100644
--- a/src/bind.c
+++ b/src/bind.c
@@ -550,34 +550,37 @@ int ssh_bind_accept_fd(ssh_bind sshbind, ssh_session session, socket_t fd){
return SSH_OK;
}
-int ssh_bind_accept(ssh_bind sshbind, ssh_session session) {
- socket_t fd = SSH_INVALID_SOCKET;
- int rc;
- if (sshbind->bindfd == SSH_INVALID_SOCKET) {
- ssh_set_error(sshbind, SSH_FATAL,
- "Can't accept new clients on a not bound socket.");
- return SSH_ERROR;
- }
+int ssh_bind_accept(ssh_bind sshbind, ssh_session session)
+{
+ socket_t fd = SSH_INVALID_SOCKET;
+ int rc;
- if (session == NULL){
- ssh_set_error(sshbind, SSH_FATAL,"session is null");
- return SSH_ERROR;
- }
+ if (sshbind->bindfd == SSH_INVALID_SOCKET) {
+ ssh_set_error(sshbind, SSH_FATAL,
+ "Can't accept new clients on a not bound socket.");
+ return SSH_ERROR;
+ }
- fd = accept(sshbind->bindfd, NULL, NULL);
- if (fd == SSH_INVALID_SOCKET) {
- ssh_set_error(sshbind, SSH_FATAL,
- "Accepting a new connection: %s",
- strerror(errno));
- return SSH_ERROR;
- }
- rc = ssh_bind_accept_fd(sshbind, session, fd);
+ if (session == NULL) {
+ ssh_set_error(sshbind, SSH_FATAL, "session is null");
+ return SSH_ERROR;
+ }
- if(rc == SSH_ERROR){
- CLOSE_SOCKET(fd);
- ssh_socket_free(session->socket);
- }
- return rc;
+ fd = accept(sshbind->bindfd, NULL, NULL);
+ if (fd == SSH_INVALID_SOCKET) {
+ ssh_set_error(sshbind, SSH_FATAL,
+ "Accepting a new connection: %s",
+ strerror(errno));
+ return SSH_ERROR;
+ }
+ rc = ssh_bind_accept_fd(sshbind, session, fd);
+
+ if (rc == SSH_ERROR) {
+ CLOSE_SOCKET(fd);
+ ssh_socket_free(session->socket);
+ }
+
+ return rc;
}