PageRenderTime 50ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/src/Arduino/libraries/CC3000/utility/socket.h

https://github.com/InsideTheBlue/signal-fish
C Header | 691 lines | 139 code | 62 blank | 490 comment | 2 complexity | 4f145795b21c34b33207ba299a2c3cfc MD5 | raw file
Possible License(s): LGPL-3.0
  1. /*****************************************************************************
  2. *
  3. * socket.h - CC3000 Host Driver Implementation.
  4. * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
  5. *
  6. * Adapted for use with the Arduino/AVR by KTOWN (Kevin Townsend)
  7. * & Limor Fried for Adafruit Industries
  8. * This library works with the Adafruit CC3000 breakout
  9. * ----> https://www.adafruit.com/products/1469
  10. * Adafruit invests time and resources providing this open source code,
  11. * please support Adafruit and open-source hardware by purchasing
  12. * products from Adafruit!
  13. *
  14. * Redistribution and use in source and binary forms, with or without
  15. * modification, are permitted provided that the following conditions
  16. * are met:
  17. *
  18. * Redistributions of source code must retain the above copyright
  19. * notice, this list of conditions and the following disclaimer.
  20. *
  21. * Redistributions in binary form must reproduce the above copyright
  22. * notice, this list of conditions and the following disclaimer in the
  23. * documentation and/or other materials provided with the
  24. * distribution.
  25. *
  26. * Neither the name of Texas Instruments Incorporated nor the names of
  27. * its contributors may be used to endorse or promote products derived
  28. * from this software without specific prior written permission.
  29. *
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  33. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  34. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  35. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  36. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  37. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  38. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  39. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  40. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  41. *
  42. *****************************************************************************/
  43. #ifndef __SOCKET_H__
  44. #define __SOCKET_H__
  45. //*****************************************************************************
  46. //
  47. //! \addtogroup socket_api
  48. //! @{
  49. //
  50. //*****************************************************************************
  51. //*****************************************************************************
  52. //
  53. // If building with a C++ compiler, make all of the definitions in this header
  54. // have a C binding.
  55. //
  56. //*****************************************************************************
  57. #ifdef __cplusplus
  58. extern "C" {
  59. #endif
  60. #define HOSTNAME_MAX_LENGTH (230) // 230 bytes + header shouldn't exceed 8 bit value
  61. //--------- Address Families --------
  62. #define AF_INET 2
  63. #define AF_INET6 23
  64. //------------ Socket Types ------------
  65. #define SOCK_STREAM 1
  66. #define SOCK_DGRAM 2
  67. #define SOCK_RAW 3 // Raw sockets allow new IPv4 protocols to be implemented in user space. A raw socket receives or sends the raw datagram not including link level headers
  68. #define SOCK_RDM 4
  69. #define SOCK_SEQPACKET 5
  70. //----------- Socket Protocol ----------
  71. #define IPPROTO_IP 0 // dummy for IP
  72. #define IPPROTO_ICMP 1 // control message protocol
  73. #define IPPROTO_IPV4 IPPROTO_IP // IP inside IP
  74. #define IPPROTO_TCP 6 // tcp
  75. #define IPPROTO_UDP 17 // user datagram protocol
  76. #define IPPROTO_IPV6 41 // IPv6 in IPv6
  77. #define IPPROTO_NONE 59 // No next header
  78. #define IPPROTO_RAW 255 // raw IP packet
  79. #define IPPROTO_MAX 256
  80. //----------- Socket retunr codes -----------
  81. #define SOC_ERROR (-1) // error
  82. #define SOC_IN_PROGRESS (-2) // socket in progress
  83. //----------- Socket Options -----------
  84. #define SOL_SOCKET 0xffff // socket level
  85. #define SOCKOPT_RECV_NONBLOCK 0 // recv non block mode, set SOCK_ON or SOCK_OFF (default block mode)
  86. #define SOCKOPT_RECV_TIMEOUT 1 // optname to configure recv and recvfromtimeout
  87. #define SOCKOPT_ACCEPT_NONBLOCK 2 // accept non block mode, set SOCK_ON or SOCK_OFF (default block mode)
  88. #define SOCK_ON 0 // socket non-blocking mode is enabled
  89. #define SOCK_OFF 1 // socket blocking mode is enabled
  90. #define TCP_NODELAY 0x0001
  91. #define TCP_BSDURGENT 0x7000
  92. #define MAX_PACKET_SIZE 1500
  93. #define MAX_LISTEN_QUEUE 4
  94. #define IOCTL_SOCKET_EVENTMASK
  95. #ifdef ENOBUFS
  96. #undef ENOBUFS
  97. #endif
  98. #define ENOBUFS 55 // No buffer space available
  99. #define __FD_SETSIZE 32
  100. #define ASIC_ADDR_LEN 8
  101. #define NO_QUERY_RECIVED -3
  102. typedef struct _in_addr_t
  103. {
  104. unsigned long s_addr; // load with inet_aton()
  105. } in_addr;
  106. typedef struct _sockaddr_t
  107. {
  108. unsigned short int sa_family;
  109. unsigned char sa_data[14];
  110. } sockaddr;
  111. typedef struct _sockaddr_in_t
  112. {
  113. short sin_family; // e.g. AF_INET
  114. unsigned short sin_port; // e.g. htons(3490)
  115. in_addr sin_addr; // see struct in_addr, below
  116. char sin_zero[8]; // zero this if you want to
  117. } sockaddr_in;
  118. typedef unsigned long socklen_t;
  119. // The fd_set member is required to be an array of longs.
  120. typedef long int __fd_mask;
  121. // It's easier to assume 8-bit bytes than to get CHAR_BIT.
  122. #define __NFDBITS (8 * sizeof (__fd_mask))
  123. #define __FDELT(d) ((d) / __NFDBITS)
  124. #define __FDMASK(d) ((__fd_mask) 1 << ((d) % __NFDBITS))
  125. #ifdef fd_set
  126. #undef fd_set // for compatibility with newlib, which defines fd_set
  127. #endif
  128. // fd_set for select and pselect.
  129. typedef struct
  130. {
  131. __fd_mask fds_bits[__FD_SETSIZE / __NFDBITS];
  132. #define __FDS_BITS(set) ((set)->fds_bits)
  133. } fd_set;
  134. // We don't use `memset' because this would require a prototype and
  135. // the array isn't too big.
  136. #define __FD_ZERO(set) \
  137. do { \
  138. unsigned int __i; \
  139. fd_set *__arr = (set); \
  140. for (__i = 0; __i < sizeof (fd_set) / sizeof (__fd_mask); ++__i) \
  141. __FDS_BITS (__arr)[__i] = 0; \
  142. } while (0)
  143. #define __FD_SET(d, set) (__FDS_BITS (set)[__FDELT (d)] |= __FDMASK (d))
  144. #define __FD_CLR(d, set) (__FDS_BITS (set)[__FDELT (d)] &= ~__FDMASK (d))
  145. #define __FD_ISSET(d, set) (__FDS_BITS (set)[__FDELT (d)] & __FDMASK (d))
  146. // Access macros for 'fd_set'.
  147. #ifdef FD_SET
  148. #undef FD_SET
  149. #endif
  150. #ifdef FD_CLR
  151. #undef FD_CLR
  152. #endif
  153. #ifdef FD_ISSET
  154. #undef FD_ISSET
  155. #endif
  156. #ifdef FD_ZERO
  157. #undef FD_ZERO
  158. #endif
  159. #define FD_SET(fd, fdsetp) __FD_SET (fd, fdsetp)
  160. #define FD_CLR(fd, fdsetp) __FD_CLR (fd, fdsetp)
  161. #define FD_ISSET(fd, fdsetp) __FD_ISSET (fd, fdsetp)
  162. #define FD_ZERO(fdsetp) __FD_ZERO (fdsetp)
  163. //Use in case of Big Endian only
  164. #define htonl(A) ((((unsigned long)(A) & 0xff000000) >> 24) | \
  165. (((unsigned long)(A) & 0x00ff0000) >> 8) | \
  166. (((unsigned long)(A) & 0x0000ff00) << 8) | \
  167. (((unsigned long)(A) & 0x000000ff) << 24))
  168. #define ntohl htonl
  169. //Use in case of Big Endian only
  170. #define htons(A) ((((unsigned long)(A) & 0xff00) >> 8) | \
  171. (((unsigned long)(A) & 0x00ff) << 8))
  172. #define ntohs htons
  173. // mDNS port - 5353 mDNS multicast address - 224.0.0.251
  174. #define SET_mDNS_ADD(sockaddr) sockaddr.sa_data[0] = 0x14; \
  175. sockaddr.sa_data[1] = 0xe9; \
  176. sockaddr.sa_data[2] = 0xe0; \
  177. sockaddr.sa_data[3] = 0x0; \
  178. sockaddr.sa_data[4] = 0x0; \
  179. sockaddr.sa_data[5] = 0xfb;
  180. //*****************************************************************************
  181. //
  182. // Prototypes for the APIs.
  183. //
  184. //*****************************************************************************
  185. //*****************************************************************************
  186. //
  187. //! socket
  188. //!
  189. //! @param domain selects the protocol family which will be used for
  190. //! communication. On this version only AF_INET is supported
  191. //! @param type specifies the communication semantics. On this version
  192. //! only SOCK_STREAM, SOCK_DGRAM, SOCK_RAW are supported
  193. //! @param protocol specifies a particular protocol to be used with the
  194. //! socket IPPROTO_TCP, IPPROTO_UDP or IPPROTO_RAW are
  195. //! supported.
  196. //!
  197. //! @return On success, socket handle that is used for consequent socket
  198. //! operations. On error, -1 is returned.
  199. //!
  200. //! @brief create an endpoint for communication
  201. //! The socket function creates a socket that is bound to a specific
  202. //! transport service provider. This function is called by the
  203. //! application layer to obtain a socket handle.
  204. //
  205. //*****************************************************************************
  206. extern int socket(long domain, long type, long protocol);
  207. //*****************************************************************************
  208. //
  209. //! closesocket
  210. //!
  211. //! @param sd socket handle.
  212. //!
  213. //! @return On success, zero is returned. On error, -1 is returned.
  214. //!
  215. //! @brief The socket function closes a created socket.
  216. //
  217. //*****************************************************************************
  218. extern long closesocket(long sd);
  219. //*****************************************************************************
  220. //
  221. //! accept
  222. //!
  223. //! @param[in] sd socket descriptor (handle)
  224. //! @param[out] addr the argument addr is a pointer to a sockaddr structure
  225. //! This structure is filled in with the address of the
  226. //! peer socket, as known to the communications layer.
  227. //! determined. The exact format of the address returned
  228. //! addr is by the socket's address sockaddr.
  229. //! On this version only AF_INET is supported.
  230. //! This argument returns in network order.
  231. //! @param[out] addrlen the addrlen argument is a value-result argument:
  232. //! it should initially contain the size of the structure
  233. //! pointed to by addr.
  234. //!
  235. //! @return For socket in blocking mode:
  236. //! On success, socket handle. on failure negative
  237. //! For socket in non-blocking mode:
  238. //! - On connection establishment, socket handle
  239. //! - On connection pending, SOC_IN_PROGRESS (-2)
  240. //! - On failure, SOC_ERROR (-1)
  241. //!
  242. //! @brief accept a connection on a socket:
  243. //! This function is used with connection-based socket types
  244. //! (SOCK_STREAM). It extracts the first connection request on the
  245. //! queue of pending connections, creates a new connected socket, and
  246. //! returns a new file descriptor referring to that socket.
  247. //! The newly created socket is not in the listening state.
  248. //! The original socket sd is unaffected by this call.
  249. //! The argument sd is a socket that has been created with socket(),
  250. //! bound to a local address with bind(), and is listening for
  251. //! connections after a listen(). The argument addr is a pointer
  252. //! to a sockaddr structure. This structure is filled in with the
  253. //! address of the peer socket, as known to the communications layer.
  254. //! The exact format of the address returned addr is determined by the
  255. //! socket's address family. The addrlen argument is a value-result
  256. //! argument: it should initially contain the size of the structure
  257. //! pointed to by addr, on return it will contain the actual
  258. //! length (in bytes) of the address returned.
  259. //!
  260. //! @sa socket ; bind ; listen
  261. //
  262. //*****************************************************************************
  263. extern long accept(long sd, sockaddr *addr, socklen_t *addrlen);
  264. //*****************************************************************************
  265. //
  266. //! bind
  267. //!
  268. //! @param[in] sd socket descriptor (handle)
  269. //! @param[out] addr specifies the destination address. On this version
  270. //! only AF_INET is supported.
  271. //! @param[out] addrlen contains the size of the structure pointed to by addr.
  272. //!
  273. //! @return On success, zero is returned. On error, -1 is returned.
  274. //!
  275. //! @brief assign a name to a socket
  276. //! This function gives the socket the local address addr.
  277. //! addr is addrlen bytes long. Traditionally, this is called when a
  278. //! socket is created with socket, it exists in a name space (address
  279. //! family) but has no name assigned.
  280. //! It is necessary to assign a local address before a SOCK_STREAM
  281. //! socket may receive connections.
  282. //!
  283. //! @sa socket ; accept ; listen
  284. //
  285. //*****************************************************************************
  286. extern long bind(long sd, const sockaddr *addr, long addrlen);
  287. //*****************************************************************************
  288. //
  289. //! listen
  290. //!
  291. //! @param[in] sd socket descriptor (handle)
  292. //! @param[in] backlog specifies the listen queue depth. On this version
  293. //! backlog is not supported.
  294. //! @return On success, zero is returned. On error, -1 is returned.
  295. //!
  296. //! @brief listen for connections on a socket
  297. //! The willingness to accept incoming connections and a queue
  298. //! limit for incoming connections are specified with listen(),
  299. //! and then the connections are accepted with accept.
  300. //! The listen() call applies only to sockets of type SOCK_STREAM
  301. //! The backlog parameter defines the maximum length the queue of
  302. //! pending connections may grow to.
  303. //!
  304. //! @sa socket ; accept ; bind
  305. //!
  306. //! @note On this version, backlog is not supported
  307. //
  308. //*****************************************************************************
  309. extern long listen(long sd, long backlog);
  310. //*****************************************************************************
  311. //
  312. //! gethostbyname
  313. //!
  314. //! @param[in] hostname host name
  315. //! @param[in] usNameLen name length
  316. //! @param[out] out_ip_addr This parameter is filled in with host IP address.
  317. //! In case that host name is not resolved,
  318. //! out_ip_addr is zero.
  319. //! @return On success, positive is returned. On error, negative is returned
  320. //!
  321. //! @brief Get host IP by name. Obtain the IP Address of machine on network,
  322. //! by its name.
  323. //!
  324. //! @note On this version, only blocking mode is supported. Also note that
  325. //! the function requires DNS server to be configured prior to its usage.
  326. //
  327. //*****************************************************************************
  328. #ifndef CC3000_TINY_DRIVER
  329. extern int gethostbyname(const char * hostname, uint8_t usNameLen, uint32_t* out_ip_addr);
  330. #endif
  331. //*****************************************************************************
  332. //
  333. //! connect
  334. //!
  335. //! @param[in] sd socket descriptor (handle)
  336. //! @param[in] addr specifies the destination addr. On this version
  337. //! only AF_INET is supported.
  338. //! @param[out] addrlen contains the size of the structure pointed to by addr
  339. //! @return On success, zero is returned. On error, -1 is returned
  340. //!
  341. //! @brief initiate a connection on a socket
  342. //! Function connects the socket referred to by the socket descriptor
  343. //! sd, to the address specified by addr. The addrlen argument
  344. //! specifies the size of addr. The format of the address in addr is
  345. //! determined by the address space of the socket. If it is of type
  346. //! SOCK_DGRAM, this call specifies the peer with which the socket is
  347. //! to be associated; this address is that to which datagrams are to be
  348. //! sent, and the only address from which datagrams are to be received.
  349. //! If the socket is of type SOCK_STREAM, this call attempts to make a
  350. //! connection to another socket. The other socket is specified by
  351. //! address, which is an address in the communications space of the
  352. //! socket. Note that the function implements only blocking behavior
  353. //! thus the caller will be waiting either for the connection
  354. //! establishment or for the connection establishment failure.
  355. //!
  356. //! @sa socket
  357. //
  358. //*****************************************************************************
  359. extern long connect(long sd, const sockaddr *addr, long addrlen);
  360. //*****************************************************************************
  361. //
  362. //! select
  363. //!
  364. //! @param[in] nfds the highest-numbered file descriptor in any of the
  365. //! three sets, plus 1.
  366. //! @param[out] writesds socket descriptors list for write monitoring
  367. //! @param[out] readsds socket descriptors list for read monitoring
  368. //! @param[out] exceptsds socket descriptors list for exception monitoring
  369. //! @param[in] timeout is an upper bound on the amount of time elapsed
  370. //! before select() returns. Null means infinity
  371. //! timeout. The minimum timeout is 5 milliseconds,
  372. //! less than 5 milliseconds will be set
  373. //! automatically to 5 milliseconds.
  374. //! @return On success, select() returns the number of file descriptors
  375. //! contained in the three returned descriptor sets (that is, the
  376. //! total number of bits that are set in readfds, writefds,
  377. //! exceptfds) which may be zero if the timeout expires before
  378. //! anything interesting happens.
  379. //! On error, -1 is returned.
  380. //! *readsds - return the sockets on which Read request will
  381. //! return without delay with valid data.
  382. //! *writesds - return the sockets on which Write request
  383. //! will return without delay.
  384. //! *exceptsds - return the sockets which closed recently.
  385. //!
  386. //! @brief Monitor socket activity
  387. //! Select allow a program to monitor multiple file descriptors,
  388. //! waiting until one or more of the file descriptors become
  389. //! "ready" for some class of I/O operation
  390. //!
  391. //! @Note If the timeout value set to less than 5ms it will automatically set
  392. //! to 5ms to prevent overload of the system
  393. //!
  394. //! @sa socket
  395. //
  396. //*****************************************************************************
  397. extern int select(long nfds, fd_set *readsds, fd_set *writesds,
  398. fd_set *exceptsds, struct timeval *timeout);
  399. //*****************************************************************************
  400. //
  401. //! setsockopt
  402. //!
  403. //! @param[in] sd socket handle
  404. //! @param[in] level defines the protocol level for this option
  405. //! @param[in] optname defines the option name to Interrogate
  406. //! @param[in] optval specifies a value for the option
  407. //! @param[in] optlen specifies the length of the option value
  408. //! @return On success, zero is returned. On error, -1 is returned
  409. //!
  410. //! @brief set socket options
  411. //! This function manipulate the options associated with a socket.
  412. //! Options may exist at multiple protocol levels; they are always
  413. //! present at the uppermost socket level.
  414. //! When manipulating socket options the level at which the option
  415. //! resides and the name of the option must be specified.
  416. //! To manipulate options at the socket level, level is specified as
  417. //! SOL_SOCKET. To manipulate options at any other level the protocol
  418. //! number of the appropriate protocol controlling the option is
  419. //! supplied. For example, to indicate that an option is to be
  420. //! interpreted by the TCP protocol, level should be set to the
  421. //! protocol number of TCP;
  422. //! The parameters optval and optlen are used to access optval -
  423. //! use for setsockopt(). For getsockopt() they identify a buffer
  424. //! in which the value for the requested option(s) are to
  425. //! be returned. For getsockopt(), optlen is a value-result
  426. //! parameter, initially containing the size of the buffer
  427. //! pointed to by option_value, and modified on return to
  428. //! indicate the actual size of the value returned. If no option
  429. //! value is to be supplied or returned, option_value may be NULL.
  430. //!
  431. //! @Note On this version the following two socket options are enabled:
  432. //! The only protocol level supported in this version
  433. //! is SOL_SOCKET (level).
  434. //! 1. SOCKOPT_RECV_TIMEOUT (optname)
  435. //! SOCKOPT_RECV_TIMEOUT configures recv and recvfrom timeout
  436. //! in milliseconds.
  437. //! In that case optval should be pointer to unsigned long.
  438. //! 2. SOCKOPT_NONBLOCK (optname). sets the socket non-blocking mode on
  439. //! or off.
  440. //! In that case optval should be SOCK_ON or SOCK_OFF (optval).
  441. //!
  442. //! @sa getsockopt
  443. //
  444. //*****************************************************************************
  445. #ifndef CC3000_TINY_DRIVER
  446. extern int setsockopt(long sd, long level, long optname, const void *optval,
  447. socklen_t optlen);
  448. #endif
  449. //*****************************************************************************
  450. //
  451. //! getsockopt
  452. //!
  453. //! @param[in] sd socket handle
  454. //! @param[in] level defines the protocol level for this option
  455. //! @param[in] optname defines the option name to Interrogate
  456. //! @param[out] optval specifies a value for the option
  457. //! @param[out] optlen specifies the length of the option value
  458. //! @return On success, zero is returned. On error, -1 is returned
  459. //!
  460. //! @brief set socket options
  461. //! This function manipulate the options associated with a socket.
  462. //! Options may exist at multiple protocol levels; they are always
  463. //! present at the uppermost socket level.
  464. //! When manipulating socket options the level at which the option
  465. //! resides and the name of the option must be specified.
  466. //! To manipulate options at the socket level, level is specified as
  467. //! SOL_SOCKET. To manipulate options at any other level the protocol
  468. //! number of the appropriate protocol controlling the option is
  469. //! supplied. For example, to indicate that an option is to be
  470. //! interpreted by the TCP protocol, level should be set to the
  471. //! protocol number of TCP;
  472. //! The parameters optval and optlen are used to access optval -
  473. //! use for setsockopt(). For getsockopt() they identify a buffer
  474. //! in which the value for the requested option(s) are to
  475. //! be returned. For getsockopt(), optlen is a value-result
  476. //! parameter, initially containing the size of the buffer
  477. //! pointed to by option_value, and modified on return to
  478. //! indicate the actual size of the value returned. If no option
  479. //! value is to be supplied or returned, option_value may be NULL.
  480. //!
  481. //! @Note On this version the following two socket options are enabled:
  482. //! The only protocol level supported in this version
  483. //! is SOL_SOCKET (level).
  484. //! 1. SOCKOPT_RECV_TIMEOUT (optname)
  485. //! SOCKOPT_RECV_TIMEOUT configures recv and recvfrom timeout
  486. //! in milliseconds.
  487. //! In that case optval should be pointer to unsigned long.
  488. //! 2. SOCKOPT_NONBLOCK (optname). sets the socket non-blocking mode on
  489. //! or off.
  490. //! In that case optval should be SOCK_ON or SOCK_OFF (optval).
  491. //!
  492. //! @sa setsockopt
  493. //
  494. //*****************************************************************************
  495. extern int getsockopt(long sd, long level, long optname, void *optval,
  496. socklen_t *optlen);
  497. //*****************************************************************************
  498. //
  499. //! recv
  500. //!
  501. //! @param[in] sd socket handle
  502. //! @param[out] buf Points to the buffer where the message should be stored
  503. //! @param[in] len Specifies the length in bytes of the buffer pointed to
  504. //! by the buffer argument.
  505. //! @param[in] flags Specifies the type of message reception.
  506. //! On this version, this parameter is not supported.
  507. //!
  508. //! @return Return the number of bytes received, or -1 if an error
  509. //! occurred
  510. //!
  511. //! @brief function receives a message from a connection-mode socket
  512. //!
  513. //! @sa recvfrom
  514. //!
  515. //! @Note On this version, only blocking mode is supported.
  516. //
  517. //*****************************************************************************
  518. extern int recv(long sd, void *buf, long len, long flags);
  519. //*****************************************************************************
  520. //
  521. //! recvfrom
  522. //!
  523. //! @param[in] sd socket handle
  524. //! @param[out] buf Points to the buffer where the message should be stored
  525. //! @param[in] len Specifies the length in bytes of the buffer pointed to
  526. //! by the buffer argument.
  527. //! @param[in] flags Specifies the type of message reception.
  528. //! On this version, this parameter is not supported.
  529. //! @param[in] from pointer to an address structure indicating the source
  530. //! address: sockaddr. On this version only AF_INET is
  531. //! supported.
  532. //! @param[in] fromlen source address structure size
  533. //!
  534. //! @return Return the number of bytes received, or -1 if an error
  535. //! occurred
  536. //!
  537. //! @brief read data from socket
  538. //! function receives a message from a connection-mode or
  539. //! connectionless-mode socket. Note that raw sockets are not
  540. //! supported.
  541. //!
  542. //! @sa recv
  543. //!
  544. //! @Note On this version, only blocking mode is supported.
  545. //
  546. //*****************************************************************************
  547. extern int recvfrom(long sd, void *buf, long len, long flags, sockaddr *from,
  548. socklen_t *fromlen);
  549. //*****************************************************************************
  550. //
  551. //! send
  552. //!
  553. //! @param sd socket handle
  554. //! @param buf Points to a buffer containing the message to be sent
  555. //! @param len message size in bytes
  556. //! @param flags On this version, this parameter is not supported
  557. //!
  558. //! @return Return the number of bytes transmitted, or -1 if an
  559. //! error occurred
  560. //!
  561. //! @brief Write data to TCP socket
  562. //! This function is used to transmit a message to another
  563. //! socket.
  564. //!
  565. //! @Note On this version, only blocking mode is supported.
  566. //!
  567. //! @sa sendto
  568. //
  569. //*****************************************************************************
  570. extern int send(long sd, const void *buf, long len, long flags);
  571. //*****************************************************************************
  572. //
  573. //! sendto
  574. //!
  575. //! @param sd socket handle
  576. //! @param buf Points to a buffer containing the message to be sent
  577. //! @param len message size in bytes
  578. //! @param flags On this version, this parameter is not supported
  579. //! @param to pointer to an address structure indicating the destination
  580. //! address: sockaddr. On this version only AF_INET is
  581. //! supported.
  582. //! @param tolen destination address structure size
  583. //!
  584. //! @return Return the number of bytes transmitted, or -1 if an
  585. //! error occurred
  586. //!
  587. //! @brief Write data to TCP socket
  588. //! This function is used to transmit a message to another
  589. //! socket.
  590. //!
  591. //! @Note On this version, only blocking mode is supported.
  592. //!
  593. //! @sa send
  594. //
  595. //*****************************************************************************
  596. extern int sendto(long sd, const void *buf, long len, long flags,
  597. const sockaddr *to, socklen_t tolen);
  598. //*****************************************************************************
  599. //
  600. //! mdnsAdvertiser
  601. //!
  602. //! @param[in] mdnsEnabled flag to enable/disable the mDNS feature
  603. //! @param[in] deviceServiceName Service name as part of the published
  604. //! canonical domain name
  605. //! @param[in] deviceServiceNameLength Length of the service name
  606. //!
  607. //!
  608. //! @return On success, zero is returned, return SOC_ERROR if socket was not
  609. //! opened successfully, or if an error occurred.
  610. //!
  611. //! @brief Set CC3000 in mDNS advertiser mode in order to advertise itself.
  612. //
  613. //*****************************************************************************
  614. extern int mdnsAdvertiser(unsigned short mdnsEnabled, char * deviceServiceName, unsigned short deviceServiceNameLength);
  615. //*****************************************************************************
  616. //
  617. // Close the Doxygen group.
  618. //! @}
  619. //
  620. //*****************************************************************************
  621. //*****************************************************************************
  622. //
  623. // Mark the end of the C bindings section for C++ compilers.
  624. //
  625. //*****************************************************************************
  626. #ifdef __cplusplus
  627. }
  628. #endif // __cplusplus
  629. #endif // __SOCKET_H__