Improve ssh_bind_listen().

git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@650 7dcaeef0-15fb-0310-b436-a5af3365683c
This commit is contained in:
Andreas Schneider
2009-04-29 11:48:54 +00:00
parent 1cdc7c6e43
commit 23a55a0a0a

View File

@@ -129,27 +129,37 @@ void ssh_bind_set_options(SSH_BIND *ssh_bind, SSH_OPTIONS *options) {
ssh_bind->options = options; ssh_bind->options = options;
} }
int ssh_bind_listen(SSH_BIND *ssh_bind){ int ssh_bind_listen(SSH_BIND *ssh_bind) {
const char *host; const char *host;
int fd; int fd;
if(!ssh_bind->options)
if (ssh_bind->options == NULL) {
return -1; return -1;
}
if (ssh_socket_init() < 0) { if (ssh_socket_init() < 0) {
return -1; return -1;
} }
host=ssh_bind->options->bindaddr;
if(!host) host = ssh_bind->options->bindaddr;
host="0.0.0.0"; if (host == NULL) {
fd=bind_socket(ssh_bind,host,ssh_bind->options->bindport); host = "0.0.0.0";
if(fd<0) }
fd = bind_socket(ssh_bind, host, ssh_bind->options->bindport);
if (fd < 0) {
return -1; return -1;
ssh_bind->bindfd=fd; }
if(listen(fd,10)<0){ ssh_bind->bindfd = fd;
ssh_set_error(ssh_bind,SSH_FATAL,"listening to socket %d: %s",
fd,strerror(errno)); if (listen(fd, 10) < 0) {
ssh_set_error(ssh_bind, SSH_FATAL,
"Listening to socket %d: %s",
fd, strerror(errno));
close(fd); close(fd);
return -1; return -1;
} }
return 0; return 0;
} }