@@ -445,8 +445,12 @@ fn socket_inet_ntoa(packed_ip: PyBytesRef, vm: &VirtualMachine) -> PyResult {
445
445
Ok ( vm. new_str ( Ipv4Addr :: from ( ip_num) . to_string ( ) ) )
446
446
}
447
447
448
- fn socket_htonl ( host : u32 , vm : & VirtualMachine ) -> PyResult {
449
- Ok ( vm. new_int ( host. to_be ( ) ) )
448
+ fn socket_hton < U : num_traits:: int:: PrimInt > ( host : U , _vm : & VirtualMachine ) -> U {
449
+ U :: to_be ( host)
450
+ }
451
+
452
+ fn socket_ntoh < U : num_traits:: int:: PrimInt > ( network : U , _vm : & VirtualMachine ) -> U {
453
+ U :: from_be ( network)
450
454
}
451
455
452
456
#[ derive( FromArgs ) ]
@@ -635,7 +639,10 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
635
639
"inet_aton" => ctx. new_rustfunc( socket_inet_aton) ,
636
640
"inet_ntoa" => ctx. new_rustfunc( socket_inet_ntoa) ,
637
641
"gethostname" => ctx. new_rustfunc( socket_gethostname) ,
638
- "htonl" => ctx. new_rustfunc( socket_htonl) ,
642
+ "htonl" => ctx. new_rustfunc( socket_hton:: <u32 >) ,
643
+ "htons" => ctx. new_rustfunc( socket_hton:: <u16 >) ,
644
+ "ntohl" => ctx. new_rustfunc( socket_ntoh:: <u32 >) ,
645
+ "ntohs" => ctx. new_rustfunc( socket_ntoh:: <u16 >) ,
639
646
"getdefaulttimeout" => ctx. new_rustfunc( |vm: & VirtualMachine | vm. get_none( ) ) ,
640
647
"getaddrinfo" => ctx. new_rustfunc( socket_getaddrinfo) ,
641
648
"gethostbyaddr" => ctx. new_rustfunc( socket_gethostbyaddr) ,
0 commit comments