summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/cssh.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/cssh.c b/src/cssh.c
index bb03430..be138b4 100644
--- a/src/cssh.c
+++ b/src/cssh.c
@@ -13,6 +13,7 @@
#include <pwd.h>
#include <inttypes.h>
#include <unistd.h>
+#include <netdb.h>
#include "msleep.h"
@@ -20,6 +21,7 @@
#include "version.h"
#define BUFSIZE 4096
+#define DEFAULT_SSH_PORT 22
typedef enum auth_state_e {
CSSH_AUTH_INIT,
@@ -161,6 +163,16 @@ ASK_AGAIN:
return true;
}
+static unsigned short get_default_ssh_port( )
+{
+ struct servent *ent = getservbyname( "ssh", "tcp" );
+ if( ent != NULL ) {
+ return (unsigned short)ntohs( ent->s_port );
+ } else {
+ return DEFAULT_SSH_PORT;
+ }
+}
+
static int accept_server( ssh_session session, unsigned char *hash, size_t hlen )
{
char *hexa;
@@ -482,7 +494,7 @@ int main( int argc, char *argv[] )
case CSSH_EXECUTE_AS_SSH: {
// command line arguments are '[user@]host'
if( !args_info.hosts_file_given ) {
- unsigned short default_port = 22;
+ unsigned short default_port = get_default_ssh_port( );
host = (char **)malloc( sizeof( char * ) );
port = (unsigned short *)malloc( sizeof( unsigned short ) );
if( args_info.inputs_num >= 1 ) {
@@ -541,7 +553,7 @@ int main( int argc, char *argv[] )
// for the hosts in the file containing hosts
unsigned nof_hosts;
- unsigned short default_port = 22;
+ unsigned short default_port = get_default_ssh_port( );
if( args_info.port_given ) {
default_port = args_info.port_arg;
}