---
name: "ping_host_add"
section: "3"
platform: "linux"
package: "liboping-dev"
version: "1.10.0-5+b5"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/ping_host_add"
---

# ping\_host\_add(3)

Add a host to a liboping object

## NAME

ping\_host\_add - Add a host to a liboping object

## SYNOPSIS

```
  #include <oping.h>
  int ping_host_add    (pingobj_t *obj, const char *host);
  int ping_host_remove (pingobj_t *obj, const char *host);
```

## DESCRIPTION

The **ping\_host\_add** method tries to resolve the *host* argument, open a socket and associate everything with the liboping object *obj*.

The *obj* argument is a pointer to an liboping object, as returned by [**ping\_construct**(3)](/ping_construct/3.md).

The *host* parameter is a '\\0' terminated string which is interpreted as a hostname or an IP address. Depending on the address family setting, set with [**ping\_setopt**(3)](/ping_setopt/3.md), the hostname is resolved to an IPv4 or IPv6 address.

The **ping\_host\_remove** method looks for *host* within *obj* and remove it if found. It will close the socket and deallocate the memory, too.

The names passed to **ping\_host\_add** and **ping\_host\_remove** must match. This name can be queried using [**ping\_iterator\_get\_info**(3)](/ping_iterator_get_info/3.md).

## RETURN VALUE

If **ping\_host\_add** succeeds it returns zero. If an error occurs a value less than zero is returned and the last error is saved internally. You can receive the error message using [**ping\_get\_error**(3)](/ping_get_error/3.md).

**ping\_host\_remove** returns zero upon success and less than zero if it failed. Currently the only reason for failure is that the host isn't found, but this is subject to change. Use [**ping\_get\_error**(3)](/ping_get_error/3.md) to receive the error message.

## SEE ALSO

[**ping\_construct**(3)](/ping_construct/3.md), [**ping\_setopt**(3)](/ping_setopt/3.md), [**ping\_get\_error**(3)](/ping_get_error/3.md), [**liboping**(3)](/liboping/3.md)

## AUTHOR

liboping is written by Florian "octo" Forster \<ff at octo.it\>. Its homepage can be found at \<http://noping.cc/\>.

Copyright (c) 2006-2017 by Florian "octo" Forster.
