Connection: Store the port number as a string
Signed-off-by: Anders Kaseorg <andersk@mit.edu>
This commit is contained in:
@@ -46,7 +46,7 @@ int main( int argc, char *argv[] )
|
||||
bool server = true;
|
||||
char *key;
|
||||
char *ip;
|
||||
int port;
|
||||
char *port;
|
||||
|
||||
UserStream me, remote;
|
||||
|
||||
@@ -59,7 +59,7 @@ int main( int argc, char *argv[] )
|
||||
|
||||
key = argv[ 1 ];
|
||||
ip = argv[ 2 ];
|
||||
port = atoi( argv[ 3 ] );
|
||||
port = argv[ 3 ];
|
||||
|
||||
n = new Transport<UserStream, UserStream>( me, remote, key, ip, port );
|
||||
} else {
|
||||
@@ -70,7 +70,7 @@ int main( int argc, char *argv[] )
|
||||
exit( 1 );
|
||||
}
|
||||
|
||||
fprintf( stderr, "Port bound is %d, key is %s\n", n->port(), n->get_key().c_str() );
|
||||
fprintf( stderr, "Port bound is %s, key is %s\n", n->port().c_str(), n->get_key().c_str() );
|
||||
|
||||
if ( server ) {
|
||||
Select &sel = Select::get_instance();
|
||||
|
||||
@@ -117,7 +117,6 @@ int main( int argc, char *argv[] )
|
||||
}
|
||||
|
||||
char *ip, *desired_port;
|
||||
int port;
|
||||
|
||||
if ( argc - optind != 2 ) {
|
||||
usage( argv[ 0 ] );
|
||||
@@ -142,8 +141,6 @@ int main( int argc, char *argv[] )
|
||||
exit( 1 );
|
||||
}
|
||||
|
||||
port = myatoi( desired_port );
|
||||
|
||||
/* Read key from environment */
|
||||
char *env_key = getenv( "MOSH_KEY" );
|
||||
if ( env_key == NULL ) {
|
||||
@@ -170,7 +167,7 @@ int main( int argc, char *argv[] )
|
||||
set_native_locale();
|
||||
|
||||
try {
|
||||
STMClient client( ip, port, key, predict_mode );
|
||||
STMClient client( ip, desired_port, key, predict_mode );
|
||||
client.init();
|
||||
|
||||
try {
|
||||
|
||||
@@ -354,7 +354,7 @@ int run_server( const char *desired_ip, const char *desired_port,
|
||||
network->set_verbose();
|
||||
}
|
||||
|
||||
printf( "\nMOSH CONNECT %d %s\n", network->port(), network->get_key().c_str() );
|
||||
printf( "\nMOSH CONNECT %s %s\n", network->port().c_str(), network->get_key().c_str() );
|
||||
fflush( stdout );
|
||||
|
||||
/* don't let signals kill us */
|
||||
|
||||
@@ -188,7 +188,7 @@ void STMClient::init( void )
|
||||
escape_key_help = L"Commands: Ctrl-Z suspends, \".\" quits, " + escape_pass_name + L" gives literal " + escape_key_name;
|
||||
}
|
||||
wchar_t tmp[ 128 ];
|
||||
swprintf( tmp, 128, L"Nothing received from server on UDP port %d.", port );
|
||||
swprintf( tmp, 128, L"Nothing received from server on UDP port %s.", port.c_str() );
|
||||
connecting_notification = wstring( tmp );
|
||||
}
|
||||
|
||||
@@ -209,8 +209,8 @@ void STMClient::shutdown( void )
|
||||
}
|
||||
|
||||
if ( still_connecting() ) {
|
||||
fprintf( stderr, "\nmosh did not make a successful connection to %s:%d.\n", ip.c_str(), port );
|
||||
fprintf( stderr, "Please verify that UDP port %d is not firewalled and can reach the server.\n\n", port );
|
||||
fprintf( stderr, "\nmosh did not make a successful connection to %s:%s.\n", ip.c_str(), port.c_str() );
|
||||
fprintf( stderr, "Please verify that UDP port %s is not firewalled and can reach the server.\n\n", port.c_str() );
|
||||
fprintf( stderr, "(By default, mosh uses a UDP port between 60000 and 61000. The -p option\nselects a specific UDP port number.)\n" );
|
||||
} else if ( network ) {
|
||||
if ( !clean_shutdown ) {
|
||||
@@ -247,7 +247,7 @@ void STMClient::main_init( void )
|
||||
Network::UserStream blank;
|
||||
Terminal::Complete local_terminal( window_size.ws_col, window_size.ws_row );
|
||||
network = new Network::Transport< Network::UserStream, Terminal::Complete >( blank, local_terminal,
|
||||
key.c_str(), ip.c_str(), port );
|
||||
key.c_str(), ip.c_str(), port.c_str() );
|
||||
|
||||
network->set_send_delay( 1 ); /* minimal delay on outgoing keystrokes */
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
class STMClient {
|
||||
private:
|
||||
std::string ip;
|
||||
int port;
|
||||
std::string port;
|
||||
std::string key;
|
||||
|
||||
int escape_key;
|
||||
@@ -83,7 +83,7 @@ private:
|
||||
void resume( void ); /* restore state after SIGCONT */
|
||||
|
||||
public:
|
||||
STMClient( const char *s_ip, int s_port, const char *s_key, const char *predict_mode )
|
||||
STMClient( const char *s_ip, const char *s_port, const char *s_key, const char *predict_mode )
|
||||
: ip( s_ip ), port( s_port ), key( s_key ),
|
||||
escape_key( 0x1E ), escape_pass_key( '^' ), escape_pass_key2( '^' ),
|
||||
escape_requires_lf( false ), escape_key_help( L"?" ),
|
||||
|
||||
@@ -306,7 +306,7 @@ bool Connection::try_bind( int socket, uint32_t addr, int port_low, int port_hig
|
||||
return false;
|
||||
}
|
||||
|
||||
Connection::Connection( const char *key_str, const char *ip, int port ) /* client */
|
||||
Connection::Connection( const char *key_str, const char *ip, const char *port ) /* client */
|
||||
: socks(),
|
||||
has_remote_addr( false ),
|
||||
remote_addr(),
|
||||
@@ -332,7 +332,7 @@ Connection::Connection( const char *key_str, const char *ip, int port ) /* clien
|
||||
|
||||
/* associate socket with remote host and port */
|
||||
remote_addr.sin_family = AF_INET;
|
||||
remote_addr.sin_port = htons( port );
|
||||
remote_addr.sin_port = htons( myatoi( port ) );
|
||||
if ( !inet_aton( ip, &remote_addr.sin_addr ) ) {
|
||||
int saved_errno = errno;
|
||||
char buffer[ 2048 ];
|
||||
@@ -524,7 +524,7 @@ string Connection::recv_one( int sock_to_recv, bool nonblocking )
|
||||
return p.payload; /* we do return out-of-order or duplicated packets to caller */
|
||||
}
|
||||
|
||||
int Connection::port( void ) const
|
||||
std::string Connection::port( void ) const
|
||||
{
|
||||
struct sockaddr_in local_addr;
|
||||
socklen_t addrlen = sizeof( local_addr );
|
||||
@@ -533,7 +533,9 @@ int Connection::port( void ) const
|
||||
throw NetworkException( "getsockname", errno );
|
||||
}
|
||||
|
||||
return ntohs( local_addr.sin_port );
|
||||
char buf[ 32 ];
|
||||
snprintf( buf, sizeof( buf ), "%d", ntohs( local_addr.sin_port ) );
|
||||
return std::string( buf );
|
||||
}
|
||||
|
||||
uint64_t Network::timestamp( void )
|
||||
|
||||
@@ -161,14 +161,14 @@ namespace Network {
|
||||
|
||||
public:
|
||||
Connection( const char *desired_ip, const char *desired_port ); /* server */
|
||||
Connection( const char *key_str, const char *ip, int port ); /* client */
|
||||
Connection( const char *key_str, const char *ip, const char *port ); /* client */
|
||||
|
||||
void send( string s );
|
||||
string recv( void );
|
||||
const std::vector< int > fds( void ) const;
|
||||
int get_MTU( void ) const { return MTU; }
|
||||
|
||||
int port( void ) const;
|
||||
std::string port( void ) const;
|
||||
string get_key( void ) const { return key.printable_key(); }
|
||||
bool get_has_remote_addr( void ) const { return has_remote_addr; }
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ Transport<MyState, RemoteState>::Transport( MyState &initial_state, RemoteState
|
||||
|
||||
template <class MyState, class RemoteState>
|
||||
Transport<MyState, RemoteState>::Transport( MyState &initial_state, RemoteState &initial_remote,
|
||||
const char *key_str, const char *ip, int port )
|
||||
const char *key_str, const char *ip, const char *port )
|
||||
: connection( key_str, ip, port ),
|
||||
sender( &connection, initial_state ),
|
||||
received_states( 1, TimestampedState<RemoteState>( timestamp(), 0, initial_remote ) ),
|
||||
|
||||
@@ -69,7 +69,7 @@ namespace Network {
|
||||
Transport( MyState &initial_state, RemoteState &initial_remote,
|
||||
const char *desired_ip, const char *desired_port );
|
||||
Transport( MyState &initial_state, RemoteState &initial_remote,
|
||||
const char *key_str, const char *ip, int port );
|
||||
const char *key_str, const char *ip, const char *port );
|
||||
|
||||
/* Send data or an ack if necessary. */
|
||||
void tick( void ) { sender.tick(); }
|
||||
@@ -94,7 +94,7 @@ namespace Network {
|
||||
/* Other side has requested shutdown and we have sent one ACK */
|
||||
bool counterparty_shutdown_ack_sent( void ) const { return sender.get_counterparty_shutdown_acknowledged(); }
|
||||
|
||||
int port( void ) const { return connection.port(); }
|
||||
std::string port( void ) const { return connection.port(); }
|
||||
string get_key( void ) const { return connection.get_key(); }
|
||||
|
||||
MyState &get_current_state( void ) { return sender.get_current_state(); }
|
||||
|
||||
Reference in New Issue
Block a user