Wed Oct 28 11:51:05 2009

Asterisk developer's documentation


network.h

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 2007, Digium, Inc.
00005  *
00006  * Luigi Rizzo
00007  *
00008  * See http://www.asterisk.org for more information about
00009  * the Asterisk project. Please do not directly contact
00010  * any of the maintainers of this project for assistance;
00011  * the project provides a web site, mailing lists and IRC
00012  * channels for your use.
00013  *
00014  * This program is free software, distributed under the terms of
00015  * the GNU General Public License Version 2. See the LICENSE file
00016  * at the top of the source tree.
00017  */
00018 
00019 /*! \file
00020  * \brief Wrapper for network related headers,
00021  * masking differences between various operating systems.
00022  * On passing, we also provide here trivial functions or
00023  * other simple wrappers to network-related functions.
00024  */
00025 
00026 #ifndef _ASTERISK_NETWORK_H
00027 #define _ASTERISK_NETWORK_H
00028 
00029 #if defined(__cplusplus) || defined(c_plusplus)
00030 extern "C" {
00031 #endif
00032 
00033 /*
00034  * Include relevant network headers.
00035  * Our preferred choice are the standard BSD/linux/unix headers.
00036  * Missing them (e.g. for solaris or various windows environments),
00037  * we resort to whatever we find around, and provide local definitions
00038  * for the missing bits.
00039  */
00040 #ifdef HAVE_ARPA_INET_H
00041 #include <netinet/in.h>
00042 #include <arpa/inet.h>     /* include early to override inet_ntoa */
00043 #include <netinet/in_systm.h>
00044 #include <netinet/ip.h>
00045 #include <netinet/tcp.h>
00046 #include <netdb.h>
00047 #include <sys/socket.h>
00048 #include <net/if.h>
00049 #include <sys/ioctl.h>
00050 #elif defined(HAVE_WINSOCK_H)
00051 #include <winsock.h>
00052 typedef int socklen_t;
00053 #elif defined(HAVE_WINSOCK2_H)
00054 #include <winsock2.h>
00055 #include <ws2tcpip.h>
00056 #else
00057 #error "don't know how to handle network functions here."
00058 #endif
00059 
00060 #ifndef HAVE_INET_ATON
00061 int inet_aton(const char *cp, struct in_addr *pin);
00062 #endif
00063 
00064 #ifndef IFNAMSIZ
00065 #define  IFNAMSIZ 16
00066 #endif
00067 
00068 #ifndef MAXHOSTNAMELEN
00069 #define  MAXHOSTNAMELEN 256
00070 #endif
00071 
00072 /*!
00073  * \brief thread-safe replacement for inet_ntoa().
00074  *
00075  * \note It is very important to note that even though this is a thread-safe
00076  *       replacement for inet_ntoa(), it is *not* reentrant.  In a single
00077  *       thread, the result from a previous call to this function is no longer
00078  *       valid once it is called again.  If the result from multiple calls to
00079  *       this function need to be kept or used at once, then the result must be
00080  *       copied to a local buffer before calling this function again.
00081  */
00082 const char *ast_inet_ntoa(struct in_addr ia);
00083 
00084 #ifdef inet_ntoa
00085 #undef inet_ntoa
00086 #endif
00087 #define inet_ntoa __dont__use__inet_ntoa__use__ast_inet_ntoa__instead__
00088 
00089 /*! \brief Compares the source address and port of two sockaddr_in */
00090 static force_inline int inaddrcmp(const struct sockaddr_in *sin1, const struct sockaddr_in *sin2)
00091 {
00092         return ((sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
00093                 || (sin1->sin_port != sin2->sin_port));
00094 }
00095 
00096 #if defined(__cplusplus) || defined(c_plusplus)
00097 }
00098 #endif
00099 
00100 #endif /* _ASTERISK_NETWORK_H */

Generated on Wed Oct 28 11:51:05 2009 for Asterisk - the Open Source PBX by  doxygen 1.5.6