Tor 0.4.9.0-alpha-dev
nettypes.h
Go to the documentation of this file.
1/* Copyright (c) 2003-2004, Roger Dingledine
2 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
3 * Copyright (c) 2007-2021, The Tor Project, Inc. */
4/* See LICENSE for licensing information */
5
6/**
7 * \file nettypes.h
8 * \brief Declarations for types used throughout the Tor networking system
9 **/
10
11#ifndef TOR_NET_TYPES_H
12#define TOR_NET_TYPES_H
13
14#include "orconfig.h"
15#ifdef HAVE_SYS_TYPES_H
16#include <sys/types.h>
17#endif
18#ifdef HAVE_SYS_SOCKET_H
19#include <sys/socket.h>
20#endif
21
22#if (SIZEOF_SOCKLEN_T == 0)
23typedef int socklen_t;
24#endif
25
26#ifdef _WIN32
27/* XXX Actually, this should arguably be SOCKET; we use intptr_t here so that
28 * any inadvertent checks for the socket being <= 0 or > 0 will probably
29 * still work. */
30#define tor_socket_t intptr_t
31#define TOR_SOCKET_T_FORMAT "%"PRIuPTR
32#define SOCKET_OK(s) ((SOCKET)(s) != INVALID_SOCKET)
33#define TOR_INVALID_SOCKET INVALID_SOCKET
34#else /* !defined(_WIN32) */
35/** Type used for a network socket. */
36#define tor_socket_t int
37#define TOR_SOCKET_T_FORMAT "%d"
38/** Macro: true iff 's' is a possible value for a valid initialized socket. */
39#define SOCKET_OK(s) ((s) >= 0)
40/** Error/uninitialized value for a tor_socket_t. */
41#define TOR_INVALID_SOCKET (-1)
42#endif /* defined(_WIN32) */
43
44#endif /* !defined(TOR_NET_TYPES_H) */