| Line No. | Rev | Author | Line | 
|---|---|---|---|
| 1 | 32 | kaklik | /********************************************************************* | 
| 2 |  * | ||
| 3 |  *      Berekely Socket Distribution API Header File | ||
| 4 |  * | ||
| 5 |  ********************************************************************* | ||
| 6 |  * FileName:        BerkeleyAPI.h | ||
| 7 |  * Description:     Berkeley socket Distribution(BSD) APIs for Microchip TCPIP Stack | ||
| 8 |  * Processor:       PIC18, PIC24F, PIC24H, dsPIC30F, dsPIC33F, PIC32 | ||
| 9 |  * Compiler:        Microchip C32 v1.05 or higher | ||
| 10 |  *					Microchip C30 v3.12 or higher | ||
| 11 |  *					Microchip C18 v3.30 or higher | ||
| 12 |  *					HI-TECH PICC-18 PRO 9.63PL2 or higher | ||
| 13 |  * Company:         Microchip Technology, Inc. | ||
| 14 |  * | ||
| 15 |  * Software License Agreement | ||
| 16 |  * | ||
| 17 |  * Copyright (C) 2002-2009 Microchip Technology Inc.  All rights | ||
| 18 |  * reserved. | ||
| 19 |  * | ||
| 20 |  * Microchip licenses to you the right to use, modify, copy, and | ||
| 21 |  * distribute: | ||
| 22 |  * (i)  the Software when embedded on a Microchip microcontroller or | ||
| 23 |  *      digital signal controller product ("Device") which is | ||
| 24 |  *      integrated into Licensee's product; or | ||
| 25 |  * (ii) ONLY the Software driver source files ENC28J60.c, ENC28J60.h, | ||
| 26 |  *		ENCX24J600.c and ENCX24J600.h ported to a non-Microchip device | ||
| 27 |  *		used in conjunction with a Microchip ethernet controller for | ||
| 28 |  *		the sole purpose of interfacing with the ethernet controller. | ||
| 29 |  * | ||
| 30 |  * You should refer to the license agreement accompanying this | ||
| 31 |  * Software for additional information regarding your rights and | ||
| 32 |  * obligations. | ||
| 33 |  * | ||
| 34 |  * THE SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT | ||
| 35 |  * WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT | ||
| 36 |  * LIMITATION, ANY WARRANTY OF MERCHANTABILITY, FITNESS FOR A | ||
| 37 |  * PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL | ||
| 38 |  * MICROCHIP BE LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT OR | ||
| 39 |  * CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF | ||
| 40 |  * PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR SERVICES, ANY CLAIMS | ||
| 41 |  * BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE | ||
| 42 |  * THEREOF), ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION, OR OTHER | ||
| 43 |  * SIMILAR COSTS, WHETHER ASSERTED ON THE BASIS OF CONTRACT, TORT | ||
| 44 |  * (INCLUDING NEGLIGENCE), BREACH OF WARRANTY, OR OTHERWISE. | ||
| 45 |  * | ||
| 46 |  * Author               Date    	Comment | ||
| 47 |  *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 48 |  * Aseem Swalah         4/3/08  	Original | ||
| 49 |  ********************************************************************/ | ||
| 50 | |||
| 51 | #ifndef _BERKELEY_API_HEADER_FILE | ||
| 52 | #define _BERKELEY_API_HEADER_FILE | ||
| 53 | |||
| 54 | typedef BYTE SOCKET;   //Socket descriptor | ||
| 55 | |||
| 56 | #define AF_INET         2			// Internet Address Family - UDP, TCP, etc. | ||
| 57 | |||
| 58 | #define IP_ADDR_ANY     0u			// IP Address for server binding | ||
| 59 | #define INADDR_ANY      0x00000000u	// IP address for server binding. | ||
| 60 | |||
| 61 | |||
| 62 | #define SOCK_STREAM 100  //Connection based byte streams. Use TCP for the internet address family. | ||
| 63 | #define SOCK_DGRAM  110  //Connectionless datagram socket. Use UDP for the internet address family. | ||
| 64 | |||
| 65 | #define IPPROTO_TCP     6   // Indicates TCP for the internet address family. | ||
| 66 | #define IPPROTO_UDP     17  // Indicates UDP for the internet address family. | ||
| 67 | |||
| 68 | #define SOCKET_ERROR            (-1) //Socket error | ||
| 69 | #define SOCKET_CNXN_IN_PROGRESS (-2) //Socket connection state. | ||
| 70 | #define SOCKET_DISCONNECTED     (-3) //Socket disconnected | ||
| 71 | |||
| 72 | typedef enum | ||
| 73 | { | ||
| 74 |     SKT_CLOSED,   			// Socket closed state indicating a free descriptor | ||
| 75 |     SKT_CREATED, 			// Socket created state for TCP and UDP sockets | ||
| 76 |     SKT_BOUND,   			// Socket bound state for TCP and UDP sockets | ||
| 77 |     SKT_BSD_LISTEN,			// Listening state for TCP BSD listener handle "socket" | ||
| 78 |     SKT_LISTEN,  			// TCP server listen state | ||
| 79 |     SKT_IN_PROGRESS, 		// TCP client connection in progress state | ||
| 80 |     SKT_EST,  				// TCP client or server established state | ||
| 81 |     SKT_DISCONNECTED		// TCP client or server no longer connected to the remote host (but was historically) | ||
| 82 | } BSD_SCK_STATE; // Berkeley Socket (BSD) states | ||
| 83 | |||
| 84 | struct BSDSocket | ||
| 85 | { | ||
| 86 |     int            SocketType; // Socket type | ||
| 87 |     BSD_SCK_STATE  bsdState; //Socket state | ||
| 88 |     WORD           localPort; //local port | ||
| 89 |     WORD           remotePort; //remote port | ||
| 90 |     DWORD          remoteIP; //remote IP | ||
| 91 |     int            backlog; // maximum number or client connection | ||
| 92 |     BOOL           isServer; // server/client check | ||
| 93 |     TCP_SOCKET     SocketID; // Socket ID | ||
| 94 | }; // Berkeley Socket structure | ||
| 95 | |||
| 96 | #define INVALID_TCP_PORT   (0L)  //Invalide TCP port | ||
| 97 | |||
| 98 | struct in_addr | ||
| 99 | { | ||
| 100 |     union | ||
| 101 |    { | ||
| 102 |        struct { BYTE s_b1,s_b2,s_b3,s_b4; } S_un_b; // IP address in Byte | ||
| 103 |        struct { WORD s_w1,s_w2; } S_un_w; //IP address in Word | ||
| 104 |        DWORD S_addr; //IP address | ||
| 105 |    }S_un; //union of IP address | ||
| 106 | |||
| 107 | #define s_addr  S_un.S_addr //can be used for most tcp & ip code | ||
| 108 | #define s_host  S_un.S_un_b.s_b2 //host on imp | ||
| 109 | #define s_net   S_un.S_un_b.s_b1 // network | ||
| 110 | #define s_imp   S_un.S_un_w.s_w2 // imp | ||
| 111 | #define s_impno S_un.S_un_b.s_b4 // imp number | ||
| 112 | #define s_lh    S_un.S_un_b.s_b3 // logical host | ||
| 113 | }; // in_addr structure | ||
| 114 | |||
| 115 | struct __attribute__((__packed__)) sockaddr | ||
| 116 | { | ||
| 117 |     unsigned short   sa_family;   //address family | ||
| 118 |     char    sa_data[14];       //up to 14 bytes of direct address | ||
| 119 | }; //generic address structure for all address families | ||
| 120 | |||
| 121 | struct __attribute__((__packed__)) sockaddr_in | ||
| 122 | { | ||
| 123 |     short   sin_family; //Address family; must be AF_INET. | ||
| 124 |     WORD    sin_port;  //Internet Protocol (IP) port. | ||
| 125 |     struct  in_addr sin_addr; //IP address in network byte order. | ||
| 126 |     char    sin_zero[8];  //Padding to make structure the same size as SOCKADDR.  | ||
| 127 | }; //In the Internet address family | ||
| 128 | |||
| 129 | typedef struct sockaddr_in SOCKADDR_IN; //In the Internet address family | ||
| 130 | typedef struct sockaddr SOCKADDR;  // generic address structure for all address families | ||
| 131 | |||
| 132 | void BerkeleySocketInit(void); | ||
| 133 | SOCKET socket( int af, int type, int protocol ); | ||
| 134 | int bind( SOCKET s, const struct sockaddr* name, int namelen ); | ||
| 135 | int listen( SOCKET s, int backlog ); | ||
| 136 | SOCKET accept( SOCKET s, struct sockaddr* addr, int* addrlen ); | ||
| 137 | int connect( SOCKET s, struct sockaddr* name, int namelen ); | ||
| 138 | int send( SOCKET s, const char* buf, int len, int flags ); | ||
| 139 | int sendto( SOCKET s, const char* buf, int len, int flags, const struct sockaddr* to, int tolen ); | ||
| 140 | int recv( SOCKET s, char* buf, int len, int flags ); | ||
| 141 | int recvfrom( SOCKET s, char* buf, int len, int flags, struct sockaddr* from, int* fromlen ); | ||
| 142 | int gethostname(char* name, int namelen); | ||
| 143 | int closesocket( SOCKET s ); | ||
| 144 | |||
| 145 | #endif | ||
| 146 | 
Powered by WebSVN v2.8.3