---
name: "nutscan_add_ip_range"
section: "3"
platform: "linux"
package: "nut"
version: "2.8.5-2"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/nutscan_add_ip_range"
---

# nutscan\_add\_ip\_range(3)

Add an entry with IP address range (starting and ending addresses) to a \`nutscan\_ip\_range\_list\_t\` structure.

## NAME

nutscan\_add\_ip\_range - Add an entry with IP address range (starting and ending addresses) to a \`nutscan\_ip\_range\_list\_t\` structure.

## SYNOPSIS

```
        #include <nut-scan.h>
        /* One IP address range: */
        typedef struct nutscan_ip_range_s {
                char * start_ip;
                char * end_ip;
                struct nutscan_ip_range_s * next;
        } nutscan_ip_range_t;
        /* List of IP address ranges and helper data: */
        typedef struct nutscan_ip_range_list_s {
                nutscan_ip_range_t * ip_ranges;         /* Actual linked list of entries, first entry */
                nutscan_ip_range_t * ip_ranges_last;    /* Pointer to end of list for quicker additions */
                size_t ip_ranges_count;                 /* Counter of added entries */
        } nutscan_ip_range_list_t;
        size_t nutscan_add_ip_range(
                nutscan_ip_range_list_t *irl,
                char * start_ip,
                char * end_ip);
```

## DESCRIPTION

The **nutscan\_add\_ip\_range()** function can create and add a nutscan\_ip\_range\_t entry based on provided inputs to the specified nutscan\_ip\_range\_list\_t structure. The resulting amount of entries in the structure is returned, or 0 in case of non-fatal errors.

This function skips work if:

• the structure pointer is NULL (*0* is returned);

• neither start\_ip nor end\_ip were provided, i.e. they both have NULL values (current list length from the structure is returned);

• failed to allocate the entry (fatal).

If only one of start\_ip or end\_ip values was provided (not NULL), a single-address range is created with both addresses set to the same pointer value.

The structure should be initialized before use by nutscan\_init\_ip\_ranges().

The caller must free the contents of the structure after completing its use by calling nutscan\_free\_ip\_ranges() (after which the structure can be re-used for a new list), and explicitly free() the structure object itself if it was allocated dynamically (e.g. by calling nutscan\_init\_ip\_ranges(NULL)).

## NOTES

Technically, the function is currently defined in *nutscan-ip.h* file.

Currently there are no checks for duplicate or overlapping entries, so the same IP addresses and whole IP address ranges can be added to the list (and would eventually be scanned) many times.

## SEE ALSO

[**nutscan\_init\_ip\_ranges**(3)](/nutscan_init_ip_ranges/3.md), [**nutscan\_free\_ip\_ranges**(3)](/nutscan_free_ip_ranges/3.md), [**nutscan\_stringify\_ip\_ranges**(3)](/nutscan_stringify_ip_ranges/3.md), [**nutscan\_cidr\_to\_ip**(3)](/nutscan_cidr_to_ip/3.md), [**nutscan\_ip\_ranges\_iter\_init**(3)](/nutscan_ip_ranges_iter_init/3.md), [**nutscan\_ip\_ranges\_iter\_inc**(3)](/nutscan_ip_ranges_iter_inc/3.md)
