|
|
@ -43,11 +43,14 @@ char* Server::recvAll() {
|
|
|
|
if (this->ip_ver == 4) {
|
|
|
|
if (this->ip_ver == 4) {
|
|
|
|
/* FOR IPv4 */
|
|
|
|
/* FOR IPv4 */
|
|
|
|
struct sockaddr_in* temp_struct = (struct sockaddr_in*)this->dest;
|
|
|
|
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)));
|
|
|
|
peer_addr = connect_code::dec_to_dotted_dec(std::to_string(htonl(temp_struct->sin_addr.s_addr)));
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
/* FOR IPv6 */
|
|
|
|
/* FOR IPv6 - Use the inet_ntop function, and convert the struct's address into a string */
|
|
|
|
peer_addr = "IPV6 NOT SUPPORTED YET";
|
|
|
|
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;
|
|
|
|
return to_return;
|
|
|
@ -83,7 +86,7 @@ is thrown as an exception. */
|
|
|
|
|
|
|
|
|
|
|
|
void Server::wait_for_peer() {
|
|
|
|
void Server::wait_for_peer() {
|
|
|
|
if (this->protocol == ES_TCP) {
|
|
|
|
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) {
|
|
|
|
if (this->other_socket < 0) {
|
|
|
|
throw errno;
|
|
|
|
throw errno;
|
|
|
|
}
|
|
|
|
}
|
|
|
|