PageRenderTime 54ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/utility/socket.h

https://github.com/zrecommerce/Adafruit_CC3000_Library
C Header | 672 lines | 121 code | 61 blank | 490 comment | 2 complexity | 36eee7eaab2c8f378a5533a648b83682 MD5 | raw file
  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. #define ENOBUFS 55 // No buffer space available
  96. #define __FD_SETSIZE 32
  97. #define ASIC_ADDR_LEN 8
  98. #define NO_QUERY_RECIVED -3
  99. typedef struct _in_addr_t
  100. {
  101. unsigned long s_addr; // load with inet_aton()
  102. } in_addr;
  103. typedef struct _sockaddr_t
  104. {
  105. unsigned short int sa_family;
  106. unsigned char sa_data[14];
  107. } sockaddr;
  108. typedef struct _sockaddr_in_t
  109. {
  110. short sin_family; // e.g. AF_INET
  111. unsigned short sin_port; // e.g. htons(3490)
  112. in_addr sin_addr; // see struct in_addr, below
  113. char sin_zero[8]; // zero this if you want to
  114. } sockaddr_in;
  115. typedef unsigned long socklen_t;
  116. // The fd_set member is required to be an array of longs.
  117. typedef long int __fd_mask;
  118. // It's easier to assume 8-bit bytes than to get CHAR_BIT.
  119. #define __NFDBITS (8 * sizeof (__fd_mask))
  120. #define __FDELT(d) ((d) / __NFDBITS)
  121. #define __FDMASK(d) ((__fd_mask) 1 << ((d) % __NFDBITS))
  122. // fd_set for select and pselect.
  123. typedef struct
  124. {
  125. __fd_mask fds_bits[__FD_SETSIZE / __NFDBITS];
  126. #define __FDS_BITS(set) ((set)->fds_bits)
  127. } fd_set;
  128. // We don't use `memset' because this would require a prototype and
  129. // the array isn't too big.
  130. #define __FD_ZERO(set) \
  131. do { \
  132. unsigned int __i; \
  133. fd_set *__arr = (set); \
  134. for (__i = 0; __i < sizeof (fd_set) / sizeof (__fd_mask); ++__i) \
  135. __FDS_BITS (__arr)[__i] = 0; \
  136. } while (0)
  137. #define __FD_SET(d, set) (__FDS_BITS (set)[__FDELT (d)] |= __FDMASK (d))
  138. #define __FD_CLR(d, set) (__FDS_BITS (set)[__FDELT (d)] &= ~__FDMASK (d))
  139. #define __FD_ISSET(d, set) (__FDS_BITS (set)[__FDELT (d)] & __FDMASK (d))
  140. // Access macros for 'fd_set'.
  141. #define FD_SET(fd, fdsetp) __FD_SET (fd, fdsetp)
  142. #define FD_CLR(fd, fdsetp) __FD_CLR (fd, fdsetp)
  143. #define FD_ISSET(fd, fdsetp) __FD_ISSET (fd, fdsetp)
  144. #define FD_ZERO(fdsetp) __FD_ZERO (fdsetp)
  145. //Use in case of Big Endian only
  146. #define htonl(A) ((((unsigned long)(A) & 0xff000000) >> 24) | \
  147. (((unsigned long)(A) & 0x00ff0000) >> 8) | \
  148. (((unsigned long)(A) & 0x0000ff00) << 8) | \
  149. (((unsigned long)(A) & 0x000000ff) << 24))
  150. #define ntohl htonl
  151. //Use in case of Big Endian only
  152. #define htons(A) ((((unsigned long)(A) & 0xff00) >> 8) | \
  153. (((unsigned long)(A) & 0x00ff) << 8))
  154. #define ntohs htons
  155. // mDNS port - 5353 mDNS multicast address - 224.0.0.251
  156. #define SET_mDNS_ADD(sockaddr) sockaddr.sa_data[0] = 0x14; \
  157. sockaddr.sa_data[1] = 0xe9; \
  158. sockaddr.sa_data[2] = 0xe0; \
  159. sockaddr.sa_data[3] = 0x0; \
  160. sockaddr.sa_data[4] = 0x0; \
  161. sockaddr.sa_data[5] = 0xfb;
  162. //*****************************************************************************
  163. //
  164. // Prototypes for the APIs.
  165. //
  166. //*****************************************************************************
  167. //*****************************************************************************
  168. //
  169. //! socket
  170. //!
  171. //! @param domain selects the protocol family which will be used for
  172. //! communication. On this version only AF_INET is supported
  173. //! @param type specifies the communication semantics. On this version
  174. //! only SOCK_STREAM, SOCK_DGRAM, SOCK_RAW are supported
  175. //! @param protocol specifies a particular protocol to be used with the
  176. //! socket IPPROTO_TCP, IPPROTO_UDP or IPPROTO_RAW are
  177. //! supported.
  178. //!
  179. //! @return On success, socket handle that is used for consequent socket
  180. //! operations. On error, -1 is returned.
  181. //!
  182. //! @brief create an endpoint for communication
  183. //! The socket function creates a socket that is bound to a specific
  184. //! transport service provider. This function is called by the
  185. //! application layer to obtain a socket handle.
  186. //
  187. //*****************************************************************************
  188. extern int socket(long domain, long type, long protocol);
  189. //*****************************************************************************
  190. //
  191. //! closesocket
  192. //!
  193. //! @param sd socket handle.
  194. //!
  195. //! @return On success, zero is returned. On error, -1 is returned.
  196. //!
  197. //! @brief The socket function closes a created socket.
  198. //
  199. //*****************************************************************************
  200. extern long closesocket(long sd);
  201. //*****************************************************************************
  202. //
  203. //! accept
  204. //!
  205. //! @param[in] sd socket descriptor (handle)
  206. //! @param[out] addr the argument addr is a pointer to a sockaddr structure
  207. //! This structure is filled in with the address of the
  208. //! peer socket, as known to the communications layer.
  209. //! determined. The exact format of the address returned
  210. //! addr is by the socket's address sockaddr.
  211. //! On this version only AF_INET is supported.
  212. //! This argument returns in network order.
  213. //! @param[out] addrlen the addrlen argument is a value-result argument:
  214. //! it should initially contain the size of the structure
  215. //! pointed to by addr.
  216. //!
  217. //! @return For socket in blocking mode:
  218. //! On success, socket handle. on failure negative
  219. //! For socket in non-blocking mode:
  220. //! - On connection establishment, socket handle
  221. //! - On connection pending, SOC_IN_PROGRESS (-2)
  222. //! - On failure, SOC_ERROR (-1)
  223. //!
  224. //! @brief accept a connection on a socket:
  225. //! This function is used with connection-based socket types
  226. //! (SOCK_STREAM). It extracts the first connection request on the
  227. //! queue of pending connections, creates a new connected socket, and
  228. //! returns a new file descriptor referring to that socket.
  229. //! The newly created socket is not in the listening state.
  230. //! The original socket sd is unaffected by this call.
  231. //! The argument sd is a socket that has been created with socket(),
  232. //! bound to a local address with bind(), and is listening for
  233. //! connections after a listen(). The argument addr is a pointer
  234. //! to a sockaddr structure. This structure is filled in with the
  235. //! address of the peer socket, as known to the communications layer.
  236. //! The exact format of the address returned addr is determined by the
  237. //! socket's address family. The addrlen argument is a value-result
  238. //! argument: it should initially contain the size of the structure
  239. //! pointed to by addr, on return it will contain the actual
  240. //! length (in bytes) of the address returned.
  241. //!
  242. //! @sa socket ; bind ; listen
  243. //
  244. //*****************************************************************************
  245. extern long accept(long sd, sockaddr *addr, socklen_t *addrlen);
  246. //*****************************************************************************
  247. //
  248. //! bind
  249. //!
  250. //! @param[in] sd socket descriptor (handle)
  251. //! @param[out] addr specifies the destination address. On this version
  252. //! only AF_INET is supported.
  253. //! @param[out] addrlen contains the size of the structure pointed to by addr.
  254. //!
  255. //! @return On success, zero is returned. On error, -1 is returned.
  256. //!
  257. //! @brief assign a name to a socket
  258. //! This function gives the socket the local address addr.
  259. //! addr is addrlen bytes long. Traditionally, this is called when a
  260. //! socket is created with socket, it exists in a name space (address
  261. //! family) but has no name assigned.
  262. //! It is necessary to assign a local address before a SOCK_STREAM
  263. //! socket may receive connections.
  264. //!
  265. //! @sa socket ; accept ; listen
  266. //
  267. //*****************************************************************************
  268. extern long bind(long sd, const sockaddr *addr, long addrlen);
  269. //*****************************************************************************
  270. //
  271. //! listen
  272. //!
  273. //! @param[in] sd socket descriptor (handle)
  274. //! @param[in] backlog specifies the listen queue depth. On this version
  275. //! backlog is not supported.
  276. //! @return On success, zero is returned. On error, -1 is returned.
  277. //!
  278. //! @brief listen for connections on a socket
  279. //! The willingness to accept incoming connections and a queue
  280. //! limit for incoming connections are specified with listen(),
  281. //! and then the connections are accepted with accept.
  282. //! The listen() call applies only to sockets of type SOCK_STREAM
  283. //! The backlog parameter defines the maximum length the queue of
  284. //! pending connections may grow to.
  285. //!
  286. //! @sa socket ; accept ; bind
  287. //!
  288. //! @note On this version, backlog is not supported
  289. //
  290. //*****************************************************************************
  291. extern long listen(long sd, long backlog);
  292. //*****************************************************************************
  293. //
  294. //! gethostbyname
  295. //!
  296. //! @param[in] hostname host name
  297. //! @param[in] usNameLen name length
  298. //! @param[out] out_ip_addr This parameter is filled in with host IP address.
  299. //! In case that host name is not resolved,
  300. //! out_ip_addr is zero.
  301. //! @return On success, positive is returned. On error, negative is returned
  302. //!
  303. //! @brief Get host IP by name. Obtain the IP Address of machine on network,
  304. //! by its name.
  305. //!
  306. //! @note On this version, only blocking mode is supported. Also note that
  307. //! the function requires DNS server to be configured prior to its usage.
  308. //
  309. //*****************************************************************************
  310. #ifndef CC3000_TINY_DRIVER
  311. extern int gethostbyname(char * hostname, uint8_t usNameLen, uint32_t* out_ip_addr);
  312. #endif
  313. //*****************************************************************************
  314. //
  315. //! connect
  316. //!
  317. //! @param[in] sd socket descriptor (handle)
  318. //! @param[in] addr specifies the destination addr. On this version
  319. //! only AF_INET is supported.
  320. //! @param[out] addrlen contains the size of the structure pointed to by addr
  321. //! @return On success, zero is returned. On error, -1 is returned
  322. //!
  323. //! @brief initiate a connection on a socket
  324. //! Function connects the socket referred to by the socket descriptor
  325. //! sd, to the address specified by addr. The addrlen argument
  326. //! specifies the size of addr. The format of the address in addr is
  327. //! determined by the address space of the socket. If it is of type
  328. //! SOCK_DGRAM, this call specifies the peer with which the socket is
  329. //! to be associated; this address is that to which datagrams are to be
  330. //! sent, and the only address from which datagrams are to be received.
  331. //! If the socket is of type SOCK_STREAM, this call attempts to make a
  332. //! connection to another socket. The other socket is specified by
  333. //! address, which is an address in the communications space of the
  334. //! socket. Note that the function implements only blocking behavior
  335. //! thus the caller will be waiting either for the connection
  336. //! establishment or for the connection establishment failure.
  337. //!
  338. //! @sa socket
  339. //
  340. //*****************************************************************************
  341. extern long connect(long sd, const sockaddr *addr, long addrlen);
  342. //*****************************************************************************
  343. //
  344. //! select
  345. //!
  346. //! @param[in] nfds the highest-numbered file descriptor in any of the
  347. //! three sets, plus 1.
  348. //! @param[out] writesds socket descriptors list for write monitoring
  349. //! @param[out] readsds socket descriptors list for read monitoring
  350. //! @param[out] exceptsds socket descriptors list for exception monitoring
  351. //! @param[in] timeout is an upper bound on the amount of time elapsed
  352. //! before select() returns. Null means infinity
  353. //! timeout. The minimum timeout is 5 milliseconds,
  354. //! less than 5 milliseconds will be set
  355. //! automatically to 5 milliseconds.
  356. //! @return On success, select() returns the number of file descriptors
  357. //! contained in the three returned descriptor sets (that is, the
  358. //! total number of bits that are set in readfds, writefds,
  359. //! exceptfds) which may be zero if the timeout expires before
  360. //! anything interesting happens.
  361. //! On error, -1 is returned.
  362. //! *readsds - return the sockets on which Read request will
  363. //! return without delay with valid data.
  364. //! *writesds - return the sockets on which Write request
  365. //! will return without delay.
  366. //! *exceptsds - return the sockets which closed recently.
  367. //!
  368. //! @brief Monitor socket activity
  369. //! Select allow a program to monitor multiple file descriptors,
  370. //! waiting until one or more of the file descriptors become
  371. //! "ready" for some class of I/O operation
  372. //!
  373. //! @Note If the timeout value set to less than 5ms it will automatically set
  374. //! to 5ms to prevent overload of the system
  375. //!
  376. //! @sa socket
  377. //
  378. //*****************************************************************************
  379. extern int select(long nfds, fd_set *readsds, fd_set *writesds,
  380. fd_set *exceptsds, struct timeval *timeout);
  381. //*****************************************************************************
  382. //
  383. //! setsockopt
  384. //!
  385. //! @param[in] sd socket handle
  386. //! @param[in] level defines the protocol level for this option
  387. //! @param[in] optname defines the option name to Interrogate
  388. //! @param[in] optval specifies a value for the option
  389. //! @param[in] optlen specifies the length of the option value
  390. //! @return On success, zero is returned. On error, -1 is returned
  391. //!
  392. //! @brief set socket options
  393. //! This function manipulate the options associated with a socket.
  394. //! Options may exist at multiple protocol levels; they are always
  395. //! present at the uppermost socket level.
  396. //! When manipulating socket options the level at which the option
  397. //! resides and the name of the option must be specified.
  398. //! To manipulate options at the socket level, level is specified as
  399. //! SOL_SOCKET. To manipulate options at any other level the protocol
  400. //! number of the appropriate protocol controlling the option is
  401. //! supplied. For example, to indicate that an option is to be
  402. //! interpreted by the TCP protocol, level should be set to the
  403. //! protocol number of TCP;
  404. //! The parameters optval and optlen are used to access optval -
  405. //! use for setsockopt(). For getsockopt() they identify a buffer
  406. //! in which the value for the requested option(s) are to
  407. //! be returned. For getsockopt(), optlen is a value-result
  408. //! parameter, initially containing the size of the buffer
  409. //! pointed to by option_value, and modified on return to
  410. //! indicate the actual size of the value returned. If no option
  411. //! value is to be supplied or returned, option_value may be NULL.
  412. //!
  413. //! @Note On this version the following two socket options are enabled:
  414. //! The only protocol level supported in this version
  415. //! is SOL_SOCKET (level).
  416. //! 1. SOCKOPT_RECV_TIMEOUT (optname)
  417. //! SOCKOPT_RECV_TIMEOUT configures recv and recvfrom timeout
  418. //! in milliseconds.
  419. //! In that case optval should be pointer to unsigned long.
  420. //! 2. SOCKOPT_NONBLOCK (optname). sets the socket non-blocking mode on
  421. //! or off.
  422. //! In that case optval should be SOCK_ON or SOCK_OFF (optval).
  423. //!
  424. //! @sa getsockopt
  425. //
  426. //*****************************************************************************
  427. #ifndef CC3000_TINY_DRIVER
  428. extern int setsockopt(long sd, long level, long optname, const void *optval,
  429. socklen_t optlen);
  430. #endif
  431. //*****************************************************************************
  432. //
  433. //! getsockopt
  434. //!
  435. //! @param[in] sd socket handle
  436. //! @param[in] level defines the protocol level for this option
  437. //! @param[in] optname defines the option name to Interrogate
  438. //! @param[out] optval specifies a value for the option
  439. //! @param[out] optlen specifies the length of the option value
  440. //! @return On success, zero is returned. On error, -1 is returned
  441. //!
  442. //! @brief set socket options
  443. //! This function manipulate the options associated with a socket.
  444. //! Options may exist at multiple protocol levels; they are always
  445. //! present at the uppermost socket level.
  446. //! When manipulating socket options the level at which the option
  447. //! resides and the name of the option must be specified.
  448. //! To manipulate options at the socket level, level is specified as
  449. //! SOL_SOCKET. To manipulate options at any other level the protocol
  450. //! number of the appropriate protocol controlling the option is
  451. //! supplied. For example, to indicate that an option is to be
  452. //! interpreted by the TCP protocol, level should be set to the
  453. //! protocol number of TCP;
  454. //! The parameters optval and optlen are used to access optval -
  455. //! use for setsockopt(). For getsockopt() they identify a buffer
  456. //! in which the value for the requested option(s) are to
  457. //! be returned. For getsockopt(), optlen is a value-result
  458. //! parameter, initially containing the size of the buffer
  459. //! pointed to by option_value, and modified on return to
  460. //! indicate the actual size of the value returned. If no option
  461. //! value is to be supplied or returned, option_value may be NULL.
  462. //!
  463. //! @Note On this version the following two socket options are enabled:
  464. //! The only protocol level supported in this version
  465. //! is SOL_SOCKET (level).
  466. //! 1. SOCKOPT_RECV_TIMEOUT (optname)
  467. //! SOCKOPT_RECV_TIMEOUT configures recv and recvfrom timeout
  468. //! in milliseconds.
  469. //! In that case optval should be pointer to unsigned long.
  470. //! 2. SOCKOPT_NONBLOCK (optname). sets the socket non-blocking mode on
  471. //! or off.
  472. //! In that case optval should be SOCK_ON or SOCK_OFF (optval).
  473. //!
  474. //! @sa setsockopt
  475. //
  476. //*****************************************************************************
  477. extern int getsockopt(long sd, long level, long optname, void *optval,
  478. socklen_t *optlen);
  479. //*****************************************************************************
  480. //
  481. //! recv
  482. //!
  483. //! @param[in] sd socket handle
  484. //! @param[out] buf Points to the buffer where the message should be stored
  485. //! @param[in] len Specifies the length in bytes of the buffer pointed to
  486. //! by the buffer argument.
  487. //! @param[in] flags Specifies the type of message reception.
  488. //! On this version, this parameter is not supported.
  489. //!
  490. //! @return Return the number of bytes received, or -1 if an error
  491. //! occurred
  492. //!
  493. //! @brief function receives a message from a connection-mode socket
  494. //!
  495. //! @sa recvfrom
  496. //!
  497. //! @Note On this version, only blocking mode is supported.
  498. //
  499. //*****************************************************************************
  500. extern int recv(long sd, void *buf, long len, long flags);
  501. //*****************************************************************************
  502. //
  503. //! recvfrom
  504. //!
  505. //! @param[in] sd socket handle
  506. //! @param[out] buf Points to the buffer where the message should be stored
  507. //! @param[in] len Specifies the length in bytes of the buffer pointed to
  508. //! by the buffer argument.
  509. //! @param[in] flags Specifies the type of message reception.
  510. //! On this version, this parameter is not supported.
  511. //! @param[in] from pointer to an address structure indicating the source
  512. //! address: sockaddr. On this version only AF_INET is
  513. //! supported.
  514. //! @param[in] fromlen source address structure size
  515. //!
  516. //! @return Return the number of bytes received, or -1 if an error
  517. //! occurred
  518. //!
  519. //! @brief read data from socket
  520. //! function receives a message from a connection-mode or
  521. //! connectionless-mode socket. Note that raw sockets are not
  522. //! supported.
  523. //!
  524. //! @sa recv
  525. //!
  526. //! @Note On this version, only blocking mode is supported.
  527. //
  528. //*****************************************************************************
  529. extern int recvfrom(long sd, void *buf, long len, long flags, sockaddr *from,
  530. socklen_t *fromlen);
  531. //*****************************************************************************
  532. //
  533. //! send
  534. //!
  535. //! @param sd socket handle
  536. //! @param buf Points to a buffer containing the message to be sent
  537. //! @param len message size in bytes
  538. //! @param flags On this version, this parameter is not supported
  539. //!
  540. //! @return Return the number of bytes transmitted, or -1 if an
  541. //! error occurred
  542. //!
  543. //! @brief Write data to TCP socket
  544. //! This function is used to transmit a message to another
  545. //! socket.
  546. //!
  547. //! @Note On this version, only blocking mode is supported.
  548. //!
  549. //! @sa sendto
  550. //
  551. //*****************************************************************************
  552. extern int send(long sd, const void *buf, long len, long flags);
  553. //*****************************************************************************
  554. //
  555. //! sendto
  556. //!
  557. //! @param sd socket handle
  558. //! @param buf Points to a buffer containing the message to be sent
  559. //! @param len message size in bytes
  560. //! @param flags On this version, this parameter is not supported
  561. //! @param to pointer to an address structure indicating the destination
  562. //! address: sockaddr. On this version only AF_INET is
  563. //! supported.
  564. //! @param tolen destination address structure size
  565. //!
  566. //! @return Return the number of bytes transmitted, or -1 if an
  567. //! error occurred
  568. //!
  569. //! @brief Write data to TCP socket
  570. //! This function is used to transmit a message to another
  571. //! socket.
  572. //!
  573. //! @Note On this version, only blocking mode is supported.
  574. //!
  575. //! @sa send
  576. //
  577. //*****************************************************************************
  578. extern int sendto(long sd, const void *buf, long len, long flags,
  579. const sockaddr *to, socklen_t tolen);
  580. //*****************************************************************************
  581. //
  582. //! mdnsAdvertiser
  583. //!
  584. //! @param[in] mdnsEnabled flag to enable/disable the mDNS feature
  585. //! @param[in] deviceServiceName Service name as part of the published
  586. //! canonical domain name
  587. //! @param[in] deviceServiceNameLength Length of the service name
  588. //!
  589. //!
  590. //! @return On success, zero is returned, return SOC_ERROR if socket was not
  591. //! opened successfully, or if an error occurred.
  592. //!
  593. //! @brief Set CC3000 in mDNS advertiser mode in order to advertise itself.
  594. //
  595. //*****************************************************************************
  596. extern int mdnsAdvertiser(unsigned short mdnsEnabled, char * deviceServiceName, unsigned short deviceServiceNameLength);
  597. //*****************************************************************************
  598. //
  599. // Close the Doxygen group.
  600. //! @}
  601. //
  602. //*****************************************************************************
  603. //*****************************************************************************
  604. //
  605. // Mark the end of the C bindings section for C++ compilers.
  606. //
  607. //*****************************************************************************
  608. #ifdef __cplusplus
  609. }
  610. #endif // __cplusplus
  611. #endif // __SOCKET_H__