| Wireshark 4.7.0 The Wireshark network protocol analyzer

Loading...
Searching...
No Matches
Classes | Functions
inet_cidr.h File Reference
`#include <wireshark.h>`
`#include <wsutil/inet_addr.h>`

Go to the source code of this file.

## Classes
struct | ipv4_addr_and_mask
struct | ipv6_addr_and_prefix

## Functions
WS_DLL_PUBLIC uint32_t | ws_ipv4_get_subnet_mask (const uint32_t mask_length)
| Returns the IPv4 subnet mask of the specified length.
WS_DLL_PUBLIC void | ws_ipv4_addr_and_mask_init (ipv4_addr_and_mask *dst, ws_in4_addr src_addr, unsigned src_bits)
| Initializes an IPv4 address-and-mask structure.
WS_DLL_PUBLIC bool | ws_ipv4_addr_and_mask_contains (const ipv4_addr_and_mask *ipv4, const ws_in4_addr *addr)
| Checks whether an IPv4 address is contained within a subnet.
WS_DLL_PUBLIC bool | ws_ipv6_addr_and_prefix_contains (const ipv6_addr_and_prefix *ipv6, const ws_in6_addr *addr)
| Checks whether an IPv6 address is contained within a subnet.

## Detailed Description

Definitions of IPv4 address-and-mask structure, which is what an FT_IPV4 value is (even if there's no mask in a packet, those values can be compared against an address+mask in a filter expression).

Gilbert Ramirez gram@.nosp@m.alum.nosp@m.ni.ri.nosp@m.ce.e.nosp@m.du

Wireshark - Network traffic analyzer By Gerald Combs geral.nosp@m.d@wi.nosp@m.resha.nosp@m.rk.o.nosp@m.rg Copyright 1998 Gerald Combs

SPDX-License-Identifier: GPL-2.0-or-later

## Function Documentation

## ◆ ws_ipv4_addr_and_mask_contains()

WS_DLL_PUBLIC bool ws_ipv4_addr_and_mask_contains | ( | const ipv4_addr_and_mask * | ipv4,
|  | const ws_in4_addr * | addr
| ) |  |

Checks whether an IPv4 address is contained within a subnet.

Tests whether the given address falls within the subnet defined by the address-mask pair.

Parameters

  ipv4 | Pointer to the address-mask structure representing the subnet.
  addr | Pointer to the IPv4 address to test.

Returns
  true if the address is within the subnet, false otherwise.

## ◆ ws_ipv4_addr_and_mask_init()

WS_DLL_PUBLIC void ws_ipv4_addr_and_mask_init | ( | ipv4_addr_and_mask * | dst,
|  | ws_in4_addr | src_addr,
|  | unsigned | src_bits
| ) |  |

Initializes an IPv4 address-and-mask structure.

Sets up an address-mask pair using the given address and prefix length.

Parameters

  dst | Pointer to the destination structure to initialize.
  src_addr | The IPv4 address to use.
  src_bits | The number of bits in the subnet mask (must be <= 32).

## ◆ ws_ipv4_get_subnet_mask()

WS_DLL_PUBLIC uint32_t ws_ipv4_get_subnet_mask | ( | const uint32_t | mask_length | ) |

Returns the IPv4 subnet mask of the specified length.

Constructs a subnet mask with the given number of leading 1 bits. For example, a mask length of 24 yields 255.255.255.0.

Parameters

  mask_length | The number of bits in the subnet mask (0–32).

Returns
  The subnet mask as a 32-bit unsigned integer in host byte order.

## ◆ ws_ipv6_addr_and_prefix_contains()

WS_DLL_PUBLIC bool ws_ipv6_addr_and_prefix_contains | ( | const ipv6_addr_and_prefix * | ipv6,
|  | const ws_in6_addr * | addr
| ) |  |

Checks whether an IPv6 address is contained within a subnet.

Determines if the specified IPv6 address falls within the subnet defined by the given address and prefix length. This is useful for routing, filtering, and address classification tasks.

Parameters

  ipv6 | Pointer to the IPv6 address-and-prefix structure representing the subnet.
  addr | Pointer to the IPv6 address to test.

Returns
  true if the address is within the subnet, false otherwise.