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

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