summaryrefslogtreecommitdiff
path: root/include/wolf/network/network.h
blob: d55ac58927296b60be9e25d835914e97cf82a8b1 (plain)
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
    Copyright (C) 2008 Andreas Baumann <abaumann@yahoo.com>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef WOLF_NETWORK_H
#define WOLF_NETWORK_H

/**
 * @addtogroup wolf_networking support for networking
 * @{
 */

/**
 * @file network.h
 * @brief Portable helper functions for networking
 * @author Andreas Baumann <abaumann@yahoo.com>
 */

#ifdef __cplusplus
extern "C" {
#endif

#include "port/sys.h"

#include "errors.h"

#if defined LINUX
#include <sys/socket.h>		/* for sockaddr_storage */
#include <netinet/in.h>		/* for sockaddr_in */
#else
#if defined OPENBSD
#include <sys/types.h>		/* for u_int8_t, uid_t, etc */ 
#include <sys/socket.h>		/* for sockaddr_storage */
#include <netinet/in.h>		/* for sockaddr_in */
#else
#if defined NETBSD
#include <sys/socket.h>		/* for sockaddr_storage */
#include <netinet/in.h>		/* for sockaddr_in */
#else
#if defined FREEBSD
#include <sys/socket.h>		/* for sockaddr_storage */
#include <netinet/in.h>		/* for sockaddr_in */
#else
#if defined _WIN32
#define WIN32_MEAN_AND_LEAN
#include <windows.h>
#else
#error Check includes first!
#endif /* defined _WIN32 */
#endif /* defined FREEBSD */
#endif /* defined NETBSD */
#endif /* defined OPENBSD */
#endif /* defined LINUX */

/**
 * helper union to avoid anti-aliasing warnings in old network functions like getpeername,
 * used instead of struct sockaddr_storage when declaring socket address variables which need
 * proper alignment
 */
typedef union wolf_network_sockaddr_union_t {
	struct sockaddr_storage  storage;
	struct sockaddr_in       in;
#ifdef HAVE_IPV6
	struct sockaddr_in6      in6;
#endif
	struct sockaddr          addr;
} wolf_network_sockaddr_union_t;

/**
 * Set a file descriptor non-blocking, Unix-specific, and more important, doesn't
 * work on all kind of descriptors!
 */
wolf_error_t wolf_network_set_nonblocking( int fd );

#ifdef __cplusplus
}
#endif

/** @} */ /* @addtogroup wolf_networking */

#endif /* ifndef WOLF_NETWORK_H */