socket.h

Go to the documentation of this file.
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.11  2008/08/20 06:56:59  haraldkipp
00066  * Implemented IP demultiplexer.
00067  *
00068  * Revision 1.10  2008/08/11 07:00:27  haraldkipp
00069  * BSD types replaced by stdint types (feature request #1282721).
00070  *
00071  * Revision 1.9  2008/04/18 13:32:00  haraldkipp
00072  * Changed size parameter from u_short to int, which is easier to handle
00073  * for 32-bit targets. You need to recompile your ARM code. No impact on
00074  * AVR expected
00075  * I changed u_int to int at some places to avoid some warnings during
00076  * compilation of Nut/Net.
00077  * libs.
00078  *
00079  * Revision 1.8  2005/07/26 15:49:59  haraldkipp
00080  * Cygwin support added.
00081  *
00082  * Revision 1.7  2005/04/08 10:01:21  freckle
00083  * removed #defines from unix emulation as provided by system headers
00084  *
00085  * Revision 1.6  2005/04/04 19:33:54  freckle
00086  * added creation of include/netdb_orig.h, include/sys/socket_orig.h and
00087  * include/netinet/in_orig.h to allow unix emulation to use tcp/ip sockets
00088  *
00089  * Revision 1.5  2004/07/30 19:54:46  drsung
00090  * Some code of TCP stack redesigned. Round trip time calculation is now
00091  * supported. Fixed several bugs in TCP state machine. Now TCP connections
00092  * should be more reliable under heavy traffic or poor physical connections.
00093  *
00094  * Revision 1.4  2004/03/16 16:48:44  haraldkipp
00095  * Added Jan Dubiec's H8/300 port.
00096  *
00097  * Revision 1.3  2004/02/02 19:03:09  drsung
00098  * Some more ICMP support added.
00099  *
00100  * Revision 1.2  2003/11/24 21:00:21  drsung
00101  * Packet queue added for UDP sockets.
00102  *
00103  * Revision 1.1.1.1  2003/05/09 14:41:21  haraldkipp
00104  * Initial using 3.2.1
00105  *
00106  * Revision 1.7  2003/02/04 18:00:53  harald
00107  * Version 3 released
00108  *
00109  * Revision 1.6  2002/09/15 16:46:57  harald
00110  * Error prototype added
00111  *
00112  * Revision 1.5  2002/06/26 17:29:29  harald
00113  * First pre-release with 2.4 stack
00114  *
00115  */
00116 
00117 
00118 
00119 #if defined(__linux__) || defined(__APPLE__) || defined(__CYGWIN__)
00120 
00121 /* use native version on unix emulation */
00122 #include <sys/socket_orig.h>
00123 
00124 #else /* embedded systems */
00125 
00130 /*
00131  * Types
00132  */
00133 #define SOCK_STREAM 1       
00134 #define SOCK_DGRAM  2       
00135 #define SOCK_RAW    3       
00137 /*
00138  * Option flags per-socket.
00139  */
00140 #define SO_DEBUG        0x0001      
00141 #define SO_ACCEPTCONN   0x0002      
00142 #define SO_REUSEADDR    0x0004      
00143 #define SO_KEEPALIVE    0x0008      
00144 #define SO_DONTROUTE    0x0010      
00145 #define SO_BROADCAST    0x0020      
00146 #define SO_USELOOPBACK  0x0040      
00147 #define SO_LINGER       0x0080      
00148 #define SO_OOBINLINE    0x0100      
00149 #define SO_REUSEPORT    0x0200      
00151 /*
00152  * Additional options, not kept in so_options.
00153  */
00154 #define SO_SNDBUF       0x1001      
00155 #define SO_RCVBUF       0x1002      
00156 #define SO_SNDLOWAT     0x1003      
00157 #define SO_RCVLOWAT     0x1004      
00158 #define SO_SNDTIMEO     0x1005      
00159 #define SO_RCVTIMEO     0x1006      
00160 #define SO_ERROR        0x1007      
00161 #define SO_TYPE         0x1008      
00163 /*
00164  * Address families.
00165  */
00166 #define AF_INET     2       
00168 #endif /* unix / embedded */
00169 
00170 
00171 /* assure _SYS_SOCKET_H_ is set */
00172 #undef  _SYS_SOCKET_H_
00173 #define _SYS_SOCKET_H_
00174 
00175 #include <sys/sock_var.h>
00176 
00182 #ifdef __cplusplus
00183 extern "C" {
00184 #endif
00185 
00186 extern TCPSOCKET *NutTcpCreateSocket(void);
00187 extern int NutTcpSetSockOpt(TCPSOCKET *sock, int optname, CONST void *optval, int optlen);
00188 extern int NutTcpGetSockOpt(TCPSOCKET *sock, int optname, void *optval, int optlen);
00189 extern int NutTcpConnect(TCPSOCKET *sock, uint32_t addr, uint16_t port);
00190 extern int NutTcpAccept(TCPSOCKET *sock, uint16_t port);
00191 extern int NutTcpInput(NUTDEVICE * dev, NETBUF *nb);
00192 extern int NutTcpSend(TCPSOCKET *sock, CONST void *data, int len);
00193 #ifdef __HARVARD_ARCH__
00194 extern int NutTcpSend_P(TCPSOCKET *sock, PGM_P data, int len);
00195 #endif
00196 extern int NutTcpCloseSocket(TCPSOCKET *sock);
00197 extern void NutTcpDestroySocket(TCPSOCKET *sock);
00198 extern int NutTcpReceive(TCPSOCKET *sock, void *data, int size);
00199 extern TCPSOCKET *NutTcpFindSocket(uint16_t lport, uint16_t rport, uint32_t raddr);
00200 extern int NutTcpError(TCPSOCKET *sock);
00201 extern int NutTcpAbortSocket(TCPSOCKET *sock, uint16_t last_error);
00202 extern void NutTcpDiscardBuffers(TCPSOCKET * sock);
00203 
00204 extern int NutTcpDeviceRead(TCPSOCKET *sock, void *buffer, int size);
00205 extern int NutTcpDeviceWrite(TCPSOCKET *sock, CONST void *buffer, int size);
00206 #ifdef __HARVARD_ARCH__
00207 extern int NutTcpDeviceWrite_P(TCPSOCKET *sock, PGM_P buffer, int size);
00208 #endif
00209 extern int NutTcpDeviceIOCtl(TCPSOCKET *sock, int cmd, void *param);
00210 extern int NutTcpDeviceClose(TCPSOCKET *sock);
00211 
00212 extern UDPSOCKET *NutUdpCreateSocket(uint16_t port);
00213 extern int NutUdpSendTo(UDPSOCKET *sock, uint32_t addr, uint16_t port, void *data, int len);
00214 extern int NutUdpReceiveFrom(UDPSOCKET *sock, uint32_t *addr, uint16_t *port, void *data, int size, uint32_t timeout);
00215 extern int NutUdpDestroySocket(UDPSOCKET *sock);
00216 extern UDPSOCKET *NutUdpFindSocket(uint16_t port);
00217 extern int NutUdpSetSockOpt(UDPSOCKET *sock, int optname, CONST void *optval, int optlen);
00218 extern int NutUdpGetSockOpt(UDPSOCKET *sock, int optname, void *optval, int optlen);
00219 
00220 
00221 #ifdef __cplusplus
00222 }
00223 #endif
00224 
00225 #endif

© 2000-2007 by egnite Software GmbH - visit http://www.ethernut.de/