PageRenderTime 62ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/core-common-lib/CC3000_Host_Driver/socket.h

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