File: getifaddr.h

package info (click to toggle)
miniupnpd 2.3.9-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,040 kB
  • sloc: ansic: 28,571; sh: 2,024; makefile: 164
file content (78 lines) | stat: -rw-r--r-- 2,433 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* $Id: getifaddr.h,v 1.13 2025/04/08 21:28:42 nanard Exp $ */
/* vim: tabstop=4 shiftwidth=4 noexpandtab
 * MiniUPnP project
 * http://miniupnp.free.fr/ or https://miniupnp.tuxfamily.org/
 * (c) 2006-2025 Thomas Bernard
 * This software is subject to the conditions detailed
 * in the LICENCE file provided within the distribution */

#ifndef GETIFADDR_H_INCLUDED
#define GETIFADDR_H_INCLUDED

/*! \file getifaddr.h
 * \brief get IP address of network interface
 */

#define GETIFADDR_OK 0
/*! \brief bad arguments */
#define GETIFADDR_BAD_ARGS -1
/*! \brief socket() call error */
#define GETIFADDR_SOCKET_ERROR -2
/*! \brief device not configure / no such device */
#define GETIFADDR_DEVICE_NOT_CONFIGURED -3
/*! \brief other error from ioctl() */
#define GETIFADDR_IOCTL_ERROR -4
/*! \brief network interface is down */
#define GETIFADDR_IF_DOWN -5
/*! \brief no IPv4 address for the network interface */
#define GETIFADDR_NO_ADDRESS -6
/*! \brief inet_ntop() call error */
#define GETIFADDR_INET_NTOP_ERROR -7
/*! \brief getifaddrs() call error */
#define GETIFADDR_GETIFADDRS_ERROR -8

struct in_addr;
struct in6_addr;

/*! \brief get IPv4 address
 *
 * write the ip v4 address as text in the buffer
 * \param[in] ifname network interface name
 * \param[out] buf character buffer
 * \param[in] len buf length
 * \param[out] addr ip v4 address
 * \param[out] mask ip v4 mask
 * \return 0 on success, a negative value on failure */
int
getifaddr(const char * ifname, char * buf, int len,
          struct in_addr * addr, struct in_addr * mask);

/*! \brief get IPv4 or IPv6 address
 *
 * Filters out loopback and linklocal addresses
 * \param[in] ifname network interface name
 * \param[in] af `AF_INET` or `AF_INET6`
 * \param[out] addr address
 * \return 0 on success, -1 on failure */
int
getifaddr_in6(const char * ifname, int af, struct in6_addr* addr);

/*! \brief find a non link local IP v6 address for the interface.
 *
 * if ifname is NULL, look for all interfaces
 * \param[in] ifname network interface name
 * \param[out] dst character buffer
 * \param[in] n dst length
 * \return 0 on success, -1 on failure */
int
find_ipv6_addr(const char * ifname,
               char * dst, int n);

/*! \brief check if address is in private / reserved block (e.g. local area network)
 *
 * \param addr IPv4 address
 * \return 1 for private address, 0 for routable address */
int
addr_is_reserved(struct in_addr * addr);

#endif