---
name: "hesiod_getservbyname"
section: "3"
platform: "linux"
package: "libhesiod-dev"
version: "3.2.1-5"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/hesiod_getservbyname"
---

# hesiod\_getservbyname(3)

Hesiod functions for retrieving service information

## NAME

hesiod\_getservbyname, hesiod\_free\_servent - Hesiod functions for retrieving service information

## SYNOPSIS

```
#include <hesiod.h>
```

**struct servent \*hesiod\_getservbyname(void \**context*,** **const char \**name*, const char \**proto*)** **void hesiod\_free\_servent(void \**context*, struct servent \**serv*)**

**cc file.c -lhesiod**

## DESCRIPTION

This family of functions allows you to retrieve service to port mappings using Hesiod.  To perform lookups, you need an initialized Hesiod context; see [hesiod(3)](/hesiod/3.md) for details.  Information is returned in the same format as by *getservbyname*. It is the caller's responsibility to call *hesiod\_free\_servent* with the returned service entry to free the resources used by the service entry.

Hesiod queries for service information are made using the \`\`service'' Hesiod type, using the service name as the Hesiod name.  The corresponding records should be space-separated lists of strings giving the service name, protocol, port number (in decimal), and zero or more aliases for the service.  There may be multiple records per service name; *hesiod\_getservbyname* will pick the first one whose protocol matches *proto*.

## RETURN VALUES

On failure, *hesiod\_getservbyname* returns NULL and sets the global variable *errno* to indicate the error.

## ERRORS

*hesiod\_getservbyname* may fail for any of the reasons the routine *hesiod\_resolve* may fail.

## SEE ALSO

[hesiod(3)](/hesiod/3.md)
