Added support for printing out the peer's IPv6 address; replaced struct sockaddr with struct sockaddr_storage

master
Aadhavan Srinivasan 10 months ago
parent 550643281e
commit a847da5339

@ -43,11 +43,14 @@ char* Server::recvAll() {
if (this->ip_ver == 4) {
/* FOR IPv4 */
struct sockaddr_in* temp_struct = (struct sockaddr_in*)this->dest;
/* Convert the s_addr field of the caseted struct to host network-byte, and convert it to a dotted decimal */
/* Convert the s_addr field of the casted struct to host network-byte, and convert it to a dotted decimal */
peer_addr = connect_code::dec_to_dotted_dec(std::to_string(htonl(temp_struct->sin_addr.s_addr)));
} else {
/* FOR IPv6 */
peer_addr = "IPV6 NOT SUPPORTED YET";
/* FOR IPv6 - Use the inet_ntop function, and convert the struct's address into a string */
struct sockaddr_in6* temp_struct = (struct sockaddr_in6*)this->dest;
char* temp_buf = (char *)malloc(sizeof(char) * (INET6_ADDRSTRLEN + 1));
peer_addr = std::string(inet_ntop(AF_INET6, temp_struct->sin6_addr.s6_addr, temp_buf, INET6_ADDRSTRLEN));
free(temp_buf);
}
return to_return;
@ -83,7 +86,7 @@ is thrown as an exception. */
void Server::wait_for_peer() {
if (this->protocol == ES_TCP) {
this->other_socket = accept(this->sock_fd, dest, &addrlen);
this->other_socket = accept(this->sock_fd, (struct sockaddr *)dest, &addrlen);
if (this->other_socket < 0) {
throw errno;
}

Loading…
Cancel
Save