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

/pjproject-1.0.2/pjlib/include/pj/sock.h

https://bitbucket.org/teluu/tabikphoneandroid
C Header | 1262 lines | 311 code | 173 blank | 778 comment | 7 complexity | 5b83f1d7c43ac4e012b278edf5533a92 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, BSD-3-Clause
  1. /* $Id: sock.h 2394 2008-12-23 17:27:53Z bennylp $ */
  2. /*
  3. * Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com)
  4. * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #ifndef __PJ_SOCK_H__
  21. #define __PJ_SOCK_H__
  22. /**
  23. * @file sock.h
  24. * @brief Socket Abstraction.
  25. */
  26. #include <pj/types.h>
  27. PJ_BEGIN_DECL
  28. /**
  29. * @defgroup PJ_SOCK Socket Abstraction
  30. * @ingroup PJ_IO
  31. * @{
  32. *
  33. * The PJLIB socket abstraction layer is a thin and very portable abstraction
  34. * for socket API. It provides API similar to BSD socket API. The abstraction
  35. * is needed because BSD socket API is not always available on all platforms,
  36. * therefore it wouldn't be possible to create a trully portable network
  37. * programs unless we provide such abstraction.
  38. *
  39. * Applications can use this API directly in their application, just
  40. * as they would when using traditional BSD socket API, provided they
  41. * call #pj_init() first.
  42. *
  43. * \section pj_sock_examples_sec Examples
  44. *
  45. * For some examples on how to use the socket API, please see:
  46. *
  47. * - \ref page_pjlib_sock_test
  48. * - \ref page_pjlib_select_test
  49. * - \ref page_pjlib_sock_perf_test
  50. */
  51. /**
  52. * Supported address families.
  53. * APPLICATION MUST USE THESE VALUES INSTEAD OF NORMAL AF_*, BECAUSE
  54. * THE LIBRARY WILL DO TRANSLATION TO THE NATIVE VALUE.
  55. */
  56. /** Address family is unspecified. @see pj_AF_UNSPEC() */
  57. extern const pj_uint16_t PJ_AF_UNSPEC;
  58. /** Unix domain socket. @see pj_AF_UNIX() */
  59. extern const pj_uint16_t PJ_AF_UNIX;
  60. /** POSIX name for AF_UNIX */
  61. #define PJ_AF_LOCAL PJ_AF_UNIX;
  62. /** Internet IP protocol. @see pj_AF_INET() */
  63. extern const pj_uint16_t PJ_AF_INET;
  64. /** IP version 6. @see pj_AF_INET6() */
  65. extern const pj_uint16_t PJ_AF_INET6;
  66. /** Packet family. @see pj_AF_PACKET() */
  67. extern const pj_uint16_t PJ_AF_PACKET;
  68. /** IRDA sockets. @see pj_AF_IRDA() */
  69. extern const pj_uint16_t PJ_AF_IRDA;
  70. /*
  71. * Accessor functions for various address family constants. These
  72. * functions are provided because Symbian doesn't allow exporting
  73. * global variables from a DLL.
  74. */
  75. #if defined(PJ_DLL)
  76. /** Get #PJ_AF_UNSPEC value */
  77. PJ_DECL(pj_uint16_t) pj_AF_UNSPEC(void);
  78. /** Get #PJ_AF_UNIX value. */
  79. PJ_DECL(pj_uint16_t) pj_AF_UNIX(void);
  80. /** Get #PJ_AF_INET value. */
  81. PJ_DECL(pj_uint16_t) pj_AF_INET(void);
  82. /** Get #PJ_AF_INET6 value. */
  83. PJ_DECL(pj_uint16_t) pj_AF_INET6(void);
  84. /** Get #PJ_AF_PACKET value. */
  85. PJ_DECL(pj_uint16_t) pj_AF_PACKET(void);
  86. /** Get #PJ_AF_IRDA value. */
  87. PJ_DECL(pj_uint16_t) pj_AF_IRDA(void);
  88. #else
  89. /* When pjlib is not built as DLL, these accessor functions are
  90. * simply a macro to get their constants
  91. */
  92. /** Get #PJ_AF_UNSPEC value */
  93. # define pj_AF_UNSPEC() PJ_AF_UNSPEC
  94. /** Get #PJ_AF_UNIX value. */
  95. # define pj_AF_UNIX() PJ_AF_UNIX
  96. /** Get #PJ_AF_INET value. */
  97. # define pj_AF_INET() PJ_AF_INET
  98. /** Get #PJ_AF_INET6 value. */
  99. # define pj_AF_INET6() PJ_AF_INET6
  100. /** Get #PJ_AF_PACKET value. */
  101. # define pj_AF_PACKET() PJ_AF_PACKET
  102. /** Get #PJ_AF_IRDA value. */
  103. # define pj_AF_IRDA() PJ_AF_IRDA
  104. #endif
  105. /**
  106. * Supported types of sockets.
  107. * APPLICATION MUST USE THESE VALUES INSTEAD OF NORMAL SOCK_*, BECAUSE
  108. * THE LIBRARY WILL TRANSLATE THE VALUE TO THE NATIVE VALUE.
  109. */
  110. /** Sequenced, reliable, connection-based byte streams.
  111. * @see pj_SOCK_STREAM() */
  112. extern const pj_uint16_t PJ_SOCK_STREAM;
  113. /** Connectionless, unreliable datagrams of fixed maximum lengths.
  114. * @see pj_SOCK_DGRAM() */
  115. extern const pj_uint16_t PJ_SOCK_DGRAM;
  116. /** Raw protocol interface. @see pj_SOCK_RAW() */
  117. extern const pj_uint16_t PJ_SOCK_RAW;
  118. /** Reliably-delivered messages. @see pj_SOCK_RDM() */
  119. extern const pj_uint16_t PJ_SOCK_RDM;
  120. /*
  121. * Accessor functions for various constants. These functions are provided
  122. * because Symbian doesn't allow exporting global variables from a DLL.
  123. */
  124. #if defined(PJ_DLL)
  125. /** Get #PJ_SOCK_STREAM constant */
  126. PJ_DECL(int) pj_SOCK_STREAM(void);
  127. /** Get #PJ_SOCK_DGRAM constant */
  128. PJ_DECL(int) pj_SOCK_DGRAM(void);
  129. /** Get #PJ_SOCK_RAW constant */
  130. PJ_DECL(int) pj_SOCK_RAW(void);
  131. /** Get #PJ_SOCK_RDM constant */
  132. PJ_DECL(int) pj_SOCK_RDM(void);
  133. #else
  134. /** Get #PJ_SOCK_STREAM constant */
  135. # define pj_SOCK_STREAM() PJ_SOCK_STREAM
  136. /** Get #PJ_SOCK_DGRAM constant */
  137. # define pj_SOCK_DGRAM() PJ_SOCK_DGRAM
  138. /** Get #PJ_SOCK_RAW constant */
  139. # define pj_SOCK_RAW() PJ_SOCK_RAW
  140. /** Get #PJ_SOCK_RDM constant */
  141. # define pj_SOCK_RDM() PJ_SOCK_RDM
  142. #endif
  143. /**
  144. * Socket level specified in #pj_sock_setsockopt() or #pj_sock_getsockopt().
  145. * APPLICATION MUST USE THESE VALUES INSTEAD OF NORMAL SOL_*, BECAUSE
  146. * THE LIBRARY WILL TRANSLATE THE VALUE TO THE NATIVE VALUE.
  147. */
  148. /** Socket level. @see pj_SOL_SOCKET() */
  149. extern const pj_uint16_t PJ_SOL_SOCKET;
  150. /** IP level. @see pj_SOL_IP() */
  151. extern const pj_uint16_t PJ_SOL_IP;
  152. /** TCP level. @see pj_SOL_TCP() */
  153. extern const pj_uint16_t PJ_SOL_TCP;
  154. /** UDP level. @see pj_SOL_UDP() */
  155. extern const pj_uint16_t PJ_SOL_UDP;
  156. /** IP version 6. @see pj_SOL_IPV6() */
  157. extern const pj_uint16_t PJ_SOL_IPV6;
  158. /*
  159. * Accessor functions for various constants. These functions are provided
  160. * because Symbian doesn't allow exporting global variables from a DLL.
  161. */
  162. #if defined(PJ_DLL)
  163. /** Get #PJ_SOL_SOCKET constant */
  164. PJ_DECL(pj_uint16_t) pj_SOL_SOCKET(void);
  165. /** Get #PJ_SOL_IP constant */
  166. PJ_DECL(pj_uint16_t) pj_SOL_IP(void);
  167. /** Get #PJ_SOL_TCP constant */
  168. PJ_DECL(pj_uint16_t) pj_SOL_TCP(void);
  169. /** Get #PJ_SOL_UDP constant */
  170. PJ_DECL(pj_uint16_t) pj_SOL_UDP(void);
  171. /** Get #PJ_SOL_IPV6 constant */
  172. PJ_DECL(pj_uint16_t) pj_SOL_IPV6(void);
  173. #else
  174. /** Get #PJ_SOL_SOCKET constant */
  175. # define pj_SOL_SOCKET() PJ_SOL_SOCKET
  176. /** Get #PJ_SOL_IP constant */
  177. # define pj_SOL_IP() PJ_SOL_IP
  178. /** Get #PJ_SOL_TCP constant */
  179. # define pj_SOL_TCP() PJ_SOL_TCP
  180. /** Get #PJ_SOL_UDP constant */
  181. # define pj_SOL_UDP() PJ_SOL_UDP
  182. /** Get #PJ_SOL_IPV6 constant */
  183. # define pj_SOL_IPV6() PJ_SOL_IPV6
  184. #endif
  185. /* IP_TOS
  186. *
  187. * Note:
  188. * TOS CURRENTLY DOES NOT WORK IN Windows 2000 and above!
  189. * See http://support.microsoft.com/kb/248611
  190. */
  191. /** IP_TOS optname in setsockopt(). @see pj_IP_TOS() */
  192. extern const pj_uint16_t PJ_IP_TOS;
  193. /*
  194. * IP TOS related constats.
  195. *
  196. * Note:
  197. * TOS CURRENTLY DOES NOT WORK IN Windows 2000 and above!
  198. * See http://support.microsoft.com/kb/248611
  199. */
  200. /** Minimize delays. @see pj_IPTOS_LOWDELAY() */
  201. extern const pj_uint16_t PJ_IPTOS_LOWDELAY;
  202. /** Optimize throughput. @see pj_IPTOS_THROUGHPUT() */
  203. extern const pj_uint16_t PJ_IPTOS_THROUGHPUT;
  204. /** Optimize for reliability. @see pj_IPTOS_RELIABILITY() */
  205. extern const pj_uint16_t PJ_IPTOS_RELIABILITY;
  206. /** "filler data" where slow transmission does't matter.
  207. * @see pj_IPTOS_MINCOST() */
  208. extern const pj_uint16_t PJ_IPTOS_MINCOST;
  209. #if defined(PJ_DLL)
  210. /** Get #PJ_IP_TOS constant */
  211. PJ_DECL(int) pj_IP_TOS(void);
  212. /** Get #PJ_IPTOS_LOWDELAY constant */
  213. PJ_DECL(int) pj_IPTOS_LOWDELAY(void);
  214. /** Get #PJ_IPTOS_THROUGHPUT constant */
  215. PJ_DECL(int) pj_IPTOS_THROUGHPUT(void);
  216. /** Get #PJ_IPTOS_RELIABILITY constant */
  217. PJ_DECL(int) pj_IPTOS_RELIABILITY(void);
  218. /** Get #PJ_IPTOS_MINCOST constant */
  219. PJ_DECL(int) pj_IPTOS_MINCOST(void);
  220. #else
  221. /** Get #PJ_IP_TOS constant */
  222. # define pj_IP_TOS() PJ_IP_TOS
  223. /** Get #PJ_IPTOS_LOWDELAY constant */
  224. # define pj_IPTOS_LOWDELAY() PJ_IP_TOS_LOWDELAY
  225. /** Get #PJ_IPTOS_THROUGHPUT constant */
  226. # define pj_IPTOS_THROUGHPUT() PJ_IP_TOS_THROUGHPUT
  227. /** Get #PJ_IPTOS_RELIABILITY constant */
  228. # define pj_IPTOS_RELIABILITY() PJ_IP_TOS_RELIABILITY
  229. /** Get #PJ_IPTOS_MINCOST constant */
  230. # define pj_IPTOS_MINCOST() PJ_IP_TOS_MINCOST
  231. #endif
  232. /**
  233. * Values to be specified as \c optname when calling #pj_sock_setsockopt()
  234. * or #pj_sock_getsockopt().
  235. */
  236. /** Socket type. @see pj_SO_TYPE() */
  237. extern const pj_uint16_t PJ_SO_TYPE;
  238. /** Buffer size for receive. @see pj_SO_RCVBUF() */
  239. extern const pj_uint16_t PJ_SO_RCVBUF;
  240. /** Buffer size for send. @see pj_SO_SNDBUF() */
  241. extern const pj_uint16_t PJ_SO_SNDBUF;
  242. /** IP multicast interface. @see pj_IP_MULTICAST_IF() */
  243. extern const pj_uint16_t PJ_IP_MULTICAST_IF;
  244. /** IP multicast ttl. @see pj_IP_MULTICAST_TTL() */
  245. extern const pj_uint16_t PJ_IP_MULTICAST_TTL;
  246. /** IP multicast loopback. @see pj_IP_MULTICAST_LOOP() */
  247. extern const pj_uint16_t PJ_IP_MULTICAST_LOOP;
  248. /** Add an IP group membership. @see pj_IP_ADD_MEMBERSHIP() */
  249. extern const pj_uint16_t PJ_IP_ADD_MEMBERSHIP;
  250. /** Drop an IP group membership. @see pj_IP_DROP_MEMBERSHIP() */
  251. extern const pj_uint16_t PJ_IP_DROP_MEMBERSHIP;
  252. #if defined(PJ_DLL)
  253. /** Get #PJ_SO_TYPE constant */
  254. PJ_DECL(pj_uint16_t) pj_SO_TYPE(void);
  255. /** Get #PJ_SO_RCVBUF constant */
  256. PJ_DECL(pj_uint16_t) pj_SO_RCVBUF(void);
  257. /** Get #PJ_SO_SNDBUF constant */
  258. PJ_DECL(pj_uint16_t) pj_SO_SNDBUF(void);
  259. /** Get #PJ_IP_MULTICAST_IF constant */
  260. PJ_DECL(pj_uint16_t) pj_IP_MULTICAST_IF(void);
  261. /** Get #PJ_IP_MULTICAST_TTL constant */
  262. PJ_DECL(pj_uint16_t) pj_IP_MULTICAST_TTL(void);
  263. /** Get #PJ_IP_MULTICAST_LOOP constant */
  264. PJ_DECL(pj_uint16_t) pj_IP_MULTICAST_LOOP(void);
  265. /** Get #PJ_IP_ADD_MEMBERSHIP constant */
  266. PJ_DECL(pj_uint16_t) pj_IP_ADD_MEMBERSHIP(void);
  267. /** Get #PJ_IP_DROP_MEMBERSHIP constant */
  268. PJ_DECL(pj_uint16_t) pj_IP_DROP_MEMBERSHIP(void);
  269. #else
  270. /** Get #PJ_SO_TYPE constant */
  271. # define pj_SO_TYPE() PJ_SO_TYPE
  272. /** Get #PJ_SO_RCVBUF constant */
  273. # define pj_SO_RCVBUF() PJ_SO_RCVBUF
  274. /** Get #PJ_SO_SNDBUF constant */
  275. # define pj_SO_SNDBUF() PJ_SO_SNDBUF
  276. /** Get #PJ_IP_MULTICAST_IF constant */
  277. # define pj_IP_MULTICAST_IF() PJ_IP_MULTICAST_IF
  278. /** Get #PJ_IP_MULTICAST_TTL constant */
  279. # define pj_IP_MULTICAST_TTL() PJ_IP_MULTICAST_TTL
  280. /** Get #PJ_IP_MULTICAST_LOOP constant */
  281. # define pj_IP_MULTICAST_LOOP() PJ_IP_MULTICAST_LOOP
  282. /** Get #PJ_IP_ADD_MEMBERSHIP constant */
  283. # define pj_IP_ADD_MEMBERSHIP() PJ_IP_ADD_MEMBERSHIP
  284. /** Get #PJ_IP_DROP_MEMBERSHIP constant */
  285. # define pj_IP_DROP_MEMBERSHIP() PJ_IP_DROP_MEMBERSHIP
  286. #endif
  287. /*
  288. * Flags to be specified in #pj_sock_recv, #pj_sock_send, etc.
  289. */
  290. /** Out-of-band messages. @see pj_MSG_OOB() */
  291. extern const int PJ_MSG_OOB;
  292. /** Peek, don't remove from buffer. @see pj_MSG_PEEK() */
  293. extern const int PJ_MSG_PEEK;
  294. /** Don't route. @see pj_MSG_DONTROUTE() */
  295. extern const int PJ_MSG_DONTROUTE;
  296. #if defined(PJ_DLL)
  297. /** Get #PJ_MSG_OOB constant */
  298. PJ_DECL(int) pj_MSG_OOB(void);
  299. /** Get #PJ_MSG_PEEK constant */
  300. PJ_DECL(int) pj_MSG_PEEK(void);
  301. /** Get #PJ_MSG_DONTROUTE constant */
  302. PJ_DECL(int) pj_MSG_DONTROUTE(void);
  303. #else
  304. /** Get #PJ_MSG_OOB constant */
  305. # define pj_MSG_OOB() PJ_MSG_OOB
  306. /** Get #PJ_MSG_PEEK constant */
  307. # define pj_MSG_PEEK() PJ_MSG_PEEK
  308. /** Get #PJ_MSG_DONTROUTE constant */
  309. # define pj_MSG_DONTROUTE() PJ_MSG_DONTROUTE
  310. #endif
  311. /**
  312. * Flag to be specified in #pj_sock_shutdown().
  313. */
  314. typedef enum pj_socket_sd_type
  315. {
  316. PJ_SD_RECEIVE = 0, /**< No more receive. */
  317. PJ_SHUT_RD = 0, /**< Alias for SD_RECEIVE. */
  318. PJ_SD_SEND = 1, /**< No more sending. */
  319. PJ_SHUT_WR = 1, /**< Alias for SD_SEND. */
  320. PJ_SD_BOTH = 2, /**< No more send and receive. */
  321. PJ_SHUT_RDWR = 2 /**< Alias for SD_BOTH. */
  322. } pj_socket_sd_type;
  323. /** Address to accept any incoming messages. */
  324. #define PJ_INADDR_ANY ((pj_uint32_t)0)
  325. /** Address indicating an error return */
  326. #define PJ_INADDR_NONE ((pj_uint32_t)0xffffffff)
  327. /** Address to send to all hosts. */
  328. #define PJ_INADDR_BROADCAST ((pj_uint32_t)0xffffffff)
  329. /**
  330. * Maximum length specifiable by #pj_sock_listen().
  331. * If the build system doesn't override this value, then the lowest
  332. * denominator (five, in Win32 systems) will be used.
  333. */
  334. #if !defined(PJ_SOMAXCONN)
  335. # define PJ_SOMAXCONN 5
  336. #endif
  337. /**
  338. * Constant for invalid socket returned by #pj_sock_socket() and
  339. * #pj_sock_accept().
  340. */
  341. #define PJ_INVALID_SOCKET (-1)
  342. /* Must undefine s_addr because of pj_in_addr below */
  343. #undef s_addr
  344. /**
  345. * This structure describes Internet address.
  346. */
  347. typedef struct pj_in_addr
  348. {
  349. pj_uint32_t s_addr; /**< The 32bit IP address. */
  350. } pj_in_addr;
  351. /**
  352. * Maximum length of text representation of an IPv4 address.
  353. */
  354. #define PJ_INET_ADDRSTRLEN 16
  355. /**
  356. * Maximum length of text representation of an IPv6 address.
  357. */
  358. #define PJ_INET6_ADDRSTRLEN 46
  359. /**
  360. * This structure describes Internet socket address.
  361. * If PJ_SOCKADDR_HAS_LEN is not zero, then sin_zero_len member is added
  362. * to this struct. As far the application is concerned, the value of
  363. * this member will always be zero. Internally, PJLIB may modify the value
  364. * before calling OS socket API, and reset the value back to zero before
  365. * returning the struct to application.
  366. */
  367. struct pj_sockaddr_in
  368. {
  369. #if defined(PJ_SOCKADDR_HAS_LEN) && PJ_SOCKADDR_HAS_LEN!=0
  370. pj_uint8_t sin_zero_len; /**< Just ignore this. */
  371. pj_uint8_t sin_family; /**< Address family. */
  372. #else
  373. pj_uint16_t sin_family; /**< Address family. */
  374. #endif
  375. pj_uint16_t sin_port; /**< Transport layer port number. */
  376. pj_in_addr sin_addr; /**< IP address. */
  377. #if defined(PJ_SOCKADDR_HAS_PAD) && PJ_SOCKADDR_HAS_PAD!=0
  378. char __pad[8]; /**< Padding. */
  379. #else
  380. char sin_zero[8]; /**< Padding. */
  381. #endif
  382. };
  383. #undef s6_addr
  384. /**
  385. * This structure describes IPv6 address.
  386. */
  387. typedef union pj_in6_addr
  388. {
  389. /* This is the main entry */
  390. pj_uint8_t s6_addr[16]; /**< 8-bit array */
  391. /* While these are used for proper alignment */
  392. pj_uint32_t u6_addr32[4];
  393. /* Do not use this with Winsock2, as this will align pj_sockaddr_in6
  394. * to 64-bit boundary and Winsock2 doesn't like it!
  395. */
  396. #if defined(PJ_HAS_INT64) && PJ_HAS_INT64!=0 && \
  397. (!defined(PJ_WIN32) || PJ_WIN32==0)
  398. pj_int64_t u6_addr64[2];
  399. #endif
  400. } pj_in6_addr;
  401. /** Initializer value for pj_in6_addr. */
  402. #define PJ_IN6ADDR_ANY_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } }
  403. /** Initializer value for pj_in6_addr. */
  404. #define PJ_IN6ADDR_LOOPBACK_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } }
  405. /**
  406. * This structure describes IPv6 socket address.
  407. * If PJ_SOCKADDR_HAS_LEN is not zero, then sin_zero_len member is added
  408. * to this struct. As far the application is concerned, the value of
  409. * this member will always be zero. Internally, PJLIB may modify the value
  410. * before calling OS socket API, and reset the value back to zero before
  411. * returning the struct to application.
  412. */
  413. typedef struct pj_sockaddr_in6
  414. {
  415. #if defined(PJ_SOCKADDR_HAS_LEN) && PJ_SOCKADDR_HAS_LEN!=0
  416. pj_uint8_t sin6_zero_len; /**< Just ignore this. */
  417. pj_uint8_t sin6_family; /**< Address family. */
  418. #else
  419. pj_uint16_t sin6_family; /**< Address family */
  420. #endif
  421. pj_uint16_t sin6_port; /**< Transport layer port number. */
  422. pj_uint32_t sin6_flowinfo; /**< IPv6 flow information */
  423. pj_in6_addr sin6_addr; /**< IPv6 address. */
  424. pj_uint32_t sin6_scope_id; /**< Set of interfaces for a scope */
  425. } pj_sockaddr_in6;
  426. /**
  427. * This structure describes common attributes found in transport addresses.
  428. * If PJ_SOCKADDR_HAS_LEN is not zero, then sa_zero_len member is added
  429. * to this struct. As far the application is concerned, the value of
  430. * this member will always be zero. Internally, PJLIB may modify the value
  431. * before calling OS socket API, and reset the value back to zero before
  432. * returning the struct to application.
  433. */
  434. typedef struct pj_addr_hdr
  435. {
  436. #if defined(PJ_SOCKADDR_HAS_LEN) && PJ_SOCKADDR_HAS_LEN!=0
  437. pj_uint8_t sa_zero_len;
  438. pj_uint8_t sa_family;
  439. #else
  440. pj_uint16_t sa_family; /**< Common data: address family. */
  441. #endif
  442. } pj_addr_hdr;
  443. /**
  444. * This union describes a generic socket address.
  445. */
  446. typedef union pj_sockaddr
  447. {
  448. pj_addr_hdr addr; /**< Generic transport address. */
  449. pj_sockaddr_in ipv4; /**< IPv4 transport address. */
  450. pj_sockaddr_in6 ipv6; /**< IPv6 transport address. */
  451. } pj_sockaddr;
  452. /**
  453. * This structure provides multicast group information for IPv4 addresses.
  454. */
  455. typedef struct pj_ip_mreq {
  456. pj_in_addr imr_multiaddr; /**< IP multicast address of group. */
  457. pj_in_addr imr_interface; /**< local IP address of interface. */
  458. } pj_ip_mreq;
  459. /*****************************************************************************
  460. *
  461. * SOCKET ADDRESS MANIPULATION.
  462. *
  463. *****************************************************************************
  464. */
  465. /**
  466. * Convert 16-bit value from network byte order to host byte order.
  467. *
  468. * @param netshort 16-bit network value.
  469. * @return 16-bit host value.
  470. */
  471. PJ_DECL(pj_uint16_t) pj_ntohs(pj_uint16_t netshort);
  472. /**
  473. * Convert 16-bit value from host byte order to network byte order.
  474. *
  475. * @param hostshort 16-bit host value.
  476. * @return 16-bit network value.
  477. */
  478. PJ_DECL(pj_uint16_t) pj_htons(pj_uint16_t hostshort);
  479. /**
  480. * Convert 32-bit value from network byte order to host byte order.
  481. *
  482. * @param netlong 32-bit network value.
  483. * @return 32-bit host value.
  484. */
  485. PJ_DECL(pj_uint32_t) pj_ntohl(pj_uint32_t netlong);
  486. /**
  487. * Convert 32-bit value from host byte order to network byte order.
  488. *
  489. * @param hostlong 32-bit host value.
  490. * @return 32-bit network value.
  491. */
  492. PJ_DECL(pj_uint32_t) pj_htonl(pj_uint32_t hostlong);
  493. /**
  494. * Convert an Internet host address given in network byte order
  495. * to string in standard numbers and dots notation.
  496. *
  497. * @param inaddr The host address.
  498. * @return The string address.
  499. */
  500. PJ_DECL(char*) pj_inet_ntoa(pj_in_addr inaddr);
  501. /**
  502. * This function converts the Internet host address cp from the standard
  503. * numbers-and-dots notation into binary data and stores it in the structure
  504. * that inp points to.
  505. *
  506. * @param cp IP address in standard numbers-and-dots notation.
  507. * @param inp Structure that holds the output of the conversion.
  508. *
  509. * @return nonzero if the address is valid, zero if not.
  510. */
  511. PJ_DECL(int) pj_inet_aton(const pj_str_t *cp, struct pj_in_addr *inp);
  512. /**
  513. * This function converts an address in its standard text presentation form
  514. * into its numeric binary form. It supports both IPv4 and IPv6 address
  515. * conversion.
  516. *
  517. * @param af Specify the family of the address. The PJ_AF_INET and
  518. * PJ_AF_INET6 address families shall be supported.
  519. * @param src Points to the string being passed in.
  520. * @param dst Points to a buffer into which the function stores the
  521. * numeric address; this shall be large enough to hold the
  522. * numeric address (32 bits for PJ_AF_INET, 128 bits for
  523. * PJ_AF_INET6).
  524. *
  525. * @return PJ_SUCCESS if conversion was successful.
  526. */
  527. PJ_DECL(pj_status_t) pj_inet_pton(int af, const pj_str_t *src, void *dst);
  528. /**
  529. * This function converts a numeric address into a text string suitable
  530. * for presentation. It supports both IPv4 and IPv6 address
  531. * conversion.
  532. * @see pj_sockaddr_print()
  533. *
  534. * @param af Specify the family of the address. This can be PJ_AF_INET
  535. * or PJ_AF_INET6.
  536. * @param src Points to a buffer holding an IPv4 address if the af argument
  537. * is PJ_AF_INET, or an IPv6 address if the af argument is
  538. * PJ_AF_INET6; the address must be in network byte order.
  539. * @param dst Points to a buffer where the function stores the resulting
  540. * text string; it shall not be NULL.
  541. * @param size Specifies the size of this buffer, which shall be large
  542. * enough to hold the text string (PJ_INET_ADDRSTRLEN characters
  543. * for IPv4, PJ_INET6_ADDRSTRLEN characters for IPv6).
  544. *
  545. * @return PJ_SUCCESS if conversion was successful.
  546. */
  547. PJ_DECL(pj_status_t) pj_inet_ntop(int af, const void *src,
  548. char *dst, int size);
  549. /**
  550. * Converts numeric address into its text string representation.
  551. * @see pj_sockaddr_print()
  552. *
  553. * @param af Specify the family of the address. This can be PJ_AF_INET
  554. * or PJ_AF_INET6.
  555. * @param src Points to a buffer holding an IPv4 address if the af argument
  556. * is PJ_AF_INET, or an IPv6 address if the af argument is
  557. * PJ_AF_INET6; the address must be in network byte order.
  558. * @param dst Points to a buffer where the function stores the resulting
  559. * text string; it shall not be NULL.
  560. * @param size Specifies the size of this buffer, which shall be large
  561. * enough to hold the text string (PJ_INET_ADDRSTRLEN characters
  562. * for IPv4, PJ_INET6_ADDRSTRLEN characters for IPv6).
  563. *
  564. * @return The address string or NULL if failed.
  565. */
  566. PJ_DECL(char*) pj_inet_ntop2(int af, const void *src,
  567. char *dst, int size);
  568. /**
  569. * Print socket address.
  570. *
  571. * @param addr The socket address.
  572. * @param buf Text buffer.
  573. * @param size Size of buffer.
  574. * @param flags Bitmask combination of these value:
  575. * - 1: port number is included.
  576. * - 2: square bracket is included for IPv6 address.
  577. *
  578. * @return The address string.
  579. */
  580. PJ_DECL(char*) pj_sockaddr_print(const pj_sockaddr_t *addr,
  581. char *buf, int size,
  582. unsigned flags);
  583. /**
  584. * Convert address string with numbers and dots to binary IP address.
  585. *
  586. * @param cp The IP address in numbers and dots notation.
  587. * @return If success, the IP address is returned in network
  588. * byte order. If failed, PJ_INADDR_NONE will be
  589. * returned.
  590. * @remark
  591. * This is an obsolete interface to #pj_inet_aton(); it is obsolete
  592. * because -1 is a valid address (255.255.255.255), and #pj_inet_aton()
  593. * provides a cleaner way to indicate error return.
  594. */
  595. PJ_DECL(pj_in_addr) pj_inet_addr(const pj_str_t *cp);
  596. /**
  597. * Convert address string with numbers and dots to binary IP address.
  598. *
  599. * @param cp The IP address in numbers and dots notation.
  600. * @return If success, the IP address is returned in network
  601. * byte order. If failed, PJ_INADDR_NONE will be
  602. * returned.
  603. * @remark
  604. * This is an obsolete interface to #pj_inet_aton(); it is obsolete
  605. * because -1 is a valid address (255.255.255.255), and #pj_inet_aton()
  606. * provides a cleaner way to indicate error return.
  607. */
  608. PJ_DECL(pj_in_addr) pj_inet_addr2(const char *cp);
  609. /**
  610. * Initialize IPv4 socket address based on the address and port info.
  611. * The string address may be in a standard numbers and dots notation or
  612. * may be a hostname. If hostname is specified, then the function will
  613. * resolve the host into the IP address.
  614. *
  615. * @see pj_sockaddr_init()
  616. *
  617. * @param addr The IP socket address to be set.
  618. * @param cp The address string, which can be in a standard
  619. * dotted numbers or a hostname to be resolved.
  620. * @param port The port number, in host byte order.
  621. *
  622. * @return Zero on success.
  623. */
  624. PJ_DECL(pj_status_t) pj_sockaddr_in_init( pj_sockaddr_in *addr,
  625. const pj_str_t *cp,
  626. pj_uint16_t port);
  627. /**
  628. * Initialize IP socket address based on the address and port info.
  629. * The string address may be in a standard numbers and dots notation or
  630. * may be a hostname. If hostname is specified, then the function will
  631. * resolve the host into the IP address.
  632. *
  633. * @see pj_sockaddr_in_init()
  634. *
  635. * @param af Internet address family.
  636. * @param addr The IP socket address to be set.
  637. * @param cp The address string, which can be in a standard
  638. * dotted numbers or a hostname to be resolved.
  639. * @param port The port number, in host byte order.
  640. *
  641. * @return Zero on success.
  642. */
  643. PJ_DECL(pj_status_t) pj_sockaddr_init(int af,
  644. pj_sockaddr *addr,
  645. const pj_str_t *cp,
  646. pj_uint16_t port);
  647. /**
  648. * Compare two socket addresses.
  649. *
  650. * @param addr1 First address.
  651. * @param addr2 Second address.
  652. *
  653. * @return Zero on equal, -1 if addr1 is less than addr2,
  654. * and +1 if addr1 is more than addr2.
  655. */
  656. PJ_DECL(int) pj_sockaddr_cmp(const pj_sockaddr_t *addr1,
  657. const pj_sockaddr_t *addr2);
  658. /**
  659. * Get pointer to the address part of a socket address.
  660. *
  661. * @param addr Socket address.
  662. *
  663. * @return Pointer to address part (sin_addr or sin6_addr,
  664. * depending on address family)
  665. */
  666. PJ_DECL(void*) pj_sockaddr_get_addr(const pj_sockaddr_t *addr);
  667. /**
  668. * Check that a socket address contains a non-zero address part.
  669. *
  670. * @param addr Socket address.
  671. *
  672. * @return Non-zero if address is set to non-zero.
  673. */
  674. PJ_DECL(pj_bool_t) pj_sockaddr_has_addr(const pj_sockaddr_t *addr);
  675. /**
  676. * Get the address part length of a socket address, based on its address
  677. * family. For PJ_AF_INET, the length will be sizeof(pj_in_addr), and
  678. * for PJ_AF_INET6, the length will be sizeof(pj_in6_addr).
  679. *
  680. * @param addr Socket address.
  681. *
  682. * @return Length in bytes.
  683. */
  684. PJ_DECL(unsigned) pj_sockaddr_get_addr_len(const pj_sockaddr_t *addr);
  685. /**
  686. * Get the socket address length, based on its address
  687. * family. For PJ_AF_INET, the length will be sizeof(pj_sockaddr_in), and
  688. * for PJ_AF_INET6, the length will be sizeof(pj_sockaddr_in6).
  689. *
  690. * @param addr Socket address.
  691. *
  692. * @return Length in bytes.
  693. */
  694. PJ_DECL(unsigned) pj_sockaddr_get_len(const pj_sockaddr_t *addr);
  695. /**
  696. * Copy only the address part (sin_addr/sin6_addr) of a socket address.
  697. *
  698. * @param dst Destination socket address.
  699. * @param src Source socket address.
  700. *
  701. * @see @pj_sockaddr_cp()
  702. */
  703. PJ_DECL(void) pj_sockaddr_copy_addr(pj_sockaddr *dst,
  704. const pj_sockaddr *src);
  705. /**
  706. * Copy socket address. This will copy the whole structure depending
  707. * on the address family of the source socket address.
  708. *
  709. * @param dst Destination socket address.
  710. * @param src Source socket address.
  711. *
  712. * @see @pj_sockaddr_copy_addr()
  713. */
  714. PJ_DECL(void) pj_sockaddr_cp(pj_sockaddr_t *dst, const pj_sockaddr_t *src);
  715. /**
  716. * Get the IP address of an IPv4 socket address.
  717. * The address is returned as 32bit value in host byte order.
  718. *
  719. * @param addr The IP socket address.
  720. * @return 32bit address, in host byte order.
  721. */
  722. PJ_DECL(pj_in_addr) pj_sockaddr_in_get_addr(const pj_sockaddr_in *addr);
  723. /**
  724. * Set the IP address of an IPv4 socket address.
  725. *
  726. * @param addr The IP socket address.
  727. * @param hostaddr The host address, in host byte order.
  728. */
  729. PJ_DECL(void) pj_sockaddr_in_set_addr(pj_sockaddr_in *addr,
  730. pj_uint32_t hostaddr);
  731. /**
  732. * Set the IP address of an IP socket address from string address,
  733. * with resolving the host if necessary. The string address may be in a
  734. * standard numbers and dots notation or may be a hostname. If hostname
  735. * is specified, then the function will resolve the host into the IP
  736. * address.
  737. *
  738. * @see pj_sockaddr_set_str_addr()
  739. *
  740. * @param addr The IP socket address to be set.
  741. * @param cp The address string, which can be in a standard
  742. * dotted numbers or a hostname to be resolved.
  743. *
  744. * @return PJ_SUCCESS on success.
  745. */
  746. PJ_DECL(pj_status_t) pj_sockaddr_in_set_str_addr( pj_sockaddr_in *addr,
  747. const pj_str_t *cp);
  748. /**
  749. * Set the IP address of an IPv4 or IPv6 socket address from string address,
  750. * with resolving the host if necessary. The string address may be in a
  751. * standard IPv6 or IPv6 address or may be a hostname. If hostname
  752. * is specified, then the function will resolve the host into the IP
  753. * address according to the address family.
  754. *
  755. * @param af Address family.
  756. * @param addr The IP socket address to be set.
  757. * @param cp The address string, which can be in a standard
  758. * IP numbers (IPv4 or IPv6) or a hostname to be resolved.
  759. *
  760. * @return PJ_SUCCESS on success.
  761. */
  762. PJ_DECL(pj_status_t) pj_sockaddr_set_str_addr(int af,
  763. pj_sockaddr *addr,
  764. const pj_str_t *cp);
  765. /**
  766. * Get the port number of a socket address, in host byte order.
  767. * This function can be used for both IPv4 and IPv6 socket address.
  768. *
  769. * @param addr Socket address.
  770. *
  771. * @return Port number, in host byte order.
  772. */
  773. PJ_DECL(pj_uint16_t) pj_sockaddr_get_port(const pj_sockaddr_t *addr);
  774. /**
  775. * Get the transport layer port number of an Internet socket address.
  776. * The port is returned in host byte order.
  777. *
  778. * @param addr The IP socket address.
  779. * @return Port number, in host byte order.
  780. */
  781. PJ_DECL(pj_uint16_t) pj_sockaddr_in_get_port(const pj_sockaddr_in *addr);
  782. /**
  783. * Set the port number of an Internet socket address.
  784. *
  785. * @param addr The socket address.
  786. * @param hostport The port number, in host byte order.
  787. */
  788. PJ_DECL(pj_status_t) pj_sockaddr_set_port(pj_sockaddr *addr,
  789. pj_uint16_t hostport);
  790. /**
  791. * Set the port number of an IPv4 socket address.
  792. *
  793. * @see pj_sockaddr_set_port()
  794. *
  795. * @param addr The IP socket address.
  796. * @param hostport The port number, in host byte order.
  797. */
  798. PJ_DECL(void) pj_sockaddr_in_set_port(pj_sockaddr_in *addr,
  799. pj_uint16_t hostport);
  800. /*****************************************************************************
  801. *
  802. * HOST NAME AND ADDRESS.
  803. *
  804. *****************************************************************************
  805. */
  806. /**
  807. * Get system's host name.
  808. *
  809. * @return The hostname, or empty string if the hostname can not
  810. * be identified.
  811. */
  812. PJ_DECL(const pj_str_t*) pj_gethostname(void);
  813. /**
  814. * Get host's IP address, which the the first IP address that is resolved
  815. * from the hostname.
  816. *
  817. * @return The host's IP address, PJ_INADDR_NONE if the host
  818. * IP address can not be identified.
  819. */
  820. PJ_DECL(pj_in_addr) pj_gethostaddr(void);
  821. /*****************************************************************************
  822. *
  823. * SOCKET API.
  824. *
  825. *****************************************************************************
  826. */
  827. /**
  828. * Create new socket/endpoint for communication.
  829. *
  830. * @param family Specifies a communication domain; this selects the
  831. * protocol family which will be used for communication.
  832. * @param type The socket has the indicated type, which specifies the
  833. * communication semantics.
  834. * @param protocol Specifies a particular protocol to be used with the
  835. * socket. Normally only a single protocol exists to support
  836. * a particular socket type within a given protocol family,
  837. * in which a case protocol can be specified as 0.
  838. * @param sock New socket descriptor, or PJ_INVALID_SOCKET on error.
  839. *
  840. * @return Zero on success.
  841. */
  842. PJ_DECL(pj_status_t) pj_sock_socket(int family,
  843. int type,
  844. int protocol,
  845. pj_sock_t *sock);
  846. /**
  847. * Close the socket descriptor.
  848. *
  849. * @param sockfd The socket descriptor.
  850. *
  851. * @return Zero on success.
  852. */
  853. PJ_DECL(pj_status_t) pj_sock_close(pj_sock_t sockfd);
  854. /**
  855. * This function gives the socket sockfd the local address my_addr. my_addr is
  856. * addrlen bytes long. Traditionally, this is called assigning a name to
  857. * a socket. When a socket is created with #pj_sock_socket(), it exists in a
  858. * name space (address family) but has no name assigned.
  859. *
  860. * @param sockfd The socket desriptor.
  861. * @param my_addr The local address to bind the socket to.
  862. * @param addrlen The length of the address.
  863. *
  864. * @return Zero on success.
  865. */
  866. PJ_DECL(pj_status_t) pj_sock_bind( pj_sock_t sockfd,
  867. const pj_sockaddr_t *my_addr,
  868. int addrlen);
  869. /**
  870. * Bind the IP socket sockfd to the given address and port.
  871. *
  872. * @param sockfd The socket descriptor.
  873. * @param addr Local address to bind the socket to, in host byte order.
  874. * @param port The local port to bind the socket to, in host byte order.
  875. *
  876. * @return Zero on success.
  877. */
  878. PJ_DECL(pj_status_t) pj_sock_bind_in( pj_sock_t sockfd,
  879. pj_uint32_t addr,
  880. pj_uint16_t port);
  881. #if PJ_HAS_TCP
  882. /**
  883. * Listen for incoming connection. This function only applies to connection
  884. * oriented sockets (such as PJ_SOCK_STREAM or PJ_SOCK_SEQPACKET), and it
  885. * indicates the willingness to accept incoming connections.
  886. *
  887. * @param sockfd The socket descriptor.
  888. * @param backlog Defines the maximum length the queue of pending
  889. * connections may grow to.
  890. *
  891. * @return Zero on success.
  892. */
  893. PJ_DECL(pj_status_t) pj_sock_listen( pj_sock_t sockfd,
  894. int backlog );
  895. /**
  896. * Accept new connection on the specified connection oriented server socket.
  897. *
  898. * @param serverfd The server socket.
  899. * @param newsock New socket on success, of PJ_INVALID_SOCKET if failed.
  900. * @param addr A pointer to sockaddr type. If the argument is not NULL,
  901. * it will be filled by the address of connecting entity.
  902. * @param addrlen Initially specifies the length of the address, and upon
  903. * return will be filled with the exact address length.
  904. *
  905. * @return Zero on success, or the error number.
  906. */
  907. PJ_DECL(pj_status_t) pj_sock_accept( pj_sock_t serverfd,
  908. pj_sock_t *newsock,
  909. pj_sockaddr_t *addr,
  910. int *addrlen);
  911. #endif
  912. /**
  913. * The file descriptor sockfd must refer to a socket. If the socket is of
  914. * type PJ_SOCK_DGRAM then the serv_addr address is the address to which
  915. * datagrams are sent by default, and the only address from which datagrams
  916. * are received. If the socket is of type PJ_SOCK_STREAM or PJ_SOCK_SEQPACKET,
  917. * this call attempts to make a connection to another socket. The
  918. * other socket is specified by serv_addr, which is an address (of length
  919. * addrlen) in the communications space of the socket. Each communications
  920. * space interprets the serv_addr parameter in its own way.
  921. *
  922. * @param sockfd The socket descriptor.
  923. * @param serv_addr Server address to connect to.
  924. * @param addrlen The length of server address.
  925. *
  926. * @return Zero on success.
  927. */
  928. PJ_DECL(pj_status_t) pj_sock_connect( pj_sock_t sockfd,
  929. const pj_sockaddr_t *serv_addr,
  930. int addrlen);
  931. /**
  932. * Return the address of peer which is connected to socket sockfd.
  933. *
  934. * @param sockfd The socket descriptor.
  935. * @param addr Pointer to sockaddr structure to which the address
  936. * will be returned.
  937. * @param namelen Initially the length of the addr. Upon return the value
  938. * will be set to the actual length of the address.
  939. *
  940. * @return Zero on success.
  941. */
  942. PJ_DECL(pj_status_t) pj_sock_getpeername(pj_sock_t sockfd,
  943. pj_sockaddr_t *addr,
  944. int *namelen);
  945. /**
  946. * Return the current name of the specified socket.
  947. *
  948. * @param sockfd The socket descriptor.
  949. * @param addr Pointer to sockaddr structure to which the address
  950. * will be returned.
  951. * @param namelen Initially the length of the addr. Upon return the value
  952. * will be set to the actual length of the address.
  953. *
  954. * @return Zero on success.
  955. */
  956. PJ_DECL(pj_status_t) pj_sock_getsockname( pj_sock_t sockfd,
  957. pj_sockaddr_t *addr,
  958. int *namelen);
  959. /**
  960. * Get socket option associated with a socket. Options may exist at multiple
  961. * protocol levels; they are always present at the uppermost socket level.
  962. *
  963. * @param sockfd The socket descriptor.
  964. * @param level The level which to get the option from.
  965. * @param optname The option name.
  966. * @param optval Identifies the buffer which the value will be
  967. * returned.
  968. * @param optlen Initially contains the length of the buffer, upon
  969. * return will be set to the actual size of the value.
  970. *
  971. * @return Zero on success.
  972. */
  973. PJ_DECL(pj_status_t) pj_sock_getsockopt( pj_sock_t sockfd,
  974. pj_uint16_t level,
  975. pj_uint16_t optname,
  976. void *optval,
  977. int *optlen);
  978. /**
  979. * Manipulate the options associated with a socket. Options may exist at
  980. * multiple protocol levels; they are always present at the uppermost socket
  981. * level.
  982. *
  983. * @param sockfd The socket descriptor.
  984. * @param level The level which to get the option from.
  985. * @param optname The option name.
  986. * @param optval Identifies the buffer which contain the value.
  987. * @param optlen The length of the value.
  988. *
  989. * @return PJ_SUCCESS or the status code.
  990. */
  991. PJ_DECL(pj_status_t) pj_sock_setsockopt( pj_sock_t sockfd,
  992. pj_uint16_t level,
  993. pj_uint16_t optname,
  994. const void *optval,
  995. int optlen);
  996. /**
  997. * Receives data stream or message coming to the specified socket.
  998. *
  999. * @param sockfd The socket descriptor.
  1000. * @param buf The buffer to receive the data or message.
  1001. * @param len On input, the length of the buffer. On return,
  1002. * contains the length of data received.
  1003. * @param flags Flags (such as pj_MSG_PEEK()).
  1004. *
  1005. * @return PJ_SUCCESS or the error code.
  1006. */
  1007. PJ_DECL(pj_status_t) pj_sock_recv(pj_sock_t sockfd,
  1008. void *buf,
  1009. pj_ssize_t *len,
  1010. unsigned flags);
  1011. /**
  1012. * Receives data stream or message coming to the specified socket.
  1013. *
  1014. * @param sockfd The socket descriptor.
  1015. * @param buf The buffer to receive the data or message.
  1016. * @param len On input, the length of the buffer. On return,
  1017. * contains the length of data received.
  1018. * @param flags Flags (such as pj_MSG_PEEK()).
  1019. * @param from If not NULL, it will be filled with the source
  1020. * address of the connection.
  1021. * @param fromlen Initially contains the length of from address,
  1022. * and upon return will be filled with the actual
  1023. * length of the address.
  1024. *
  1025. * @return PJ_SUCCESS or the error code.
  1026. */
  1027. PJ_DECL(pj_status_t) pj_sock_recvfrom( pj_sock_t sockfd,
  1028. void *buf,
  1029. pj_ssize_t *len,
  1030. unsigned flags,
  1031. pj_sockaddr_t *from,
  1032. int *fromlen);
  1033. /**
  1034. * Transmit data to the socket.
  1035. *
  1036. * @param sockfd Socket descriptor.
  1037. * @param buf Buffer containing data to be sent.
  1038. * @param len On input, the length of the data in the buffer.
  1039. * Upon return, it will be filled with the length
  1040. * of data sent.
  1041. * @param flags Flags (such as pj_MSG_DONTROUTE()).
  1042. *
  1043. * @return PJ_SUCCESS or the status code.
  1044. */
  1045. PJ_DECL(pj_status_t) pj_sock_send(pj_sock_t sockfd,
  1046. const void *buf,
  1047. pj_ssize_t *len,
  1048. unsigned flags);
  1049. /**
  1050. * Transmit data to the socket to the specified address.
  1051. *
  1052. * @param sockfd Socket descriptor.
  1053. * @param buf Buffer containing data to be sent.
  1054. * @param len On input, the length of the data in the buffer.
  1055. * Upon return, it will be filled with the length
  1056. * of data sent.
  1057. * @param flags Flags (such as pj_MSG_DONTROUTE()).
  1058. * @param to The address to send.
  1059. * @param tolen The length of the address in bytes.
  1060. *
  1061. * @return PJ_SUCCESS or the status code.
  1062. */
  1063. PJ_DECL(pj_status_t) pj_sock_sendto(pj_sock_t sockfd,
  1064. const void *buf,
  1065. pj_ssize_t *len,
  1066. unsigned flags,
  1067. const pj_sockaddr_t *to,
  1068. int tolen);
  1069. #if PJ_HAS_TCP
  1070. /**
  1071. * The shutdown call causes all or part of a full-duplex connection on the
  1072. * socket associated with sockfd to be shut down.
  1073. *
  1074. * @param sockfd The socket descriptor.
  1075. * @param how If how is PJ_SHUT_RD, further receptions will be
  1076. * disallowed. If how is PJ_SHUT_WR, further transmissions
  1077. * will be disallowed. If how is PJ_SHUT_RDWR, further
  1078. * receptions andtransmissions will be disallowed.
  1079. *
  1080. * @return Zero on success.
  1081. */
  1082. PJ_DECL(pj_status_t) pj_sock_shutdown( pj_sock_t sockfd,
  1083. int how);
  1084. #endif
  1085. /**
  1086. * @}
  1087. */
  1088. PJ_END_DECL
  1089. #endif /* __PJ_SOCK_H__ */