@@ -20,7 +20,6 @@ use rt::uv::last_uv_error;
20
20
use vec;
21
21
use str;
22
22
use from_str:: { FromStr } ;
23
- use num;
24
23
25
24
pub enum UvSocketAddr {
26
25
UvIpv4SocketAddr ( * sockaddr_in ) ,
@@ -85,77 +84,10 @@ fn uv_socket_addr_as_socket_addr<T>(addr: UvSocketAddr, f: &fn(SocketAddr) -> T)
85
84
port as u16
86
85
} ;
87
86
let ip_str = str:: from_bytes_slice ( ip_name) . trim_right_chars ( & '\x00' ) ;
88
- let ip = match addr {
89
- UvIpv4SocketAddr ( * ) => {
90
- let ip: ~[ u8 ] =
91
- ip_str. split_iter ( '.' )
92
- . transform ( |s : & str | -> u8 { FromStr :: from_str ( s) . unwrap ( ) } )
93
- . collect ( ) ;
94
- assert_eq ! ( ip. len( ) , 4 ) ;
95
- SocketAddr {
96
- ip : Ipv4Addr ( ip[ 0 ] , ip[ 1 ] , ip[ 2 ] , ip[ 3 ] ) ,
97
- port : ip_port
98
- }
99
- } ,
100
- UvIpv6SocketAddr ( * ) => {
101
- let ip: ~[ u16 ] = {
102
- let expand_shorthand_and_convert = |s : & str | -> ~[ ~[ u16 ] ] {
103
- let convert_each_segment = |s : & str | -> ~[ u16 ] {
104
- let read_hex_segment = |s : & str | -> u16 {
105
- num:: FromStrRadix :: from_str_radix ( s, 16 u) . unwrap ( )
106
- } ;
107
- match s {
108
- "" => ~[ ] ,
109
- // IPv4-Mapped/Compatible IPv6 Address?
110
- s if s. find ( '.' ) . is_some ( ) => {
111
- let i = s. rfind ( ':' ) . unwrap_or_default ( -1 ) ;
112
-
113
- let b = s. slice ( i + 1 , s. len ( ) ) ; // the ipv4 part
114
-
115
- let h = b. split_iter ( '.' )
116
- . transform ( |s : & str | -> u8 { FromStr :: from_str ( s) . unwrap ( ) } )
117
- . transform ( |s : u8 | -> ~str { fmt ! ( "%02x" , s as uint) } )
118
- . collect :: < ~[ ~str ] > ( ) ;
119
-
120
- if i == -1 {
121
- // Ipv4 Compatible Address (::x.x.x.x)
122
- // first 96 bits are zero leaving 32 bits
123
- // for the ipv4 part
124
- // (i.e ::127.0.0.1 == ::7F00:1)
125
- ~[ num:: FromStrRadix :: from_str_radix ( h[ 0 ] + h[ 1 ] , 16 ) . unwrap ( ) ,
126
- num:: FromStrRadix :: from_str_radix ( h[ 2 ] + h[ 3 ] , 16 ) . unwrap ( ) ]
127
- } else {
128
- // Ipv4-Mapped Address (::FFFF:x.x.x.x)
129
- // first 80 bits are zero, followed by all ones
130
- // for the next 16 bits, leaving 32 bits for
131
- // the ipv4 part
132
- // (i.e ::FFFF:127.0.0.1 == ::FFFF:7F00:1)
133
- ~[ 1 ,
134
- num:: FromStrRadix :: from_str_radix ( h[ 0 ] + h[ 1 ] , 16 ) . unwrap ( ) ,
135
- num:: FromStrRadix :: from_str_radix ( h[ 2 ] + h[ 3 ] , 16 ) . unwrap ( ) ]
136
- }
137
- } ,
138
- s => s. split_iter ( ':' ) . transform ( read_hex_segment) . collect ( )
139
- }
140
- } ;
141
- s. split_str_iter ( "::" ) . transform ( convert_each_segment) . collect ( )
142
- } ;
143
- match expand_shorthand_and_convert ( ip_str) {
144
- [ x] => x, // no shorthand found
145
- [ l, r] => l + vec:: from_elem ( 8 - l. len ( ) - r. len ( ) , 0u16 ) + r, // fill the gap
146
- _ => fail ! ( ) , // impossible. only one shorthand allowed.
147
- }
148
- } ;
149
- assert_eq ! ( ip. len( ) , 8 ) ;
150
- SocketAddr {
151
- ip : Ipv6Addr ( ip[ 0 ] , ip[ 1 ] , ip[ 2 ] , ip[ 3 ] , ip[ 4 ] , ip[ 5 ] , ip[ 6 ] , ip[ 7 ] ) ,
152
- port : ip_port
153
- }
154
- } ,
155
- } ;
87
+ let ip_addr = FromStr :: from_str ( ip_str) . unwrap ( ) ;
156
88
157
89
// finally run the closure
158
- f ( ip )
90
+ f ( SocketAddr { ip : ip_addr , port : ip_port } )
159
91
}
160
92
161
93
pub fn uv_socket_addr_to_socket_addr ( addr : UvSocketAddr ) -> SocketAddr {
0 commit comments