Add method to return whether or not a socket is connected to a remote
address
This commit is contained in:
		
							
								
								
									
										7
									
								
								sock.cpp
									
									
									
									
									
								
							
							
						
						
									
										7
									
								
								sock.cpp
									
									
									
									
									
								
							| @@ -37,6 +37,13 @@ Sock::Sock(char protocol, const char* address, int port) { | ||||
| 	this->address = std::string(address); | ||||
| } | ||||
|  | ||||
| /* This method returns whether or not the socket is connected to a remote address */ | ||||
| bool Sock::get_remote_address() { | ||||
|     struct sockaddr_storage addr; | ||||
|     socklen_t len = sizeof(addr); | ||||
|     return getpeername(this->sock_fd, (struct sockaddr*)&addr, &len) == 0; | ||||
| } | ||||
|  | ||||
| /* This method sends the given data, through the  'other_sockt' variable.. Client | ||||
| and server classes extend this method, by setting this variable to different values. | ||||
| This function needs more testing for TCP, as it focuses on UDP right now. */ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user