---
title: "port_gateway_set()"
description: "The port_gateway_set() function sets the default gateway for the local port to the specified address."
url: "https://wasix.org/docs/api-reference/wasix/port_gateway_set/"
markdown: "https://wasix.org/docs/api-reference/wasix/port_gateway_set.md"
---

# `port_gateway_set()`

Adds a default gateway to the port.

## Description

The `port_gateway_set()` function sets the default gateway for the local port to the specified address.

## Syntax

```ebnf
  ;;; Adds a default gateway to the local port
  (@interface func (export "port_gateway_set")
    ;;; Address of the default gateway
    (param $addr (@witx const_pointer $addr))
    (result $error (expected (error $errno)))
  )
```

## Parameters

- `ctx`: A mutable reference to the function environment.
- `ip`: A `WasmPtr` pointing to the memory location where the IP address of the default gateway is stored.

## Return Value

The function returns a `Result` indicating the outcome of the operation. If the operation is successful, `Ok(Errno::Success)` is returned. If an error occurs, an appropriate `WasiError` is returned.

## Notes

- The `port_gateway_set()` function sets the default gateway for the local port, which is the address that is used for routing packets when the destination IP address is outside of the local network.
- The IP address of the default gateway is provided through the `ip` parameter, which should point to a memory location that stores the IP address in the `__wasi_addr_t` format.
- The behavior and limitations of the `port_gateway_set()` function may vary depending on the specific runtime environment and underlying networking implementation. It is important to consult the documentation or specifications of the specific environment to understand its behavior in that context.

---

[Documentation index](https://wasix.org/llms.txt) · [HTML version](https://wasix.org/docs/api-reference/wasix/port_gateway_set/)
