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