# NetAddress
<span class="source-link">[[Source]](src/net/net_address.md#L1)</span>

Represents an IPv4 or IPv6 address. The family field indicates the address
type. The addr field is either the IPv4 address or the IPv6 flow info. The
addr1-4 fields are the IPv6 address, or invalid for an IPv4 address. The
scope field is the IPv6 scope, or invalid for an IPv4 address.

This class is modelled after the C data structure for holding socket
addresses for both IPv4 and IPv6 `sockaddr_storage`.

Use the `name` method to obtain address/hostname and port/service as Strings.


```pony
class val NetAddress is
  Equatable[NetAddress val] ref
```

#### Implements

* [Equatable](builtin-Equatable)\[[NetAddress](net-NetAddress) val\] ref

---

## Constructors

### create
<span class="source-link">[[Source]](src/net/net_address.md#L1)</span>


```pony
new iso create()
: NetAddress iso^
```

#### Returns

* [NetAddress](net-NetAddress) iso^

---

## Public fields

### let length: [U8](builtin-U8) val
<span class="source-link">[[Source]](src/net/net_address.md#L13)</span>



---

### let family: [U8](builtin-U8) val
<span class="source-link">[[Source]](src/net/net_address.md#L14)</span>



---

### let port: [U16](builtin-U16) val
<span class="source-link">[[Source]](src/net/net_address.md#L15)</span>

Port number in network byte order.

In order to obtain a host byte order port, use:

```pony
let host_order_port: U16 = @ntohs[U16](net_address.port)
```




---

### let addr: [U32](builtin-U32) val
<span class="source-link">[[Source]](src/net/net_address.md#L25)</span>

IPv4 address in network byte order.
Will be `0` for IPv6 addresses. Check with `ipv4()` and `ipv6()`.

Use `@ntohl[U32](net_address.addr)` to obtain it in the host byte order.




---

### let addr1: [U32](builtin-U32) val
<span class="source-link">[[Source]](src/net/net_address.md#L33)</span>

Bits 0-32 of the IPv6 address in network byte order.

`0` if this is an IPv4 address. Check with `ipv4()` and `ipv6()`.




---

### let addr2: [U32](builtin-U32) val
<span class="source-link">[[Source]](src/net/net_address.md#L40)</span>

Bits 33-64 of the IPv6 address in network byte order.

`0` if this is an IPv4 address. Check with `ipv4()` and `ipv6()`.




---

### let addr3: [U32](builtin-U32) val
<span class="source-link">[[Source]](src/net/net_address.md#L46)</span>

Bits 65-96 of the IPv6 address in network byte order.

`0` if this is an IPv4 address. Check with `ipv4()` and `ipv6()`.




---

### let addr4: [U32](builtin-U32) val
<span class="source-link">[[Source]](src/net/net_address.md#L52)</span>

Bits 97-128 of the IPv6 address in network byte order.

`0` if this is an IPv4 address. Check with `ipv4()` and `ipv6()`.




---

### let scope: [U32](builtin-U32) val
<span class="source-link">[[Source]](src/net/net_address.md#L59)</span>

IPv6 scope identifier: Unicast, Anycast, Multicast and unassigned scopes.



---

## Public Functions

### ip4
<span class="source-link">[[Source]](src/net/net_address.md#L62)</span>


Returns true for an IPv4 address.


```pony
fun box ip4()
: Bool val
```

#### Returns

* [Bool](builtin-Bool) val

---

### ip6
<span class="source-link">[[Source]](src/net/net_address.md#L68)</span>


Returns true for an IPv6 address.


```pony
fun box ip6()
: Bool val
```

#### Returns

* [Bool](builtin-Bool) val

---

### name
<span class="source-link">[[Source]](src/net/net_address.md#L74)</span>


Returns the host and service name.

If `reversedns` is an instance of `DNSLookupAuth`
a DNS lookup will be executed and the hostname
for this address is returned as first element of the result tuple.
If no hostname could be found, an error is raised.
If `reversedns` is `None` the plain IP address is given
and no DNS lookup is executed.

If `servicename` is `false` the numeric port is returned
as second element of the result tuple.
If it is `true` the port is translated into its
corresponding servicename (e.g. port 80 is returned as `"http"`).

Internally this method uses the POSIX C function `getnameinfo`.


```pony
fun box name(
  reversedns: (AmbientAuth val | NetAuth val | DNSAuth val | 
    None val) = seq,
  servicename: Bool val = seq)
: (String val , String val) ?
```
#### Parameters

*   reversedns: ([AmbientAuth](builtin-AmbientAuth) val | [NetAuth](net-NetAuth) val | [DNSAuth](net-DNSAuth) val | 
    [None](builtin-None) val) = seq
*   servicename: [Bool](builtin-Bool) val = seq

#### Returns

* ([String](builtin-String) val , [String](builtin-String) val) ?

---

### eq
<span class="source-link">[[Source]](src/net/net_address.md#L110)</span>


```pony
fun box eq(
  that: NetAddress box)
: Bool val
```
#### Parameters

*   that: [NetAddress](net-NetAddress) box

#### Returns

* [Bool](builtin-Bool) val

---

### host_eq
<span class="source-link">[[Source]](src/net/net_address.md#L117)</span>


```pony
fun box host_eq(
  that: NetAddress box)
: Bool val
```
#### Parameters

*   that: [NetAddress](net-NetAddress) box

#### Returns

* [Bool](builtin-Bool) val

---

### ne
<span class="source-link">[[Source]](src/builtin/compare.md#L20)</span>


```pony
fun box ne(
  that: NetAddress val)
: Bool val
```
#### Parameters

*   that: [NetAddress](net-NetAddress) val

#### Returns

* [Bool](builtin-Bool) val

---

