Commit efbd4eee authored by Manuel Schölling's avatar Manuel Schölling
Browse files

Fix portability issue and typo

parent 8a0e9d6c
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@ os:
env:
  global:
  - secure: J4i75AV4KMrU/UQrLIzzIh35Xix40Ki0uWjm8j05oxlXVl5aPU2zB30AemDne2QXYzkN4kRG/iRnNORE/8D0lF7YipQNSNxgfiBVoOEfj/NSogvI2BftYX9vlLZJUvt+s/nbE3xa/Pyge1IPv7itDYGO7SMe8RTSqitgqyfE2Eg=
  - FEATURES="tlsv1_1 tlsv1_2 dtlsv1 dtlsv1_2 aes_xts npn"
  - FEATURES="tlsv1_1 tlsv1_2 dtlsv1 aes_xts npn"
before_script:
  - ./openssl/tests/test.sh &
script:
+63 −17
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@ use libc::types::os::common::bsd44::sockaddr_in;
use libc::types::os::common::bsd44::sockaddr_in6;
use libc::types::os::common::bsd44::in_addr;
use libc::types::os::common::bsd44::in6_addr;
use libc::types::os::common::bsd44::sa_family_t;
use libc::types::os::common::posix01::timeval;
use libc::funcs::bsd43::setsockopt;
use libc::consts::os::bsd44::SOL_SOCKET;
@@ -53,6 +54,62 @@ enum SockaddrIn {
	V6(sockaddr_in6),
}

#[cfg(any(target_os = "linux", target_os = "android", target_os = "nacl",
	target_os = "windows"))]
fn new_sockaddr_in() -> sockaddr_in {
	sockaddr_in {
		sin_family: AF_INET as sa_family_t,
		sin_port:   9,
		sin_zero:   [0; 8],
		sin_addr:   in_addr {
			s_addr: 0
		}
	}
}

#[cfg(not(any(target_os = "linux", target_os = "android", target_os = "nacl",
	target_os = "windows")))]
fn new_sockaddr_in() -> sockaddr_in {
	sockaddr_in {
		sin_len:    0,
		sin_family: AF_INET as sa_family_t,
		sin_port:   0,
		sin_zero:   [0; 8],
		sin_addr:   in_addr {
			s_addr: 0
		}
	}
}

#[cfg(any(target_os = "linux", target_os = "android", target_os = "nacl",
	target_os = "windows"))]
fn new_sockaddr_in6() -> sockaddr_in6 {
	sockaddr_in6 {
		sin6_family:   AF_INET6 as sa_family_t,
		sin6_port:     0,
		sin6_flowinfo: 0,
		sin6_scope_id: 0,
		sin6_addr:   in6_addr {
			s6_addr: [0; 8],
		}
	}
}

#[cfg(not(any(target_os = "linux", target_os = "android", target_os = "nacl",
	target_os = "windows")))]
fn new_sockaddr_in6() -> sockaddr_in6 {
	sockaddr_in6 {
		sin6_family:   AF_INET6 as sa_family_t,
		sin6_port:     0,
		sin6_flowinfo: 0,
		sin6_scope_id: 0,
		sin6_addr:   in6_addr {
			s6_addr: [0; 8],
		}
	}
}


trait IntoSockaddrIn {
	fn into_sockaddr_in(self) -> Result<SockaddrIn, Error>;
}
@@ -63,14 +120,9 @@ impl IntoSockaddrIn for SocketAddr {

		match self.ip() {
			IpAddr::V4(_) => {
				let mut addr = sockaddr_in {
					sin_zero:   [0; 8],
					sin_family: AF_INET as u16,
					sin_port:   Int::to_be(self.port()),
					sin_addr:   in_addr {
						s_addr: 0
					}
				};
				let mut addr = new_sockaddr_in();
				addr.sin_port = Int::to_be(self.port());

				let cstr = CString::new(ip.clone()).unwrap();
				let res = unsafe {
					inet_pton(addr.sin_family as c_int,
@@ -87,15 +139,9 @@ impl IntoSockaddrIn for SocketAddr {
			},

			IpAddr::V6(_) => {
				let mut addr = sockaddr_in6 {
					sin6_family:   AF_INET6 as u16,
					sin6_port:     Int::to_be(self.port()),
					sin6_flowinfo: 0,
					sin6_scope_id: 0,
					sin6_addr:   in6_addr {
						s6_addr: [0; 8],
					}
				};
				let mut addr = new_sockaddr_in6();
				addr.sin6_port = Int::to_be(self.port());

				let cstr = CString::new(ip.clone()).unwrap();
				let res = unsafe {
					inet_pton(addr.sin6_family as c_int,
+1 −1
Original line number Diff line number Diff line
@@ -132,7 +132,7 @@ impl SslMethod {

    #[cfg(feature = "dtlsv1_2")]
    pub fn is_dtlsv1_2(&self) -> bool {
        *self == SslMethod::Dtlsv1
        *self == SslMethod::Dtlsv1_2
    }

    pub fn is_dtls(&self) -> bool {
+4 −5
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ use std::net::UdpSocket;

const PROTOCOL:SslMethod = Sslv23;

#[cfg(test)]
mod udp {
    static mut udp_port:u16 = 15410;

@@ -57,10 +58,8 @@ macro_rules! run_test(
            use std::path::Path;
            use std::net::UdpSocket;
            use std::net::TcpStream;
            use ssl::SslMethod::Sslv23;
            use ssl;
            #[cfg(feature="dtlsv1")]
            use ssl::SslMethod::Dtlsv1;
            use ssl::SslMethod;
            use ssl::{SslContext, SslStream, VerifyCallback};
            use ssl::connected_socket::Connect;
            use ssl::SslVerifyMode::SSL_VERIFY_PEER;
@@ -72,7 +71,7 @@ macro_rules! run_test(
            #[test]
            fn sslv23() {
                let stream = TcpStream::connect("127.0.0.1:15418").unwrap();
                $blk(Sslv23, stream);
                $blk(SslMethod::Sslv23, stream);
            }
            
            #[test]
@@ -81,7 +80,7 @@ macro_rules! run_test(
                let sock = UdpSocket::bind("127.0.0.1:0").unwrap();
                let stream = sock.connect(udp::next_server().as_slice()).unwrap();

                $blk(Dtlsv1, stream);
                $blk(SslMethod::Dtlsv1, stream);
            }
        }
    );