wip
Dependents: EthernetInterface_vz
Fork of Socket by
Diff: TCPSocketConnection.cpp
- Revision:
- 5:300e7ad2dc1d
- Parent:
- 4:75988d748e4d
- Child:
- 6:cd2e5559786d
diff -r 75988d748e4d -r 300e7ad2dc1d TCPSocketConnection.cpp --- a/TCPSocketConnection.cpp Thu Jul 26 10:07:43 2012 +0000 +++ b/TCPSocketConnection.cpp Thu Jul 26 15:07:32 2012 +0000 @@ -23,24 +23,15 @@ TCPSocketConnection::TCPSocketConnection() : _closedByRemoteHost(false) { - memset(&_remoteHost, 0, sizeof(struct sockaddr_in)); - _ipAddress[0] = '\0'; } int TCPSocketConnection::connect(const char* host, const int port) { - if (init(SOCK_STREAM) < 0) + if (init_socket(SOCK_STREAM) < 0) return -1; - //Resolve DNS address or populate hard-coded IP address - struct hostent *server = gethostbyname(host); - if (server == NULL) - return -1; //Could not resolve address + if (set_address(host, port) != 0) + return -1; - memcpy((char*) &_remoteHost.sin_addr.s_addr, - (char*) server->h_addr_list[0], server->h_length); - - _remoteHost.sin_family = AF_INET; - _remoteHost.sin_port = htons(port); if (lwip_connect(_sock_fd, (const struct sockaddr *) &_remoteHost, sizeof(_remoteHost)) < 0) { close(); return -1; @@ -129,18 +120,6 @@ return readLen; } -char* TCPSocketConnection::get_address() { - if (_ipAddress[0] == '\0') { - if (_remoteHost.sin_addr.s_addr == 0) - return NULL; - inet_ntoa_r(_remoteHost.sin_addr, _ipAddress, sizeof(_ipAddress)); - } - return _ipAddress; -} -int TCPSocketConnection::get_port() { - return ntohs(_remoteHost.sin_port); -} - TCPSocketConnection::~TCPSocketConnection() { close(); //Don't want to leak }