Connection: Store the port number as a string
Signed-off-by: Anders Kaseorg <andersk@mit.edu>
This commit is contained in:
@@ -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