Asterisk - The Open Source Telephony Project GIT-master-f36a736
network.h
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 2007, Digium, Inc.
5 *
6 * Luigi Rizzo
7 *
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
13 *
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
17 */
18
19/*! \file
20 * \brief Wrapper for network related headers,
21 * masking differences between various operating systems.
22 * On passing, we also provide here trivial functions or
23 * other simple wrappers to network-related functions.
24 */
25
26#ifndef _ASTERISK_NETWORK_H
27#define _ASTERISK_NETWORK_H
28
29#if defined(__cplusplus) || defined(c_plusplus)
30extern "C" {
31#endif
32
33/*
34 * Include relevant network headers.
35 * Our preferred choice are the standard BSD/linux/unix headers.
36 * Missing them (e.g. for solaris or various windows environments),
37 * we resort to whatever we find around, and provide local definitions
38 * for the missing bits.
39 */
40#ifdef HAVE_ARPA_INET_H
41#include <netinet/in.h>
42#include <arpa/inet.h> /* include early to override inet_ntoa */
43#include <netinet/in_systm.h>
44#include <netinet/ip.h>
45#include <netinet/tcp.h>
46#include <netdb.h>
47#include <sys/socket.h>
48#include <net/if.h>
49#include <sys/ioctl.h>
50#elif defined(HAVE_WINSOCK_H)
51#include <winsock.h>
52typedef int socklen_t;
53#elif defined(HAVE_WINSOCK2_H)
54#include <winsock2.h>
55#include <ws2tcpip.h>
56#else
57#error "don't know how to handle network functions here."
58#endif
59
60#ifndef HAVE_INET_ATON
61int inet_aton(const char *cp, struct in_addr *pin);
62#endif
63
64#ifndef IFNAMSIZ
65#define IFNAMSIZ 16
66#endif
67
68#ifndef MAXHOSTNAMELEN
69#define MAXHOSTNAMELEN 256
70#endif
71
72/*!
73 * \brief thread-safe replacement for inet_ntoa().
74 *
75 * \note It is very important to note that even though this is a thread-safe
76 * replacement for inet_ntoa(), it is *not* reentrant. In a single
77 * thread, the result from a previous call to this function is no longer
78 * valid once it is called again. If the result from multiple calls to
79 * this function need to be kept or used at once, then the result must be
80 * copied to a local buffer before calling this function again.
81 */
82const char *ast_inet_ntoa(struct in_addr ia);
83
84#ifdef inet_ntoa
85#undef inet_ntoa
86#endif
87#define inet_ntoa __dont__use__inet_ntoa__use__ast_inet_ntoa__instead__
88
89#ifdef getprotobyname
90#undef getprotobyname
91#endif
92#define getprotobyname __getprotobyname_is_not_threadsafe__do_not_use__
93
94/*! \brief Compares the source address and port of two sockaddr_in */
95static force_inline int inaddrcmp(const struct sockaddr_in *sin1, const struct sockaddr_in *sin2)
96{
97 return ((sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
98 || (sin1->sin_port != sin2->sin_port));
99}
100
101#if defined(__cplusplus) || defined(c_plusplus)
102}
103#endif
104
105#endif /* _ASTERISK_NETWORK_H */
#define force_inline
Definition: compiler.h:29
static force_inline int inaddrcmp(const struct sockaddr_in *sin1, const struct sockaddr_in *sin2)
Compares the source address and port of two sockaddr_in.
Definition: network.h:95
int inet_aton(const char *cp, struct in_addr *pin)
const char * ast_inet_ntoa(struct in_addr ia)
thread-safe replacement for inet_ntoa().
Definition: utils.c:928