@@ -449,6 +449,32 @@ fn socket_htonl(host: u32, vm: &VirtualMachine) -> PyResult {
449
449
Ok ( vm. new_int ( host. to_be ( ) ) )
450
450
}
451
451
452
+ fn socket_htons ( host : u16 , vm : & VirtualMachine ) -> PyResult {
453
+ Ok ( vm. new_int ( host. to_be ( ) ) )
454
+ }
455
+
456
+ fn socket_htons ( host : u16 , vm : & VirtualMachine ) -> PyResult {
457
+ Ok ( vm. new_int ( host. to_be ( ) ) )
458
+ }
459
+
460
+ fn socket_ntohl ( network : u32 , vm : & VirtualMachine ) -> PyResult {
461
+ if cfg ! ( target_endian = "big" ) {
462
+ Ok ( vm. new_int ( network) )
463
+ }
464
+ else {
465
+ Ok ( vm. new_int ( network. to_le ( ) ) )
466
+ }
467
+ }
468
+
469
+ fn socket_ntohs ( network : u16 , vm : & VirtualMachine ) -> PyResult {
470
+ if cfg ! ( target_endian = "big" ) {
471
+ Ok ( vm. new_int ( network) )
472
+ }
473
+ else {
474
+ Ok ( vm. new_int ( network. to_le ( ) ) )
475
+ }
476
+ }
477
+
452
478
#[ derive( FromArgs ) ]
453
479
struct GAIOptions {
454
480
#[ pyarg( positional_only) ]
@@ -636,6 +662,9 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
636
662
"inet_ntoa" => ctx. new_rustfunc( socket_inet_ntoa) ,
637
663
"gethostname" => ctx. new_rustfunc( socket_gethostname) ,
638
664
"htonl" => ctx. new_rustfunc( socket_htonl) ,
665
+ "htons" => ctx. new_rustfunc( socket_htons) ,
666
+ "ntohl" => ctx. new_rustfunc( socket_ntohl) ,
667
+ "ntohs" => ctx. new_rustfunc( socket_ntohs) ,
639
668
"getdefaulttimeout" => ctx. new_rustfunc( |vm: & VirtualMachine | vm. get_none( ) ) ,
640
669
"getaddrinfo" => ctx. new_rustfunc( socket_getaddrinfo) ,
641
670
"gethostbyaddr" => ctx. new_rustfunc( socket_gethostbyaddr) ,
0 commit comments