BLOG | DOCUMENTATION | TRAC

Home --> Documentations --> PJLIB Reference

sock.h
Go to the documentation of this file.
1 /* $Id$ */
2 /*
3  * Copyright (C) 2008-2011 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 
28 #include <pj/types.h>
29 #include <pj/compat/socket.h>
30 
32 
33 
66 extern const pj_uint16_t PJ_AF_UNSPEC;
67 
69 extern const pj_uint16_t PJ_AF_UNIX;
70 
72 #define PJ_AF_LOCAL PJ_AF_UNIX;
73 
75 extern const pj_uint16_t PJ_AF_INET;
76 
78 extern const pj_uint16_t PJ_AF_INET6;
79 
81 extern const pj_uint16_t PJ_AF_PACKET;
82 
84 extern const pj_uint16_t PJ_AF_IRDA;
85 
86 /*
87  * Accessor functions for various address family constants. These
88  * functions are provided because Symbian doesn't allow exporting
89  * global variables from a DLL.
90  */
91 
92 #if defined(PJ_DLL)
93 
94  PJ_DECL(pj_uint16_t) pj_AF_UNSPEC(void);
96  PJ_DECL(pj_uint16_t) pj_AF_UNIX(void);
98  PJ_DECL(pj_uint16_t) pj_AF_INET(void);
100  PJ_DECL(pj_uint16_t) pj_AF_INET6(void);
102  PJ_DECL(pj_uint16_t) pj_AF_PACKET(void);
104  PJ_DECL(pj_uint16_t) pj_AF_IRDA(void);
105 #else
106  /* When pjlib is not built as DLL, these accessor functions are
107  * simply a macro to get their constants
108  */
110 # define pj_AF_UNSPEC() PJ_AF_UNSPEC
111 
112 # define pj_AF_UNIX() PJ_AF_UNIX
113 
114 # define pj_AF_INET() PJ_AF_INET
115 
116 # define pj_AF_INET6() PJ_AF_INET6
117 
118 # define pj_AF_PACKET() PJ_AF_PACKET
119 
120 # define pj_AF_IRDA() PJ_AF_IRDA
121 #endif
122 
123 
132 extern const pj_uint16_t PJ_SOCK_STREAM;
133 
136 extern const pj_uint16_t PJ_SOCK_DGRAM;
137 
139 extern const pj_uint16_t PJ_SOCK_RAW;
140 
142 extern const pj_uint16_t PJ_SOCK_RDM;
143 
144 
145 /*
146  * Accessor functions for various constants. These functions are provided
147  * because Symbian doesn't allow exporting global variables from a DLL.
148  */
149 
150 #if defined(PJ_DLL)
151 
152  PJ_DECL(int) pj_SOCK_STREAM(void);
154  PJ_DECL(int) pj_SOCK_DGRAM(void);
156  PJ_DECL(int) pj_SOCK_RAW(void);
158  PJ_DECL(int) pj_SOCK_RDM(void);
159 #else
160 
161 # define pj_SOCK_STREAM() PJ_SOCK_STREAM
162 
163 # define pj_SOCK_DGRAM() PJ_SOCK_DGRAM
164 
165 # define pj_SOCK_RAW() PJ_SOCK_RAW
166 
167 # define pj_SOCK_RDM() PJ_SOCK_RDM
168 #endif
169 
170 
177 extern const pj_uint16_t PJ_SOL_SOCKET;
179 extern const pj_uint16_t PJ_SOL_IP;
181 extern const pj_uint16_t PJ_SOL_TCP;
183 extern const pj_uint16_t PJ_SOL_UDP;
185 extern const pj_uint16_t PJ_SOL_IPV6;
186 
187 /*
188  * Accessor functions for various constants. These functions are provided
189  * because Symbian doesn't allow exporting global variables from a DLL.
190  */
191 
192 #if defined(PJ_DLL)
193 
194  PJ_DECL(pj_uint16_t) pj_SOL_SOCKET(void);
196  PJ_DECL(pj_uint16_t) pj_SOL_IP(void);
198  PJ_DECL(pj_uint16_t) pj_SOL_TCP(void);
200  PJ_DECL(pj_uint16_t) pj_SOL_UDP(void);
202  PJ_DECL(pj_uint16_t) pj_SOL_IPV6(void);
203 #else
204 
205 # define pj_SOL_SOCKET() PJ_SOL_SOCKET
206 
207 # define pj_SOL_IP() PJ_SOL_IP
208 
209 # define pj_SOL_TCP() PJ_SOL_TCP
210 
211 # define pj_SOL_UDP() PJ_SOL_UDP
212 
213 # define pj_SOL_IPV6() PJ_SOL_IPV6
214 #endif
215 
216 
217 /* IP_TOS
218  *
219  * Note:
220  * TOS CURRENTLY DOES NOT WORK IN Windows 2000 and above!
221  * See http://support.microsoft.com/kb/248611
222  */
224 extern const pj_uint16_t PJ_IP_TOS;
225 
226 /*
227  * IP TOS related constats.
228  *
229  * Note:
230  * TOS CURRENTLY DOES NOT WORK IN Windows 2000 and above!
231  * See http://support.microsoft.com/kb/248611
232  */
234 extern const pj_uint16_t PJ_IPTOS_LOWDELAY;
235 
237 extern const pj_uint16_t PJ_IPTOS_THROUGHPUT;
238 
240 extern const pj_uint16_t PJ_IPTOS_RELIABILITY;
241 
244 extern const pj_uint16_t PJ_IPTOS_MINCOST;
245 
246 
247 #if defined(PJ_DLL)
248 
249  PJ_DECL(int) pj_IP_TOS(void);
250 
252  PJ_DECL(int) pj_IPTOS_LOWDELAY(void);
253 
255  PJ_DECL(int) pj_IPTOS_THROUGHPUT(void);
256 
258  PJ_DECL(int) pj_IPTOS_RELIABILITY(void);
259 
261  PJ_DECL(int) pj_IPTOS_MINCOST(void);
262 #else
263 
264 # define pj_IP_TOS() PJ_IP_TOS
265 
267 # define pj_IPTOS_LOWDELAY() PJ_IP_TOS_LOWDELAY
268 
270 # define pj_IPTOS_THROUGHPUT() PJ_IP_TOS_THROUGHPUT
271 
273 # define pj_IPTOS_RELIABILITY() PJ_IP_TOS_RELIABILITY
274 
276 # define pj_IPTOS_MINCOST() PJ_IP_TOS_MINCOST
277 #endif
278 
279 
281 extern const pj_uint16_t PJ_IPV6_TCLASS;
282 
283 
284 #if defined(PJ_DLL)
285 
286  PJ_DECL(int) pj_IPV6_TCLASS(void);
287 #else
288 
289 # define pj_IPV6_TCLASS() PJ_IPV6_TCLASS
290 #endif
291 
292 
299 extern const pj_uint16_t PJ_SO_TYPE;
300 
302 extern const pj_uint16_t PJ_SO_RCVBUF;
303 
305 extern const pj_uint16_t PJ_SO_SNDBUF;
306 
308 extern const pj_uint16_t PJ_TCP_NODELAY;
309 
312 extern const pj_uint16_t PJ_SO_REUSEADDR;
313 
315 extern const pj_uint16_t PJ_SO_NOSIGPIPE;
316 
319 extern const pj_uint16_t PJ_SO_PRIORITY;
320 
322 extern const pj_uint16_t PJ_IP_MULTICAST_IF;
323 
325 extern const pj_uint16_t PJ_IP_MULTICAST_TTL;
326 
328 extern const pj_uint16_t PJ_IP_MULTICAST_LOOP;
329 
331 extern const pj_uint16_t PJ_IP_ADD_MEMBERSHIP;
332 
335 
336 
337 #if defined(PJ_DLL)
338 
339  PJ_DECL(pj_uint16_t) pj_SO_TYPE(void);
340 
342  PJ_DECL(pj_uint16_t) pj_SO_RCVBUF(void);
343 
345  PJ_DECL(pj_uint16_t) pj_SO_SNDBUF(void);
346 
348  PJ_DECL(pj_uint16_t) pj_TCP_NODELAY(void);
349 
351  PJ_DECL(pj_uint16_t) pj_SO_REUSEADDR(void);
352 
354  PJ_DECL(pj_uint16_t) pj_SO_NOSIGPIPE(void);
355 
357  PJ_DECL(pj_uint16_t) pj_SO_PRIORITY(void);
358 
360  PJ_DECL(pj_uint16_t) pj_IP_MULTICAST_IF(void);
361 
363  PJ_DECL(pj_uint16_t) pj_IP_MULTICAST_TTL(void);
364 
366  PJ_DECL(pj_uint16_t) pj_IP_MULTICAST_LOOP(void);
367 
369  PJ_DECL(pj_uint16_t) pj_IP_ADD_MEMBERSHIP(void);
370 
372  PJ_DECL(pj_uint16_t) pj_IP_DROP_MEMBERSHIP(void);
373 #else
374 
375 # define pj_SO_TYPE() PJ_SO_TYPE
376 
378 # define pj_SO_RCVBUF() PJ_SO_RCVBUF
379 
381 # define pj_SO_SNDBUF() PJ_SO_SNDBUF
382 
384 # define pj_TCP_NODELAY() PJ_TCP_NODELAY
385 
387 # define pj_SO_REUSEADDR() PJ_SO_REUSEADDR
388 
390 # define pj_SO_NOSIGPIPE() PJ_SO_NOSIGPIPE
391 
393 # define pj_SO_PRIORITY() PJ_SO_PRIORITY
394 
396 # define pj_IP_MULTICAST_IF() PJ_IP_MULTICAST_IF
397 
399 # define pj_IP_MULTICAST_TTL() PJ_IP_MULTICAST_TTL
400 
402 # define pj_IP_MULTICAST_LOOP() PJ_IP_MULTICAST_LOOP
403 
405 # define pj_IP_ADD_MEMBERSHIP() PJ_IP_ADD_MEMBERSHIP
406 
408 # define pj_IP_DROP_MEMBERSHIP() PJ_IP_DROP_MEMBERSHIP
409 #endif
410 
411 
412 /*
413  * Flags to be specified in #pj_sock_recv, #pj_sock_send, etc.
414  */
415 
417 extern const int PJ_MSG_OOB;
418 
420 extern const int PJ_MSG_PEEK;
421 
423 extern const int PJ_MSG_DONTROUTE;
424 
425 
426 #if defined(PJ_DLL)
427 
428  PJ_DECL(int) pj_MSG_OOB(void);
429 
431  PJ_DECL(int) pj_MSG_PEEK(void);
432 
434  PJ_DECL(int) pj_MSG_DONTROUTE(void);
435 #else
436 
437 # define pj_MSG_OOB() PJ_MSG_OOB
438 
440 # define pj_MSG_PEEK() PJ_MSG_PEEK
441 
443 # define pj_MSG_DONTROUTE() PJ_MSG_DONTROUTE
444 #endif
445 
446 
450 typedef enum pj_socket_sd_type
451 {
459 
460 
461 
463 #define PJ_INADDR_ANY ((pj_uint32_t)0)
464 
466 #define PJ_INADDR_NONE ((pj_uint32_t)0xffffffff)
467 
469 #define PJ_INADDR_BROADCAST ((pj_uint32_t)0xffffffff)
470 
471 
477 #if !defined(PJ_SOMAXCONN)
478 # define PJ_SOMAXCONN 5
479 #endif
480 
481 
486 #define PJ_INVALID_SOCKET (-1)
487 
488 /* Undefining UNIX standard library macro such as s_addr is not
489  * recommended as it may cause build issues for anyone who uses
490  * the macro. See #2311 for more details.
491  */
492 #if 0
493 /* Must undefine s_addr because of pj_in_addr below */
494 #undef s_addr
495 
499 typedef struct pj_in_addr
500 {
501  pj_uint32_t s_addr;
502 } pj_in_addr;
503 
504 #else
505 typedef struct in_addr pj_in_addr;
506 #endif
507 
511 #define PJ_INET_ADDRSTRLEN 16
512 
516 #define PJ_INET6_ADDRSTRLEN 46
517 
522 #ifndef PJ_SOCKADDR_IN_SIN_ZERO_LEN
523 # define PJ_SOCKADDR_IN_SIN_ZERO_LEN 8
524 #endif
525 
535 {
536 #if defined(PJ_SOCKADDR_HAS_LEN) && PJ_SOCKADDR_HAS_LEN!=0
537  pj_uint8_t sin_zero_len;
538  pj_uint8_t sin_family;
539 #else
541 #endif
543  pj_in_addr sin_addr;
544  char sin_zero_pad[PJ_SOCKADDR_IN_SIN_ZERO_LEN];
545 };
546 
547 
548 /* Undefining C standard library macro such as s6_addr is not
549  * recommended as it may cause build issues for anyone who uses
550  * the macro. See #2311 for more details.
551  */
552 #if 0
553 #undef s6_addr
554 
558 typedef union pj_in6_addr
559 {
560  /* This is the main entry */
561  pj_uint8_t s6_addr[16];
563  /* While these are used for proper alignment */
564  pj_uint32_t u6_addr32[4];
565 
566  /* Do not use this with Winsock2, as this will align pj_sockaddr_in6
567  * to 64-bit boundary and Winsock2 doesn't like it!
568  * Update 26/04/2010:
569  * This is now disabled, see http://trac.pjsip.org/repos/ticket/1058
570  */
571 #if 0 && defined(PJ_HAS_INT64) && PJ_HAS_INT64!=0 && \
572  (!defined(PJ_WIN32) || PJ_WIN32==0)
573  pj_int64_t u6_addr64[2];
574 #endif
575 
576 } pj_in6_addr;
577 #else
578 typedef struct in6_addr pj_in6_addr;
579 #endif
580 
581 
583 #define PJ_IN6ADDR_ANY_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } }
584 
586 #define PJ_IN6ADDR_LOOPBACK_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } }
587 
596 typedef struct pj_sockaddr_in6
597 {
598 #if defined(PJ_SOCKADDR_HAS_LEN) && PJ_SOCKADDR_HAS_LEN!=0
599  pj_uint8_t sin6_zero_len;
600  pj_uint8_t sin6_family;
601 #else
603 #endif
606  pj_in6_addr sin6_addr;
609 
610 
619 typedef struct pj_addr_hdr
620 {
621 #if defined(PJ_SOCKADDR_HAS_LEN) && PJ_SOCKADDR_HAS_LEN!=0
622  pj_uint8_t sa_zero_len;
623  pj_uint8_t sa_family;
624 #else
626 #endif
627 } pj_addr_hdr;
628 
629 
633 typedef union pj_sockaddr
634 {
638 } pj_sockaddr;
639 
640 
644 typedef struct pj_ip_mreq {
645  pj_in_addr imr_multiaddr;
646  pj_in_addr imr_interface;
647 } pj_ip_mreq;
648 
649 
653 typedef struct pj_sockopt_params
654 {
655  /* The number of options to be applied. */
656  unsigned cnt;
657 
658  /* Array of options to be applied. */
659  struct {
660  /* The level at which the option is defined. */
661  int level;
662 
663  /* Option name. */
664  int optname;
665 
666  /* Pointer to the buffer in which the option is specified. */
667  void *optval;
668 
669  /* Buffer size of the buffer pointed by optval. */
670  int optlen;
671  } options[PJ_MAX_SOCKOPT_PARAMS];
673 
674 /*****************************************************************************
675  *
676  * SOCKET ADDRESS MANIPULATION.
677  *
678  *****************************************************************************
679  */
680 
687 PJ_DECL(pj_uint16_t) pj_ntohs(pj_uint16_t netshort);
688 
695 PJ_DECL(pj_uint16_t) pj_htons(pj_uint16_t hostshort);
696 
703 PJ_DECL(pj_uint32_t) pj_ntohl(pj_uint32_t netlong);
704 
711 PJ_DECL(pj_uint32_t) pj_htonl(pj_uint32_t hostlong);
712 
720 PJ_DECL(char*) pj_inet_ntoa(pj_in_addr inaddr);
721 
732 PJ_DECL(int) pj_inet_aton(const pj_str_t *cp, pj_in_addr *inp);
733 
749 PJ_DECL(pj_status_t) pj_inet_pton(int af, const pj_str_t *src, void *dst);
750 
770 PJ_DECL(pj_status_t) pj_inet_ntop(int af, const void *src,
771  char *dst, int size);
772 
790 PJ_DECL(char*) pj_inet_ntop2(int af, const void *src,
791  char *dst, int size);
792 
805 PJ_DECL(char*) pj_sockaddr_print(const pj_sockaddr_t *addr,
806  char *buf, int size,
807  unsigned flags);
808 
821 PJ_DECL(pj_in_addr) pj_inet_addr(const pj_str_t *cp);
822 
835 PJ_DECL(pj_in_addr) pj_inet_addr2(const char *cp);
836 
853  const pj_str_t *cp,
854  pj_uint16_t port);
855 
872 PJ_DECL(pj_status_t) pj_sockaddr_init(int af,
873  pj_sockaddr *addr,
874  const pj_str_t *cp,
875  pj_uint16_t port);
876 
886 PJ_DECL(int) pj_sockaddr_cmp(const pj_sockaddr_t *addr1,
887  const pj_sockaddr_t *addr2);
888 
897 PJ_DECL(void*) pj_sockaddr_get_addr(const pj_sockaddr_t *addr);
898 
906 PJ_DECL(pj_bool_t) pj_sockaddr_has_addr(const pj_sockaddr_t *addr);
907 
917 PJ_DECL(unsigned) pj_sockaddr_get_addr_len(const pj_sockaddr_t *addr);
918 
928 PJ_DECL(unsigned) pj_sockaddr_get_len(const pj_sockaddr_t *addr);
929 
938 PJ_DECL(void) pj_sockaddr_copy_addr(pj_sockaddr *dst,
939  const pj_sockaddr *src);
949 PJ_DECL(void) pj_sockaddr_cp(pj_sockaddr_t *dst, const pj_sockaddr_t *src);
950 
951 /*
952  * If the source's and desired address family matches, copy the address,
953  * otherwise synthesize a new address with the desired address family,
954  * from the source address. This can be useful to generate an IPv4-mapped
955  * IPv6 address.
956  *
957  * @param dst_af Desired address family.
958  * @param dst Destination socket address, invalid if synthesis is
959  * required and failed.
960  * @param src Source socket address.
961  *
962  * @return PJ_SUCCESS on success, or the error status
963  * if synthesis is required and failed.
964  */
965 PJ_DECL(pj_status_t) pj_sockaddr_synthesize(int dst_af,
966  pj_sockaddr_t *dst,
967  const pj_sockaddr_t *src);
968 
976 PJ_DECL(pj_in_addr) pj_sockaddr_in_get_addr(const pj_sockaddr_in *addr);
977 
984 PJ_DECL(void) pj_sockaddr_in_set_addr(pj_sockaddr_in *addr,
985  pj_uint32_t hostaddr);
986 
1003  const pj_str_t *cp);
1004 
1019 PJ_DECL(pj_status_t) pj_sockaddr_set_str_addr(int af,
1020  pj_sockaddr *addr,
1021  const pj_str_t *cp);
1022 
1031 PJ_DECL(pj_uint16_t) pj_sockaddr_get_port(const pj_sockaddr_t *addr);
1032 
1040 PJ_DECL(pj_uint16_t) pj_sockaddr_in_get_port(const pj_sockaddr_in *addr);
1041 
1049  pj_uint16_t hostport);
1050 
1059 PJ_DECL(void) pj_sockaddr_in_set_port(pj_sockaddr_in *addr,
1060  pj_uint16_t hostport);
1061 
1112 PJ_DECL(pj_status_t) pj_sockaddr_parse(int af, unsigned options,
1113  const pj_str_t *str,
1114  pj_sockaddr *addr);
1115 
1144 PJ_DECL(pj_status_t) pj_sockaddr_parse2(int af, unsigned options,
1145  const pj_str_t *str,
1146  pj_str_t *hostpart,
1147  pj_uint16_t *port,
1148  int *raf);
1149 
1150 /*****************************************************************************
1151  *
1152  * HOST NAME AND ADDRESS.
1153  *
1154  *****************************************************************************
1155  */
1156 
1163 PJ_DECL(const pj_str_t*) pj_gethostname(void);
1164 
1172 PJ_DECL(pj_in_addr) pj_gethostaddr(void);
1173 
1174 
1175 /*****************************************************************************
1176  *
1177  * SOCKET API.
1178  *
1179  *****************************************************************************
1180  */
1181 
1197 PJ_DECL(pj_status_t) pj_sock_socket(int family,
1198  int type,
1199  int protocol,
1200  pj_sock_t *sock);
1201 
1209 PJ_DECL(pj_status_t) pj_sock_close(pj_sock_t sockfd);
1210 
1211 
1224 PJ_DECL(pj_status_t) pj_sock_bind( pj_sock_t sockfd,
1225  const pj_sockaddr_t *my_addr,
1226  int addrlen);
1227 
1237 PJ_DECL(pj_status_t) pj_sock_bind_in( pj_sock_t sockfd,
1238  pj_uint32_t addr,
1239  pj_uint16_t port);
1240 
1254 PJ_DECL(pj_status_t) pj_sock_bind_random( pj_sock_t sockfd,
1255  const pj_sockaddr_t *addr,
1256  pj_uint16_t port_range,
1257  pj_uint16_t max_try);
1258 
1259 #if PJ_HAS_TCP
1260 
1271 PJ_DECL(pj_status_t) pj_sock_listen( pj_sock_t sockfd,
1272  int backlog );
1273 
1286 PJ_DECL(pj_status_t) pj_sock_accept( pj_sock_t serverfd,
1287  pj_sock_t *newsock,
1288  pj_sockaddr_t *addr,
1289  int *addrlen);
1290 #endif
1291 
1308 PJ_DECL(pj_status_t) pj_sock_connect( pj_sock_t sockfd,
1309  const pj_sockaddr_t *serv_addr,
1310  int addrlen);
1311 
1323 PJ_DECL(pj_status_t) pj_sock_getpeername(pj_sock_t sockfd,
1324  pj_sockaddr_t *addr,
1325  int *namelen);
1326 
1338 PJ_DECL(pj_status_t) pj_sock_getsockname( pj_sock_t sockfd,
1339  pj_sockaddr_t *addr,
1340  int *namelen);
1341 
1356 PJ_DECL(pj_status_t) pj_sock_getsockopt( pj_sock_t sockfd,
1357  pj_uint16_t level,
1358  pj_uint16_t optname,
1359  void *optval,
1360  int *optlen);
1374 PJ_DECL(pj_status_t) pj_sock_setsockopt( pj_sock_t sockfd,
1375  pj_uint16_t level,
1376  pj_uint16_t optname,
1377  const void *optval,
1378  int optlen);
1379 
1390  const pj_sockopt_params *params);
1391 
1408  pj_uint16_t optname,
1409  pj_bool_t auto_retry,
1410  unsigned *buf_size);
1411 
1412 
1424 PJ_DECL(pj_status_t) pj_sock_recv(pj_sock_t sockfd,
1425  void *buf,
1426  pj_ssize_t *len,
1427  unsigned flags);
1428 
1445 PJ_DECL(pj_status_t) pj_sock_recvfrom( pj_sock_t sockfd,
1446  void *buf,
1447  pj_ssize_t *len,
1448  unsigned flags,
1449  pj_sockaddr_t *from,
1450  int *fromlen);
1451 
1464 PJ_DECL(pj_status_t) pj_sock_send(pj_sock_t sockfd,
1465  const void *buf,
1466  pj_ssize_t *len,
1467  unsigned flags);
1468 
1483 PJ_DECL(pj_status_t) pj_sock_sendto(pj_sock_t sockfd,
1484  const void *buf,
1485  pj_ssize_t *len,
1486  unsigned flags,
1487  const pj_sockaddr_t *to,
1488  int tolen);
1489 
1490 #if PJ_HAS_TCP
1491 
1503 PJ_DECL(pj_status_t) pj_sock_shutdown( pj_sock_t sockfd,
1504  int how);
1505 #endif
1506 
1507 /*****************************************************************************
1508  *
1509  * Utilities.
1510  *
1511  *****************************************************************************
1512  */
1513 
1527 PJ_DECL(char *) pj_addr_str_print( const pj_str_t *host_str, int port,
1528  char *buf, int size, unsigned flag);
1529 
1530 
1537 
1538 #endif /* __PJ_SOCK_H__ */
1539 
const pj_uint16_t PJ_IP_DROP_MEMBERSHIP
pj_uint16_t sin_family
Definition: sock.h:540
const pj_uint16_t PJ_SO_RCVBUF
pj_in_addr sin_addr
Definition: sock.h:543
pj_uint16_t pj_ntohs(pj_uint16_t netshort)
const pj_uint16_t PJ_AF_INET6
const pj_uint16_t PJ_IPV6_TCLASS
#define pj_IPTOS_RELIABILITY()
Definition: sock.h:273
const pj_uint16_t PJ_TCP_NODELAY
pj_status_t pj_sock_setsockopt_params(pj_sock_t sockfd, const pj_sockopt_params *params)
const pj_uint16_t PJ_SO_PRIORITY
#define pj_AF_UNIX()
Definition: sock.h:112
pj_status_t pj_sock_close(pj_sock_t sockfd)
Definition: sock.h:454
pj_addr_hdr addr
Definition: sock.h:635
pj_status_t pj_sock_shutdown(pj_sock_t sockfd, int how)
pj_uint16_t pj_sockaddr_in_get_port(const pj_sockaddr_in *addr)
pj_status_t pj_sockaddr_in_set_str_addr(pj_sockaddr_in *addr, const pj_str_t *cp)
#define pj_SO_NOSIGPIPE()
Definition: sock.h:390
int pj_bool_t
Definition: types.h:71
#define pj_TCP_NODELAY()
Definition: sock.h:384
Definition: sock.h:653
pj_uint16_t sin_port
Definition: sock.h:542
const int PJ_MSG_DONTROUTE
const pj_uint16_t PJ_SOCK_DGRAM
pj_status_t pj_sock_recvfrom(pj_sock_t sockfd, void *buf, pj_ssize_t *len, unsigned flags, pj_sockaddr_t *from, int *fromlen)
#define pj_SO_TYPE()
Definition: sock.h:375
#define pj_IPTOS_MINCOST()
Definition: sock.h:276
#define pj_IPV6_TCLASS()
Definition: sock.h:289
#define pj_AF_INET()
Definition: sock.h:114
pj_status_t pj_sock_connect(pj_sock_t sockfd, const pj_sockaddr_t *serv_addr, int addrlen)
pj_status_t pj_sock_getsockopt(pj_sock_t sockfd, pj_uint16_t level, pj_uint16_t optname, void *optval, int *optlen)
pj_in_addr pj_inet_addr(const pj_str_t *cp)
const pj_uint16_t PJ_SOL_IP
pj_socket_sd_type
Definition: sock.h:450
pj_in_addr pj_gethostaddr(void)
pj_uint16_t sin6_port
Definition: sock.h:604
#define pj_SOL_IPV6()
Definition: sock.h:213
pj_uint32_t sin6_scope_id
Definition: sock.h:607
#define PJ_MAX_SOCKOPT_PARAMS
Definition: config.h:1081
pj_status_t pj_inet_pton(int af, const pj_str_t *src, void *dst)
#define PJ_SOCKADDR_IN_SIN_ZERO_LEN
Definition: sock.h:523
const pj_uint16_t PJ_SOCK_RAW
pj_status_t pj_sockaddr_parse(int af, unsigned options, const pj_str_t *str, pj_sockaddr *addr)
#define pj_SO_PRIORITY()
Definition: sock.h:393
int pj_inet_aton(const pj_str_t *cp, pj_in_addr *inp)
pj_in_addr imr_interface
Definition: sock.h:646
pj_in_addr pj_sockaddr_in_get_addr(const pj_sockaddr_in *addr)
const pj_uint16_t PJ_SO_TYPE
Declaration of basic types and utility.
#define pj_IP_DROP_MEMBERSHIP()
Definition: sock.h:408
int pj_status_t
Definition: types.h:68
pj_uint16_t pj_htons(pj_uint16_t hostshort)
Definition: sock.h:633
pj_bool_t pj_sockaddr_has_addr(const pj_sockaddr_t *addr)
const pj_uint16_t PJ_SO_SNDBUF
pj_uint16_t sa_family
Definition: sock.h:625
void pj_sockaddr_t
Definition: types.h:267
void pj_sockaddr_copy_addr(pj_sockaddr *dst, const pj_sockaddr *src)
Definition: types.h:119
pj_status_t pj_sockaddr_parse2(int af, unsigned options, const pj_str_t *str, pj_str_t *hostpart, pj_uint16_t *port, int *raf)
pj_uint32_t sin6_flowinfo
Definition: sock.h:605
pj_status_t pj_sock_setsockopt_sobuf(pj_sock_t sockfd, pj_uint16_t optname, pj_bool_t auto_retry, unsigned *buf_size)
const int PJ_MSG_PEEK
pj_status_t pj_sockaddr_in_init(pj_sockaddr_in *addr, const pj_str_t *cp, pj_uint16_t port)
const pj_uint16_t PJ_IPTOS_RELIABILITY
const pj_uint16_t PJ_SOL_UDP
const pj_uint16_t PJ_SOCK_STREAM
#define pj_SOCK_DGRAM()
Definition: sock.h:163
void pj_sockaddr_in_set_port(pj_sockaddr_in *addr, pj_uint16_t hostport)
Definition: sock.h:453
pj_uint32_t pj_ntohl(pj_uint32_t netlong)
#define pj_SOL_IP()
Definition: sock.h:207
unsigned int pj_uint32_t
Definition: types.h:43
const pj_uint16_t PJ_IPTOS_MINCOST
pj_status_t pj_sock_accept(pj_sock_t serverfd, pj_sock_t *newsock, pj_sockaddr_t *addr, int *addrlen)
void pj_sockaddr_in_set_addr(pj_sockaddr_in *addr, pj_uint32_t hostaddr)
const pj_uint16_t PJ_SOL_IPV6
const pj_uint16_t PJ_IPTOS_LOWDELAY
#define pj_MSG_DONTROUTE()
Definition: sock.h:443
const pj_uint16_t PJ_SO_REUSEADDR
#define pj_SO_RCVBUF()
Definition: sock.h:378
#define pj_AF_UNSPEC()
Definition: sock.h:110
const pj_uint16_t PJ_SO_NOSIGPIPE
#define PJ_END_DECL
Definition: config.h:1281
pj_in_addr pj_inet_addr2(const char *cp)
Definition: sock.h:452
const pj_str_t * pj_gethostname(void)
const pj_uint16_t PJ_AF_IRDA
pj_status_t pj_sock_send(pj_sock_t sockfd, const void *buf, pj_ssize_t *len, unsigned flags)
#define pj_SOCK_RAW()
Definition: sock.h:165
const pj_uint16_t PJ_SOCK_RDM
const pj_uint16_t PJ_AF_UNIX
pj_status_t pj_sock_bind_in(pj_sock_t sockfd, pj_uint32_t addr, pj_uint16_t port)
pj_status_t pj_sock_bind_random(pj_sock_t sockfd, const pj_sockaddr_t *addr, pj_uint16_t port_range, pj_uint16_t max_try)
#define pj_SOL_TCP()
Definition: sock.h:209
pj_status_t pj_sock_setsockopt(pj_sock_t sockfd, pj_uint16_t level, pj_uint16_t optname, const void *optval, int optlen)
#define pj_IP_ADD_MEMBERSHIP()
Definition: sock.h:405
#define pj_MSG_PEEK()
Definition: sock.h:440
pj_sockaddr_in6 ipv6
Definition: sock.h:637
#define PJ_BEGIN_DECL
Definition: config.h:1280
long pj_sock_t
Definition: types.h:263
void pj_sockaddr_cp(pj_sockaddr_t *dst, const pj_sockaddr_t *src)
pj_status_t pj_sockaddr_set_port(pj_sockaddr *addr, pj_uint16_t hostport)
unsigned pj_sockaddr_get_addr_len(const pj_sockaddr_t *addr)
Definition: sock.h:456
#define pj_SOL_SOCKET()
Definition: sock.h:205
long pj_ssize_t
Definition: types.h:64
pj_status_t pj_sockaddr_init(int af, pj_sockaddr *addr, const pj_str_t *cp, pj_uint16_t port)
#define pj_AF_PACKET()
Definition: sock.h:118
const pj_uint16_t PJ_AF_UNSPEC
char * pj_sockaddr_print(const pj_sockaddr_t *addr, char *buf, int size, unsigned flags)
const pj_uint16_t PJ_IP_MULTICAST_TTL
Definition: sock.h:455
pj_status_t pj_sock_bind(pj_sock_t sockfd, const pj_sockaddr_t *my_addr, int addrlen)
#define pj_AF_IRDA()
Definition: sock.h:120
#define pj_IPTOS_THROUGHPUT()
Definition: sock.h:270
const pj_uint16_t PJ_IP_TOS
unsigned char pj_uint8_t
Definition: types.h:55
int pj_sockaddr_cmp(const pj_sockaddr_t *addr1, const pj_sockaddr_t *addr2)
char * pj_addr_str_print(const pj_str_t *host_str, int port, char *buf, int size, unsigned flag)
const pj_uint16_t PJ_IPTOS_THROUGHPUT
char * pj_inet_ntoa(pj_in_addr inaddr)
Definition: sock.h:596
pj_status_t pj_sock_socket(int family, int type, int protocol, pj_sock_t *sock)
const pj_uint16_t PJ_AF_PACKET
pj_status_t pj_sockaddr_set_str_addr(int af, pj_sockaddr *addr, const pj_str_t *cp)
char * pj_inet_ntop2(int af, const void *src, char *dst, int size)
pj_uint16_t pj_sockaddr_get_port(const pj_sockaddr_t *addr)
#define pj_IP_TOS()
Definition: sock.h:264
Definition: sock.h:457
const pj_uint16_t PJ_SOL_TCP
pj_status_t pj_sock_sendto(pj_sock_t sockfd, const void *buf, pj_ssize_t *len, unsigned flags, const pj_sockaddr_t *to, int tolen)
const pj_uint16_t PJ_IP_MULTICAST_LOOP
unsigned pj_sockaddr_get_len(const pj_sockaddr_t *addr)
pj_sockaddr_in ipv4
Definition: sock.h:636
#define pj_IPTOS_LOWDELAY()
Definition: sock.h:267
const int PJ_MSG_OOB
pj_status_t pj_sock_recv(pj_sock_t sockfd, void *buf, pj_ssize_t *len, unsigned flags)
pj_status_t pj_sock_getpeername(pj_sock_t sockfd, pj_sockaddr_t *addr, int *namelen)
#define pj_AF_INET6()
Definition: sock.h:116
#define pj_IP_MULTICAST_LOOP()
Definition: sock.h:402
const pj_uint16_t PJ_AF_INET
pj_status_t pj_sock_getsockname(pj_sock_t sockfd, pj_sockaddr_t *addr, int *namelen)
pj_status_t pj_inet_ntop(int af, const void *src, char *dst, int size)
#define pj_SOCK_RDM()
Definition: sock.h:167
#define pj_SO_REUSEADDR()
Definition: sock.h:387
Definition: sock.h:534
const pj_uint16_t PJ_SOL_SOCKET
#define pj_IP_MULTICAST_IF()
Definition: sock.h:396
#define pj_SO_SNDBUF()
Definition: sock.h:381
#define pj_MSG_OOB()
Definition: sock.h:437
unsigned short pj_uint16_t
Definition: types.h:49
pj_uint32_t pj_htonl(pj_uint32_t hostlong)
pj_uint16_t sin6_family
Definition: sock.h:602
const pj_uint16_t PJ_IP_MULTICAST_IF
Definition: sock.h:619
Definition: sock.h:644
#define pj_SOCK_STREAM()
Definition: sock.h:161
pj_in_addr imr_multiaddr
Definition: sock.h:645
pj_in6_addr sin6_addr
Definition: sock.h:606
void * pj_sockaddr_get_addr(const pj_sockaddr_t *addr)
const pj_uint16_t PJ_IP_ADD_MEMBERSHIP
pj_status_t pj_sock_listen(pj_sock_t sockfd, int backlog)
#define pj_SOL_UDP()
Definition: sock.h:211
#define pj_IP_MULTICAST_TTL()
Definition: sock.h:399

 


PJLIB Open Source, high performance, small footprint, and very very portable framework
Copyright (C) 2006-2009 Teluu Inc.