# sw_ipv4_address

### OVERVIEW

`sw_ipv4_address` is a data type that represents an IP address.

### FUNCTION

## sw_ipv4_address_any

### SYNOPSIS

    sw_ipv4_address
    sw_ipv4_address_any()

### DESCRIPTION

Returns an sw_ipv4_address representing IN_ADDR_ANY (an IP address consisting of all zeros).

### FUNCTION

## sw_ipv4_address_loopback

### SYNOPSIS

    sw_ipv4_address
    sw_ipv4_address_loopback()

### DESCRIPTION

Returns an sw_ipv4_address representing the loopback address: 127.0.0.1.

### FUNCTION

## sw_ipv4_address_init

### SYNOPSIS

    sw_result
    sw_ipv4_address_init(sw_ipv4_address *self)

### DESCRIPTION

Initialize an empty sw_ipv4_address object.

### FUNCTION

## sw_ipv4_address_init_from_saddr

### SYNOPSIS

    sw_result
    sw_ipv4_address_init_from_saddr(
       sw_ipv4_address *self,
       sw_saddr    saddr)

### DESCRIPTION

Creates a new `sw_ipv4_address` at `self`. `saddr` is a ulong representing the IP address in a format such that 0x01020304 would lead to an IP address of 1.2.3.4.

### FUNCTION

## sw_ipv4_address_init_from_name

### SYNOPSIS

    sw_result
    sw_ipv4_address_init_from_name(
       sw_ipv4_address      *self,
       const sw_string  name)

### DESCRIPTION

Creates a new `sw_ipv4_address` at `self`. `name` is a string representing the IP address in "dot" format: for example, "127.0.0.1".

### FUNCTION

## sw_ipv4_address_init_from_address

### SYNOPSIS

    sw_result
    sw_ipv4_address_init_from_address(
       sw_ipv4_address *self,
       sw_ipv4_address  addr)

### DESCRIPTION

Creates a new `sw_ipv4_address` at `self`, which is an exact copy of `addr`.

### FUNCTION

## sw_ipv4_address_init_from_this_host

### SYNOPSIS

    sw_result
    sw_ipv4_address_init_from_this_host(sw_ipv4_address *self)

### DESCRIPTION

Creates a new `sw_ipv4_address` at `self`, containing the IP address of the local host.

If the local host is a multi-address host, the particular IP address is determined randomly.

### FUNCTION

## sw_ipv4_address_fina

### SYNOPSIS

    sw_result
    sw_ipv4_address_fina(sw_ipv4_address self)

### DESCRIPTION

Frees any resources associated with `self`. Equivalent to a destructor in an object-oriented language. After `sw_ipv4_address_fina` has been called, it is safe to free the memory occupied by `self`.

### FUNCTION

## sw_ipv4_address_is_any

### SYNOPSIS

    sw_bool
    sw_ipv4_address_is_any(sw_ipv4_address self)

### DESCRIPTION

Returns true iff `self` represents the IN_ADDR_ANY address (all zeros).

### FUNCTION

## sw_ipv4_address_saddr

### SYNOPSIS

    sw_saddr
    sw_ipv4_address_saddr(sw_ipv4_address self)

### DESCRIPTION

Returns a ulong representing the IP address contained in `self`.

### FUNCTION

## sw_ipv4_address_name

### SYNOPSIS

    sw_string
    sw_ipv4_address_name(
       sw_ipv4_address  self,
       sw_string   name,
       sw_ulong    len)

### DESCRIPTION

Stores at `name` an ASCII representation of the IP address contained in `self`, in "dot" format: "127.0.0.1".

`name` is where to store the string. `len` is the number of bytes available at `name`, including the null terminator.

Returns `name`.

### FUNCTION

## sw_ipv4_address_decompose

### SYNOPSIS

    sw_result
    sw_ipv4_address_decompose(
       sw_ipv4_address  self,
       sw_octet   *a1,
       sw_octet   *a2,
       sw_octet   *a3,
       sw_octet   *a4)

### DESCRIPTION

Stores four bytes representing the IP address contained in `self`.

### FUNCTION

## sw_ipv4_address_equals

### SYNOPSIS

    sw_bool
    sw_ipv4_address_equals(
       sw_ipv4_address  self,
       sw_ipv4_address  addr)

### DESCRIPTION

Returns true iff `self` and `addr` represent the same IP address.