PageRenderTime 65ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

/libraries/SimplelinkWifi/utility/socket.h

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