Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::net::{TcpListener, TcpStream};
- use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
- fn handle_client(stream: TcpStream) {
- match stream.peer_addr().unwrap().ip(){
- IpAddr::V4(ip4) => println!("ipv4: {}", ip4),
- IpAddr::V6(ip6) => println!("ipv6: {}", ip6),
- }
- }
- fn main(){
- let listener = TcpListener::bind("127.0.0.1:8080").unwrap();
- for stream in listener.incoming() {
- handle_client(stream.unwrap());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement