Ip2long function in rust

Hello,

I’m creating a program to know some information of ip and I need to use the function ip2long available in php and javascript but not in rust. I don’t know how to reproduce this function in rust. I’ve tried to make this function in rust but I’m not very good.

PHP function : https://www.php.net/manual/en/function.ip2long.php
Javascript function : https://raw.githubusercontent.com/kvz/locutus/master/src/php/network/ip2long.js

From std documentation (https://doc.rust-lang.org/std/net/struct.Ipv4Addr.html):

playground

?

1 Like

I’ve see Ipv4Addr documentation but I did not know u32::from(addr) exist. This code work very well. Thanks you !