aboutsummaryrefslogtreecommitdiff
path: root/libssh/server.c
diff options
context:
space:
mode:
authorAndreas Schneider <mail@cynapses.org>2009-04-29 11:48:54 +0000
committerAndreas Schneider <mail@cynapses.org>2009-04-29 11:48:54 +0000
commit23a55a0a0ad0e39f6dab34ef6e3d9a41bfb4d547 (patch)
treef013e4b7defcffa2db7d82fa823995ddc42c4777 /libssh/server.c
parent1cdc7c6e437a61282760159136f87542ca93f2a0 (diff)
downloadlibssh-23a55a0a0ad0e39f6dab34ef6e3d9a41bfb4d547.tar.gz
libssh-23a55a0a0ad0e39f6dab34ef6e3d9a41bfb4d547.tar.xz
libssh-23a55a0a0ad0e39f6dab34ef6e3d9a41bfb4d547.zip
Improve ssh_bind_listen().
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@650 7dcaeef0-15fb-0310-b436-a5af3365683c
Diffstat (limited to 'libssh/server.c')
-rw-r--r--libssh/server.c54
1 files changed, 32 insertions, 22 deletions
diff --git a/libssh/server.c b/libssh/server.c
index 1b42742..0fab8f1 100644
--- a/libssh/server.c
+++ b/libssh/server.c
@@ -129,28 +129,38 @@ void ssh_bind_set_options(SSH_BIND *ssh_bind, SSH_OPTIONS *options) {
ssh_bind->options = options;
}
-int ssh_bind_listen(SSH_BIND *ssh_bind){
- const char *host;
- int fd;
- if(!ssh_bind->options)
- return -1;
- if (ssh_socket_init() < 0) {
- return -1;
- }
- host=ssh_bind->options->bindaddr;
- if(!host)
- host="0.0.0.0";
- fd=bind_socket(ssh_bind,host,ssh_bind->options->bindport);
- if(fd<0)
- return -1;
- ssh_bind->bindfd=fd;
- if(listen(fd,10)<0){
- ssh_set_error(ssh_bind,SSH_FATAL,"listening to socket %d: %s",
- fd,strerror(errno));
- close(fd);
- return -1;
- }
- return 0;
+int ssh_bind_listen(SSH_BIND *ssh_bind) {
+ const char *host;
+ int fd;
+
+ if (ssh_bind->options == NULL) {
+ return -1;
+ }
+
+ if (ssh_socket_init() < 0) {
+ return -1;
+ }
+
+ host = ssh_bind->options->bindaddr;
+ if (host == NULL) {
+ host = "0.0.0.0";
+ }
+
+ fd = bind_socket(ssh_bind, host, ssh_bind->options->bindport);
+ if (fd < 0) {
+ return -1;
+ }
+ ssh_bind->bindfd = fd;
+
+ if (listen(fd, 10) < 0) {
+ ssh_set_error(ssh_bind, SSH_FATAL,
+ "Listening to socket %d: %s",
+ fd, strerror(errno));
+ close(fd);
+ return -1;
+ }
+
+ return 0;
}
void ssh_bind_set_blocking(SSH_BIND *ssh_bind, int blocking){