xref: /dragonfly/contrib/libpcap/pcap/socket.h (revision ea16f64e)
1*3a289941SAaron LI /* -*- Mode: c; tab-width: 8; indent-tabs-mode: 1; c-basic-offset: 8; -*- */
2*3a289941SAaron LI /*
3*3a289941SAaron LI  * Copyright (c) 1993, 1994, 1995, 1996, 1997
4*3a289941SAaron LI  *	The Regents of the University of California.  All rights reserved.
5*3a289941SAaron LI  *
6*3a289941SAaron LI  * Redistribution and use in source and binary forms, with or without
7*3a289941SAaron LI  * modification, are permitted provided that the following conditions
8*3a289941SAaron LI  * are met:
9*3a289941SAaron LI  * 1. Redistributions of source code must retain the above copyright
10*3a289941SAaron LI  *    notice, this list of conditions and the following disclaimer.
11*3a289941SAaron LI  * 2. Redistributions in binary form must reproduce the above copyright
12*3a289941SAaron LI  *    notice, this list of conditions and the following disclaimer in the
13*3a289941SAaron LI  *    documentation and/or other materials provided with the distribution.
14*3a289941SAaron LI  * 3. All advertising materials mentioning features or use of this software
15*3a289941SAaron LI  *    must display the following acknowledgement:
16*3a289941SAaron LI  *	This product includes software developed by the Computer Systems
17*3a289941SAaron LI  *	Engineering Group at Lawrence Berkeley Laboratory.
18*3a289941SAaron LI  * 4. Neither the name of the University nor of the Laboratory may be used
19*3a289941SAaron LI  *    to endorse or promote products derived from this software without
20*3a289941SAaron LI  *    specific prior written permission.
21*3a289941SAaron LI  *
22*3a289941SAaron LI  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23*3a289941SAaron LI  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24*3a289941SAaron LI  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25*3a289941SAaron LI  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26*3a289941SAaron LI  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27*3a289941SAaron LI  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28*3a289941SAaron LI  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29*3a289941SAaron LI  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30*3a289941SAaron LI  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31*3a289941SAaron LI  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32*3a289941SAaron LI  * SUCH DAMAGE.
33*3a289941SAaron LI  */
34*3a289941SAaron LI 
35*3a289941SAaron LI #ifndef lib_pcap_socket_h
36*3a289941SAaron LI #define lib_pcap_socket_h
37*3a289941SAaron LI 
38*3a289941SAaron LI /*
39*3a289941SAaron LI  * Some minor differences between sockets on various platforms.
40*3a289941SAaron LI  * We include whatever sockets are needed for Internet-protocol
41*3a289941SAaron LI  * socket access on UN*X and Windows.
42*3a289941SAaron LI  */
43*3a289941SAaron LI #ifdef _WIN32
44*3a289941SAaron LI   /* Need windef.h for defines used in winsock2.h under MingW32 */
45*3a289941SAaron LI   #ifdef __MINGW32__
46*3a289941SAaron LI     #include <windef.h>
47*3a289941SAaron LI   #endif
48*3a289941SAaron LI   #include <winsock2.h>
49*3a289941SAaron LI   #include <ws2tcpip.h>
50*3a289941SAaron LI 
51*3a289941SAaron LI   /*
52*3a289941SAaron LI    * Winsock doesn't have this POSIX type; it's used for the
53*3a289941SAaron LI    * tv_usec value of struct timeval.
54*3a289941SAaron LI    */
55*3a289941SAaron LI   typedef long suseconds_t;
56*3a289941SAaron LI #else /* _WIN32 */
57*3a289941SAaron LI   #include <sys/types.h>
58*3a289941SAaron LI   #include <sys/socket.h>
59*3a289941SAaron LI   #include <netdb.h>		/* for struct addrinfo/getaddrinfo() */
60*3a289941SAaron LI   #include <netinet/in.h>	/* for sockaddr_in, in BSD at least */
61*3a289941SAaron LI   #include <arpa/inet.h>
62*3a289941SAaron LI 
63*3a289941SAaron LI   /*!
64*3a289941SAaron LI    * \brief In Winsock, a socket handle is of type SOCKET; in UN*X, it's
65*3a289941SAaron LI    * a file descriptor, and therefore a signed integer.
66*3a289941SAaron LI    * We define SOCKET to be a signed integer on UN*X, so that it can
67*3a289941SAaron LI    * be used on both platforms.
68*3a289941SAaron LI    */
69*3a289941SAaron LI   #ifndef SOCKET
70*3a289941SAaron LI     #define SOCKET int
71*3a289941SAaron LI   #endif
72*3a289941SAaron LI 
73*3a289941SAaron LI   /*!
74*3a289941SAaron LI    * \brief In Winsock, the error return if socket() fails is INVALID_SOCKET;
75*3a289941SAaron LI    * in UN*X, it's -1.
76*3a289941SAaron LI    * We define INVALID_SOCKET to be -1 on UN*X, so that it can be used on
77*3a289941SAaron LI    * both platforms.
78*3a289941SAaron LI    */
79*3a289941SAaron LI   #ifndef INVALID_SOCKET
80*3a289941SAaron LI     #define INVALID_SOCKET -1
81*3a289941SAaron LI   #endif
82*3a289941SAaron LI #endif /* _WIN32 */
83*3a289941SAaron LI 
84*3a289941SAaron LI #endif /* lib_pcap_socket_h */
85