00001 #ifndef _SYS_SOCKET_H_ 00002 00003 /* 00004 * Copyright (C) 2001-2005 by egnite Software GmbH. All rights reserved. 00005 * 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions 00008 * are met: 00009 * 00010 * 1. Redistributions of source code must retain the above copyright 00011 * notice, this list of conditions and the following disclaimer. 00012 * 2. Redistributions in binary form must reproduce the above copyright 00013 * notice, this list of conditions and the following disclaimer in the 00014 * documentation and/or other materials provided with the distribution. 00015 * 3. Neither the name of the copyright holders nor the names of 00016 * contributors may be used to endorse or promote products derived 00017 * from this software without specific prior written permission. 00018 * 00019 * THIS SOFTWARE IS PROVIDED BY EGNITE SOFTWARE GMBH AND CONTRIBUTORS 00020 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00021 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00022 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL EGNITE 00023 * SOFTWARE GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00024 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00025 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 00026 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 00027 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00028 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 00029 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00030 * SUCH DAMAGE. 00031 * 00032 * For additional information see http://www.ethernut.de/ 00033 * 00034 * - 00035 * Portions Copyright (c) 1983, 1993 by 00036 * The Regents of the University of California. All rights reserved. 00037 * 00038 * Redistribution and use in source and binary forms, with or without 00039 * modification, are permitted provided that the following conditions 00040 * are met: 00041 * 1. Redistributions of source code must retain the above copyright 00042 * notice, this list of conditions and the following disclaimer. 00043 * 2. Redistributions in binary form must reproduce the above copyright 00044 * notice, this list of conditions and the following disclaimer in the 00045 * documentation and/or other materials provided with the distribution. 00046 * 3. Neither the name of the University nor the names of its contributors 00047 * may be used to endorse or promote products derived from this software 00048 * without specific prior written permission. 00049 * 00050 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 00051 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00052 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00053 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 00054 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00055 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00056 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00057 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00058 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00059 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00060 * SUCH DAMAGE. 00061 */ 00062 00063 /* 00064 * $Log: socket.h,v $ 00065 * Revision 1.8 2005/07/26 15:49:59 haraldkipp 00066 * Cygwin support added. 00067 * 00068 * Revision 1.7 2005/04/08 10:01:21 freckle 00069 * removed #defines from unix emulation as provided by system headers 00070 * 00071 * Revision 1.6 2005/04/04 19:33:54 freckle 00072 * added creation of include/netdb_orig.h, include/sys/socket_orig.h and 00073 * include/netinet/in_orig.h to allow unix emulation to use tcp/ip sockets 00074 * 00075 * Revision 1.5 2004/07/30 19:54:46 drsung 00076 * Some code of TCP stack redesigned. Round trip time calculation is now 00077 * supported. Fixed several bugs in TCP state machine. Now TCP connections 00078 * should be more reliable under heavy traffic or poor physical connections. 00079 * 00080 * Revision 1.4 2004/03/16 16:48:44 haraldkipp 00081 * Added Jan Dubiec's H8/300 port. 00082 * 00083 * Revision 1.3 2004/02/02 19:03:09 drsung 00084 * Some more ICMP support added. 00085 * 00086 * Revision 1.2 2003/11/24 21:00:21 drsung 00087 * Packet queue added for UDP sockets. 00088 * 00089 * Revision 1.1.1.1 2003/05/09 14:41:21 haraldkipp 00090 * Initial using 3.2.1 00091 * 00092 * Revision 1.7 2003/02/04 18:00:53 harald 00093 * Version 3 released 00094 * 00095 * Revision 1.6 2002/09/15 16:46:57 harald 00096 * Error prototype added 00097 * 00098 * Revision 1.5 2002/06/26 17:29:29 harald 00099 * First pre-release with 2.4 stack 00100 * 00101 */ 00102 00103 00104 00105 #if defined(__linux__) || defined(__APPLE__) || defined(__CYGWIN__) 00106 00107 /* use native version on unix emulation */ 00108 #include <sys/socket_orig.h> 00109 00110 #else /* embedded systems */ 00111 00116 /* 00117 * Types 00118 */ 00119 #define SOCK_STREAM 1 00120 #define SOCK_DGRAM 2 00121 #define SOCK_RAW 3 00123 /* 00124 * Option flags per-socket. 00125 */ 00126 #define SO_DEBUG 0x0001 00127 #define SO_ACCEPTCONN 0x0002 00128 #define SO_REUSEADDR 0x0004 00129 #define SO_KEEPALIVE 0x0008 00130 #define SO_DONTROUTE 0x0010 00131 #define SO_BROADCAST 0x0020 00132 #define SO_USELOOPBACK 0x0040 00133 #define SO_LINGER 0x0080 00134 #define SO_OOBINLINE 0x0100 00135 #define SO_REUSEPORT 0x0200 00137 /* 00138 * Additional options, not kept in so_options. 00139 */ 00140 #define SO_SNDBUF 0x1001 00141 #define SO_RCVBUF 0x1002 00142 #define SO_SNDLOWAT 0x1003 00143 #define SO_RCVLOWAT 0x1004 00144 #define SO_SNDTIMEO 0x1005 00145 #define SO_RCVTIMEO 0x1006 00146 #define SO_ERROR 0x1007 00147 #define SO_TYPE 0x1008 00149 /* 00150 * Address families. 00151 */ 00152 #define AF_INET 2 00154 #endif /* unix / embedded */ 00155 00156 00157 /* assure _SYS_SOCKET_H_ is set */ 00158 #undef _SYS_SOCKET_H_ 00159 #define _SYS_SOCKET_H_ 00160 00161 #include <sys/sock_var.h> 00162 00168 #ifdef __cplusplus 00169 extern "C" { 00170 #endif 00171 00172 extern TCPSOCKET *NutTcpCreateSocket(void); 00173 extern int NutTcpSetSockOpt(TCPSOCKET *sock, int optname, CONST void *optval, int optlen); 00174 extern int NutTcpGetSockOpt(TCPSOCKET *sock, int optname, void *optval, int optlen); 00175 extern int NutTcpConnect(TCPSOCKET *sock, u_long addr, u_short port); 00176 extern int NutTcpAccept(TCPSOCKET *sock, u_short port); 00177 extern void NutTcpInput(NETBUF *nb); 00178 extern int NutTcpSend(TCPSOCKET *sock, CONST void *data, u_short len); 00179 #ifdef __HARVARD_ARCH__ 00180 extern int NutTcpSend_P(TCPSOCKET *sock, PGM_P data, u_short len); 00181 #endif 00182 extern int NutTcpCloseSocket(TCPSOCKET *sock); 00183 extern void NutTcpDestroySocket(TCPSOCKET *sock); 00184 extern int NutTcpReceive(TCPSOCKET *sock, void *data, u_short size); 00185 extern TCPSOCKET *NutTcpFindSocket(u_short lport, u_short rport, u_long raddr); 00186 extern int NutTcpError(TCPSOCKET *sock); 00187 extern int NutTcpAbortSocket(TCPSOCKET *sock, u_short last_error); 00188 extern void NutTcpDiscardBuffers(TCPSOCKET * sock); 00189 00190 extern int NutTcpDeviceRead(TCPSOCKET *sock, void *buffer, int size); 00191 extern int NutTcpDeviceWrite(TCPSOCKET *sock, CONST void *buffer, int size); 00192 #ifdef __HARVARD_ARCH__ 00193 extern int NutTcpDeviceWrite_P(TCPSOCKET *sock, PGM_P buffer, int size); 00194 #endif 00195 extern int NutTcpDeviceIOCtl(TCPSOCKET *sock, int cmd, void *param); 00196 extern int NutTcpDeviceClose(TCPSOCKET *sock); 00197 00198 extern UDPSOCKET *NutUdpCreateSocket(u_short port); 00199 extern int NutUdpSendTo(UDPSOCKET *sock, u_long addr, u_short port, void *data, u_short len); 00200 extern int NutUdpReceiveFrom(UDPSOCKET *sock, u_long *addr, u_short *port, void *data, u_short size, u_long timeout); 00201 extern int NutUdpDestroySocket(UDPSOCKET *sock); 00202 extern UDPSOCKET *NutUdpFindSocket(u_short port); 00203 extern int NutUdpSetSockOpt(UDPSOCKET *sock, int optname, CONST void *optval, int optlen); 00204 extern int NutUdpGetSockOpt(UDPSOCKET *sock, int optname, void *optval, int optlen); 00205 00206 00207 #ifdef __cplusplus 00208 } 00209 #endif 00210 00211 #endif