@@ -658,6 +658,24 @@ fn socket_getprotobyname(name: PyStringRef, vm: &VirtualMachine) -> PyResult {
658
658
Ok ( vm. ctx . new_int ( num) )
659
659
}
660
660
661
+ fn socket_getnameinfo (
662
+ address : Address ,
663
+ flags : i32 ,
664
+ vm : & VirtualMachine ,
665
+ ) -> PyResult < ( String , String ) > {
666
+ let addr = get_addr ( vm, address) ?;
667
+ let nameinfo = addr
668
+ . as_std ( )
669
+ . and_then ( |addr| dns_lookup:: getnameinfo ( & addr, flags) . ok ( ) ) ;
670
+ nameinfo. ok_or_else ( || {
671
+ let error_type = vm. class ( "_socket" , "gaierror" ) ;
672
+ vm. new_exception_msg (
673
+ error_type,
674
+ "nodename nor servname provided, or not known" . to_owned ( ) ,
675
+ )
676
+ } )
677
+ }
678
+
661
679
fn get_addr < T , I > ( vm : & VirtualMachine , addr : T ) -> PyResult < socket2:: SockAddr >
662
680
where
663
681
T : ToSocketAddrs < Iter = I > ,
@@ -773,6 +791,7 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
773
791
"inet_pton" => ctx. new_function( socket_inet_pton) ,
774
792
"inet_ntop" => ctx. new_function( socket_inet_ntop) ,
775
793
"getprotobyname" => ctx. new_function( socket_getprotobyname) ,
794
+ "getnameinfo" => ctx. new_function( socket_getnameinfo) ,
776
795
// constants
777
796
"AF_UNSPEC" => ctx. new_int( 0 ) ,
778
797
"AF_INET" => ctx. new_int( c:: AF_INET ) ,
@@ -797,6 +816,10 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
797
816
"TCP_NODELAY" => ctx. new_int( c:: TCP_NODELAY ) ,
798
817
"AI_ALL" => ctx. new_int( c:: AI_ALL ) ,
799
818
"AI_PASSIVE" => ctx. new_int( c:: AI_PASSIVE ) ,
819
+ "NI_NAMEREQD" => ctx. new_int( c:: NI_NAMEREQD ) ,
820
+ "NI_NOFQDN" => ctx. new_int( c:: NI_NOFQDN ) ,
821
+ "NI_NUMERICHOST" => ctx. new_int( c:: NI_NUMERICHOST ) ,
822
+ "NI_NUMERICSERV" => ctx. new_int( c:: NI_NUMERICSERV ) ,
800
823
} ) ;
801
824
802
825
#[ cfg( not( target_os = "redox" ) ) ]
0 commit comments