BRL-CAD
Loading...
Searching...
No Matches
bnetwork.h
Go to the documentation of this file.
1/* B N E T W O R K . H
2 * BRL-CAD
3 *
4 * Copyright (c) 2011-2026 United States Government as represented by
5 * the U.S. Army Research Laboratory.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public License
9 * version 2.1 as published by the Free Software Foundation.
10 *
11 * This library is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this file; see the file named COPYING for more
18 * information.
19 */
20/** @addtogroup bu_bnetwork
21 *
22 * @brief
23 * BRL-CAD system compatibility wrapper header that provides declarations for
24 * native and standard system NETWORKING routines.
25 *
26 * This header is commonly used in lieu of including the following: winsock2.h
27 * (not select, fd_set), netinet/in.h, netinet/tcp.h, arpa/inet.h (htonl,
28 * ntohl, etc)
29 *
30 * The logic in this header should not rely on common.h's HAVE_* defines and
31 * should not be including the common.h header. This is intended to be a
32 * stand-alone portability header intended to be independent of build system,
33 * reusable by external projects.
34 */
35
36/** @{ */
37/** @file bnetwork.h */
38
39#ifndef BNETWORK_H
40#define BNETWORK_H
41
42#if defined(_WIN32) && !defined(__CYGWIN__)
43# ifndef _WINSOCKAPI_
44/* Prevent windows.h (pulled in by winsock2.h) from defining min/max macros,
45 * which would conflict with C++ template min/max */
46# ifndef NOMINMAX
47# define NOMINMAX
48# endif
49# include <winsock2.h> /* link against ws2_32 library */
50# include <ws2tcpip.h> /* provides extensions */
51# undef rad1 /* Win32 radio button 1 */
52# undef rad2 /* Win32 radio button 2 */
53# undef small /* defined as part of the Microsoft Interface Definition Language (MIDL) */
54# endif
55#else
56# include <sys/types.h>
57# include <netinet/in.h> /* sockaddr */
58# include <netinet/tcp.h> /* for TCP_NODELAY sockopt */
59# include <arpa/inet.h> /* hton/ntoh, inet_addr functions */
60# include <sys/socket.h> /* accept, connect, send, recv, ... */
61/* for c90/c99 compatibility */
62# if !defined(HAVE_DECL_HTONL) && !defined(htonl)
65# endif
66#endif
67
68/* INADDR_* constants come from <netinet/in.h> on POSIX and <winsock2.h> on
69 * Windows. Some strict-mode builds or Unity-build ordering issues can leave
70 * them undefined even when the underlying header was nominally processed;
71 * provide safe fallbacks so callers that include bnetwork.h always have them. */
72#ifndef INADDR_ANY
73# define INADDR_ANY ((uint32_t)0x00000000)
74#endif
75#ifndef INADDR_LOOPBACK
76# define INADDR_LOOPBACK ((uint32_t)0x7f000001)
77#endif
78#ifndef INADDR_BROADCAST
79# define INADDR_BROADCAST ((uint32_t)0xffffffff)
80#endif
81
82#endif /* BNETWORK_H */
83
84/** @} */
85
86/*
87 * Local Variables:
88 * tab-width: 8
89 * mode: C
90 * indent-tabs-mode: t
91 * c-file-style: "stroustrup"
92 * End:
93 * ex: shiftwidth=4 tabstop=8
94 */
Definition dvec.h:74
uint32_t ntohl(uint32_t)
uint32_t htonl(uint32_t)