Advertisement
Guest User

Untitled

a guest
Jan 10th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.46 KB | None | 0 0
  1. use std::net::{TcpListener, TcpStream};
  2. use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
  3.  
  4. fn handle_client(stream: TcpStream) {
  5.     match stream.peer_addr().unwrap().ip(){
  6.         IpAddr::V4(ip4) =>  println!("ipv4: {}", ip4),
  7.         IpAddr::V6(ip6) => println!("ipv6: {}", ip6),
  8.     }
  9. }
  10.  
  11. fn main(){
  12.     let listener = TcpListener::bind("127.0.0.1:8080").unwrap();
  13.  
  14.     for stream in listener.incoming() {
  15.         handle_client(stream.unwrap());
  16.     }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement