struct io.SocketAddress_ip4

Overview

This struct holds information about IP4 address in the form suitable for socket communications. More…

import "io_base.jncx"
import "io_SocketAddress.jnc"

struct SocketAddress_ip4 {
    // fields

    io.AddressFamily m_family;
    uint16_t bigendian m_port;
    io.Address_ip4 m_address;
    char _m_padding[];

    // methods

    bool isEqual(io.SocketAddress_ip4 const* address) const;
    bool isMatch(io.SocketAddress_ip4 const* filterAddress) const;
    bool errorcode parse(string_t string);
    string_t getString() const;

    // aliases

    alias toString = getString;
    alias fromString = parse;
};

Detailed Documentation

This struct holds information about IP4 address in the form suitable for socket communications.

On the binary level this structure directly maps to sockaddr_in.

See also:

io.Address_ip4, io.Socket, io.HostNameResolver

Fields

io.AddressFamily m_family

Holds the address family of the socket address; should be set to io.AddressFamily.Ip4.

uint16_t bigendian m_port

Holds the number of TCP or UDP port. There is no need to change the byte order of the port before assignment – this field is already declared as bigendian so all the necessary conversions will happen automatically.

io.Address_ip4 m_address

Holds IP4 address as io.Address_ip4.

char _m_padding[]

Extra padding to ensure binary compatibility wiht sockaddr_in.

Methods

bool isEqual(io.SocketAddress_ip4 const* address) const

Checks two IP4 socket addresses for equality; returns true if addresses are equal and false otherwise.

bool isMatch(io.SocketAddress_ip4 const* filterAddress) const

Checks two IP4 socket addresses for matching. The term matching requires some explanation.

Matching could be described as a non-strict equality check. We may decide to only check port for equality and ignore the address. To do so, set m_address field of filter argument to 0.

Or the other way around – only check address and ignore port – set m_port field of filter argument to 0.

Returns true if addresses match and false otherwise.

bool errorcode parse(string_t string)

Constructs the address from a string representation in string argument.

Returns true if address string was parsed successfully. Otherwise, sets the description of parsing error and returns false [1].

string_t getString() const

Creates and returns a string representation of the address.

Aliases

alias toString = getString

Effectively makes io.SocketAddress_ip4 a stringable class.


Footnotes