Skip to content

Get local IP address #179

@showier-drastic

Description

@showier-drastic

My application listens on 0.0.0.0:80 and 0.0.0.0:443. My server has multiple network cards with different IP addresses. I need to get my local interface IP address where the client is connecting to. In raw axum::serve I can use the following:

#[derive(Clone, Debug)]
pub struct LocalSocketInfo {
    pub local_addr: IpAddr,
}

impl Connected<IncomingStream<'_, TcpListener>> for LocalSocketInfo {
    fn connect_info(target: IncomingStream<'_, TcpListener>) -> Self {
        LocalSocketInfo {
            local_addr: target.io().local_addr().unwrap().ip(),
        }
    }
}

However when using axum-server and openssl, it is impossible to get this information.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions