Commit 38da5552 authored by Jeremy Soller's avatar Jeremy Soller

getaddrinfo: support for setting port from service argument (numeric only)

parent d2502056
Pipeline #2801 passed with stages
in 12 minutes and 17 seconds
......@@ -686,8 +686,18 @@ pub unsafe extern "C" fn getaddrinfo(
*res = ptr::null_mut();
let mut port = 0;
if let Some(service) = service_opt {
//TODO: Support other service definitions as well as AI_NUMERICSERV
match str::from_utf8_unchecked(service.to_bytes()).parse::<u16>() {
Ok(ok) => port = ok,
Err(_err) => ()
}
}
//TODO: Check hosts file
if let Some(node) = node_opt {
//TODO: Support AI_NUMERICHOST
let lookuphost = match lookup_host(str::from_utf8_unchecked(node.to_bytes())) {
Ok(lookuphost) => lookuphost,
Err(e) => {
......@@ -703,7 +713,7 @@ pub unsafe extern "C" fn getaddrinfo(
let ai_addr = Box::into_raw(Box::new(sockaddr_in {
sin_family: AF_INET as sa_family_t,
sin_port: 0,
sin_port: htons(port),
sin_addr: in_addr,
sin_zero: [0; 8]
})) as *mut sockaddr;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment