PageRenderTime 53ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/libs/network/cc3000/socket.h

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