Home --> Documentations --> PJNATH Reference

pjturn-client, a sample TURN client

This is a simple, interactive TURN client application, with the following features:

  • DNS SRV resolution
  • TCP connection to TURN server
  • Optional fingerprint

This file is pjnath/src/pjturn-client/client_main.c.

Screenshot on WinXP:

pjturn_client.jpg
pjturn_client on WinXP
1 /* $Id: client_main.c 3553 2011-05-05 06:14:19Z nanang $ */
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 #include <pjnath.h>
21 #include <pjlib-util.h>
22 #include <pjlib.h>
23 
24 
25 #define THIS_FILE "client_main.c"
26 #define LOCAL_PORT 1998
27 #define BANDWIDTH 64 /* -1 to disable */
28 #define LIFETIME 600 /* -1 to disable */
29 #define REQ_TRANSPORT -1 /* 0: udp, 1: tcp, -1: disable */
30 #define REQ_PORT_PROPS -1 /* -1 to disable */
31 #define REQ_IP 0 /* IP address string */
32 
33 //#define OPTIONS PJ_STUN_NO_AUTHENTICATE
34 #define OPTIONS 0
35 
36 
37 struct peer
38 {
39  pj_stun_sock *stun_sock;
40  pj_sockaddr mapped_addr;
41 };
42 
43 
44 static struct global
45 {
46  pj_caching_pool cp;
47  pj_pool_t *pool;
48  pj_stun_config stun_config;
49  pj_thread_t *thread;
50  pj_bool_t quit;
51 
52  pj_dns_resolver *resolver;
53 
54  pj_turn_sock *relay;
55  pj_sockaddr relay_addr;
56 
57  struct peer peer[2];
58 } g;
59 
60 static struct options
61 {
62  pj_bool_t use_tcp;
63  char *srv_addr;
64  char *srv_port;
65  char *realm;
66  char *user_name;
67  char *password;
68  pj_bool_t use_fingerprint;
69  char *stun_server;
70  char *nameserver;
71 } o;
72 
73 
74 static int worker_thread(void *unused);
75 static void turn_on_rx_data(pj_turn_sock *relay,
76  void *pkt,
77  unsigned pkt_len,
78  const pj_sockaddr_t *peer_addr,
79  unsigned addr_len);
80 static void turn_on_state(pj_turn_sock *relay, pj_turn_state_t old_state,
81  pj_turn_state_t new_state);
82 static pj_bool_t stun_sock_on_status(pj_stun_sock *stun_sock,
83  pj_stun_sock_op op,
84  pj_status_t status);
85 static pj_bool_t stun_sock_on_rx_data(pj_stun_sock *stun_sock,
86  void *pkt,
87  unsigned pkt_len,
88  const pj_sockaddr_t *src_addr,
89  unsigned addr_len);
90 
91 
92 static void my_perror(const char *title, pj_status_t status)
93 {
94  char errmsg[PJ_ERR_MSG_SIZE];
95  pj_strerror(status, errmsg, sizeof(errmsg));
96 
97  PJ_LOG(3,(THIS_FILE, "%s: %s", title, errmsg));
98 }
99 
100 #define CHECK(expr) status=expr; \
101  if (status!=PJ_SUCCESS) { \
102  my_perror(#expr, status); \
103  return status; \
104  }
105 
106 static int init()
107 {
108  int i;
109  pj_status_t status;
110 
111  CHECK( pj_init() );
112  CHECK( pjlib_util_init() );
113  CHECK( pjnath_init() );
114 
115  /* Check that server is specified */
116  if (!o.srv_addr) {
117  printf("Error: server must be specified\n");
118  return PJ_EINVAL;
119  }
120 
122 
123  g.pool = pj_pool_create(&g.cp.factory, "main", 1000, 1000, NULL);
124 
125  /* Init global STUN config */
126  pj_stun_config_init(&g.stun_config, &g.cp.factory, 0, NULL, NULL);
127 
128  /* Create global timer heap */
129  CHECK( pj_timer_heap_create(g.pool, 1000, &g.stun_config.timer_heap) );
130 
131  /* Create global ioqueue */
132  CHECK( pj_ioqueue_create(g.pool, 16, &g.stun_config.ioqueue) );
133 
134  /*
135  * Create peers
136  */
137  for (i=0; i<(int)PJ_ARRAY_SIZE(g.peer); ++i) {
138  pj_stun_sock_cb stun_sock_cb;
139  char name[] = "peer0";
140  pj_uint16_t port;
141  pj_stun_sock_cfg ss_cfg;
142  pj_str_t server;
143 
144  pj_bzero(&stun_sock_cb, sizeof(stun_sock_cb));
145  stun_sock_cb.on_rx_data = &stun_sock_on_rx_data;
146  stun_sock_cb.on_status = &stun_sock_on_status;
147 
148  g.peer[i].mapped_addr.addr.sa_family = pj_AF_INET();
149 
150  pj_stun_sock_cfg_default(&ss_cfg);
151 #if 1
152  /* make reading the log easier */
153  ss_cfg.ka_interval = 300;
154 #endif
155 
156  name[strlen(name)-1] = '0'+i;
157  status = pj_stun_sock_create(&g.stun_config, name, pj_AF_INET(),
158  &stun_sock_cb, &ss_cfg,
159  &g.peer[i], &g.peer[i].stun_sock);
160  if (status != PJ_SUCCESS) {
161  my_perror("pj_stun_sock_create()", status);
162  return status;
163  }
164 
165  if (o.stun_server) {
166  server = pj_str(o.stun_server);
167  port = PJ_STUN_PORT;
168  } else {
169  server = pj_str(o.srv_addr);
170  port = (pj_uint16_t)(o.srv_port?atoi(o.srv_port):PJ_STUN_PORT);
171  }
172  status = pj_stun_sock_start(g.peer[i].stun_sock, &server,
173  port, NULL);
174  if (status != PJ_SUCCESS) {
175  my_perror("pj_stun_sock_start()", status);
176  return status;
177  }
178  }
179 
180  /* Start the worker thread */
181  CHECK( pj_thread_create(g.pool, "stun", &worker_thread, NULL, 0, 0, &g.thread) );
182 
183 
184  return PJ_SUCCESS;
185 }
186 
187 
188 static int client_shutdown()
189 {
190  unsigned i;
191 
192  if (g.thread) {
193  g.quit = 1;
194  pj_thread_join(g.thread);
195  pj_thread_destroy(g.thread);
196  g.thread = NULL;
197  }
198  if (g.relay) {
199  pj_turn_sock_destroy(g.relay);
200  g.relay = NULL;
201  }
202  for (i=0; i<PJ_ARRAY_SIZE(g.peer); ++i) {
203  if (g.peer[i].stun_sock) {
204  pj_stun_sock_destroy(g.peer[i].stun_sock);
205  g.peer[i].stun_sock = NULL;
206  }
207  }
208  if (g.stun_config.timer_heap) {
209  pj_timer_heap_destroy(g.stun_config.timer_heap);
210  g.stun_config.timer_heap = NULL;
211  }
212  if (g.stun_config.ioqueue) {
213  pj_ioqueue_destroy(g.stun_config.ioqueue);
214  g.stun_config.ioqueue = NULL;
215  }
216  if (g.pool) {
217  pj_pool_release(g.pool);
218  g.pool = NULL;
219  }
220  pj_pool_factory_dump(&g.cp.factory, PJ_TRUE);
222 
223  return PJ_SUCCESS;
224 }
225 
226 
227 static int worker_thread(void *unused)
228 {
229  PJ_UNUSED_ARG(unused);
230 
231  while (!g.quit) {
232  const pj_time_val delay = {0, 10};
233 
234  /* Poll ioqueue for the TURN client */
235  pj_ioqueue_poll(g.stun_config.ioqueue, &delay);
236 
237  /* Poll the timer heap */
238  pj_timer_heap_poll(g.stun_config.timer_heap, NULL);
239 
240  }
241 
242  return 0;
243 }
244 
245 static pj_status_t create_relay(void)
246 {
247  pj_turn_sock_cb rel_cb;
248  pj_stun_auth_cred cred;
249  pj_str_t srv;
250  pj_status_t status;
251 
252  if (g.relay) {
253  PJ_LOG(1,(THIS_FILE, "Relay already created"));
254  return -1;
255  }
256 
257  /* Create DNS resolver if configured */
258  if (o.nameserver) {
259  pj_str_t ns = pj_str(o.nameserver);
260 
261  status = pj_dns_resolver_create(&g.cp.factory, "resolver", 0,
262  g.stun_config.timer_heap,
263  g.stun_config.ioqueue, &g.resolver);
264  if (status != PJ_SUCCESS) {
265  PJ_LOG(1,(THIS_FILE, "Error creating resolver (err=%d)", status));
266  return status;
267  }
268 
269  status = pj_dns_resolver_set_ns(g.resolver, 1, &ns, NULL);
270  if (status != PJ_SUCCESS) {
271  PJ_LOG(1,(THIS_FILE, "Error configuring nameserver (err=%d)", status));
272  return status;
273  }
274  }
275 
276  pj_bzero(&rel_cb, sizeof(rel_cb));
277  rel_cb.on_rx_data = &turn_on_rx_data;
278  rel_cb.on_state = &turn_on_state;
279  CHECK( pj_turn_sock_create(&g.stun_config, pj_AF_INET(),
280  (o.use_tcp? PJ_TURN_TP_TCP : PJ_TURN_TP_UDP),
281  &rel_cb, 0,
282  NULL, &g.relay) );
283 
284  if (o.user_name) {
285  pj_bzero(&cred, sizeof(cred));
287  cred.data.static_cred.realm = pj_str(o.realm);
288  cred.data.static_cred.username = pj_str(o.user_name);
289  cred.data.static_cred.data_type = PJ_STUN_PASSWD_PLAIN;
290  cred.data.static_cred.data = pj_str(o.password);
291  //cred.data.static_cred.nonce = pj_str(o.nonce);
292  } else {
293  PJ_LOG(2,(THIS_FILE, "Warning: no credential is set"));
294  }
295 
296  srv = pj_str(o.srv_addr);
297  CHECK(pj_turn_sock_alloc(g.relay, /* the relay */
298  &srv, /* srv addr */
299  (o.srv_port?atoi(o.srv_port):PJ_STUN_PORT),/* def port */
300  g.resolver, /* resolver */
301  (o.user_name?&cred:NULL), /* credential */
302  NULL) /* alloc param */
303  );
304 
305  return PJ_SUCCESS;
306 }
307 
308 static void destroy_relay(void)
309 {
310  if (g.relay) {
311  pj_turn_sock_destroy(g.relay);
312  }
313 }
314 
315 
316 static void turn_on_rx_data(pj_turn_sock *relay,
317  void *pkt,
318  unsigned pkt_len,
319  const pj_sockaddr_t *peer_addr,
320  unsigned addr_len)
321 {
322  char addrinfo[80];
323 
324  pj_sockaddr_print(peer_addr, addrinfo, sizeof(addrinfo), 3);
325 
326  PJ_LOG(3,(THIS_FILE, "Client received %d bytes data from %s: %.*s",
327  pkt_len, addrinfo, pkt_len, pkt));
328 }
329 
330 
331 static void turn_on_state(pj_turn_sock *relay, pj_turn_state_t old_state,
332  pj_turn_state_t new_state)
333 {
334  PJ_LOG(3,(THIS_FILE, "State %s --> %s", pj_turn_state_name(old_state),
335  pj_turn_state_name(new_state)));
336 
337  if (new_state == PJ_TURN_STATE_READY) {
339  pj_turn_sock_get_info(relay, &info);
340  pj_memcpy(&g.relay_addr, &info.relay_addr, sizeof(pj_sockaddr));
341  } else if (new_state > PJ_TURN_STATE_READY && g.relay) {
342  PJ_LOG(3,(THIS_FILE, "Relay shutting down.."));
343  g.relay = NULL;
344  }
345 }
346 
347 static pj_bool_t stun_sock_on_status(pj_stun_sock *stun_sock,
348  pj_stun_sock_op op,
349  pj_status_t status)
350 {
351  struct peer *peer = (struct peer*) pj_stun_sock_get_user_data(stun_sock);
352 
353  if (status == PJ_SUCCESS) {
354  PJ_LOG(4,(THIS_FILE, "peer%d: %s success", peer-g.peer,
355  pj_stun_sock_op_name(op)));
356  } else {
357  char errmsg[PJ_ERR_MSG_SIZE];
358  pj_strerror(status, errmsg, sizeof(errmsg));
359  PJ_LOG(1,(THIS_FILE, "peer%d: %s error: %s", peer-g.peer,
360  pj_stun_sock_op_name(op), errmsg));
361  return PJ_FALSE;
362  }
363 
366  int cmp;
367 
368  pj_stun_sock_get_info(stun_sock, &info);
369  cmp = pj_sockaddr_cmp(&info.mapped_addr, &peer->mapped_addr);
370 
371  if (cmp) {
372  char straddr[PJ_INET6_ADDRSTRLEN+10];
373 
374  pj_sockaddr_cp(&peer->mapped_addr, &info.mapped_addr);
375  pj_sockaddr_print(&peer->mapped_addr, straddr, sizeof(straddr), 3);
376  PJ_LOG(3,(THIS_FILE, "peer%d: STUN mapped address is %s",
377  peer-g.peer, straddr));
378  }
379  }
380 
381  return PJ_TRUE;
382 }
383 
384 static pj_bool_t stun_sock_on_rx_data(pj_stun_sock *stun_sock,
385  void *pkt,
386  unsigned pkt_len,
387  const pj_sockaddr_t *src_addr,
388  unsigned addr_len)
389 {
390  struct peer *peer = (struct peer*) pj_stun_sock_get_user_data(stun_sock);
391  char straddr[PJ_INET6_ADDRSTRLEN+10];
392 
393  ((char*)pkt)[pkt_len] = '\0';
394 
395  pj_sockaddr_print(src_addr, straddr, sizeof(straddr), 3);
396  PJ_LOG(3,(THIS_FILE, "peer%d: received %d bytes data from %s: %s",
397  peer-g.peer, pkt_len, straddr, (char*)pkt));
398 
399  return PJ_TRUE;
400 }
401 
402 
403 static void menu(void)
404 {
406  char client_state[20], relay_addr[80], peer0_addr[80], peer1_addr[80];
407 
408  if (g.relay) {
409  pj_turn_sock_get_info(g.relay, &info);
410  strcpy(client_state, pj_turn_state_name(info.state));
411  if (info.state >= PJ_TURN_STATE_READY)
412  pj_sockaddr_print(&info.relay_addr, relay_addr, sizeof(relay_addr), 3);
413  else
414  strcpy(relay_addr, "0.0.0.0:0");
415  } else {
416  strcpy(client_state, "NULL");
417  strcpy(relay_addr, "0.0.0.0:0");
418  }
419 
420  pj_sockaddr_print(&g.peer[0].mapped_addr, peer0_addr, sizeof(peer0_addr), 3);
421  pj_sockaddr_print(&g.peer[1].mapped_addr, peer1_addr, sizeof(peer1_addr), 3);
422 
423 
424  puts("\n");
425  puts("+=====================================================================+");
426  puts("| CLIENT | PEER-0 |");
427  puts("| | |");
428  printf("| State : %-12s | Address: %-21s |\n",
429  client_state, peer0_addr);
430  printf("| Relay addr: %-21s | |\n",
431  relay_addr);
432  puts("| | 0 Send data to relay address |");
433  puts("| a Allocate relay | |");
434  puts("| p,pp Set permission for peer 0/1 +--------------------------------+");
435  puts("| s,ss Send data to peer 0/1 | PEER-1 |");
436  puts("| b,bb BindChannel to peer 0/1 | |");
437  printf("| x Delete allocation | Address: %-21s |\n",
438  peer1_addr);
439  puts("+------------------------------------+ |");
440  puts("| q Quit d Dump | 1 Send data to relay adderss |");
441  puts("+------------------------------------+--------------------------------+");
442  printf(">>> ");
443  fflush(stdout);
444 }
445 
446 
447 static void console_main(void)
448 {
449  while (!g.quit) {
450  char input[32];
451  struct peer *peer;
452  pj_status_t status;
453 
454  menu();
455 
456  if (fgets(input, sizeof(input), stdin) == NULL)
457  break;
458 
459  switch (input[0]) {
460  case 'a':
461  create_relay();
462  break;
463  case 'd':
464  pj_pool_factory_dump(&g.cp.factory, PJ_TRUE);
465  break;
466  case 's':
467  if (g.relay == NULL) {
468  puts("Error: no relay");
469  continue;
470  }
471  if (input[1]!='s')
472  peer = &g.peer[0];
473  else
474  peer = &g.peer[1];
475 
476  strcpy(input, "Hello from client");
477  status = pj_turn_sock_sendto(g.relay, (const pj_uint8_t*)input,
478  strlen(input)+1,
479  &peer->mapped_addr,
480  pj_sockaddr_get_len(&peer->mapped_addr));
481  if (status != PJ_SUCCESS)
482  my_perror("turn_udp_sendto() failed", status);
483  break;
484  case 'b':
485  if (g.relay == NULL) {
486  puts("Error: no relay");
487  continue;
488  }
489  if (input[1]!='b')
490  peer = &g.peer[0];
491  else
492  peer = &g.peer[1];
493 
494  status = pj_turn_sock_bind_channel(g.relay, &peer->mapped_addr,
495  pj_sockaddr_get_len(&peer->mapped_addr));
496  if (status != PJ_SUCCESS)
497  my_perror("turn_udp_bind_channel() failed", status);
498  break;
499  case 'p':
500  if (g.relay == NULL) {
501  puts("Error: no relay");
502  continue;
503  }
504  if (input[1]!='p')
505  peer = &g.peer[0];
506  else
507  peer = &g.peer[1];
508 
509  status = pj_turn_sock_set_perm(g.relay, 1, &peer->mapped_addr, 1);
510  if (status != PJ_SUCCESS)
511  my_perror("pj_turn_sock_set_perm() failed", status);
512  break;
513  case 'x':
514  if (g.relay == NULL) {
515  puts("Error: no relay");
516  continue;
517  }
518  destroy_relay();
519  break;
520  case '0':
521  case '1':
522  if (g.relay == NULL) {
523  puts("No relay");
524  break;
525  }
526  peer = &g.peer[input[0]-'0'];
527  sprintf(input, "Hello from peer%d", input[0]-'0');
528  pj_stun_sock_sendto(peer->stun_sock, NULL, input, strlen(input)+1, 0,
529  &g.relay_addr, pj_sockaddr_get_len(&g.relay_addr));
530  break;
531  case 'q':
532  g.quit = PJ_TRUE;
533  break;
534  }
535  }
536 }
537 
538 
539 static void usage(void)
540 {
541  puts("Usage: pjturn_client TURN-SERVER [OPTIONS]");
542  puts("");
543  puts("where TURN-SERVER is \"host[:port]\"");
544  puts("");
545  puts("and OPTIONS:");
546  puts(" --tcp, -T Use TCP to connect to TURN server");
547  puts(" --realm, -r REALM Set realm of the credential to REALM");
548  puts(" --username, -u UID Set username of the credential to UID");
549  puts(" --password, -p PASSWD Set password of the credential to PASSWD");
550  puts(" --fingerprint, -F Use fingerprint for outgoing requests");
551  puts(" --stun-srv, -S NAME Use this STUN srv instead of TURN for Binding discovery");
552  puts(" --nameserver, -N IP Activate DNS SRV, use this DNS server");
553  puts(" --help, -h");
554 }
555 
556 int main(int argc, char *argv[])
557 {
558  struct pj_getopt_option long_options[] = {
559  { "realm", 1, 0, 'r'},
560  { "username", 1, 0, 'u'},
561  { "password", 1, 0, 'p'},
562  { "fingerprint",0, 0, 'F'},
563  { "tcp", 0, 0, 'T'},
564  { "help", 0, 0, 'h'},
565  { "stun-srv", 1, 0, 'S'},
566  { "nameserver", 1, 0, 'N'}
567  };
568  int c, opt_id;
569  char *pos;
570  pj_status_t status;
571 
572  while((c=pj_getopt_long(argc,argv, "r:u:p:S:N:hFT", long_options, &opt_id))!=-1) {
573  switch (c) {
574  case 'r':
575  o.realm = pj_optarg;
576  break;
577  case 'u':
578  o.user_name = pj_optarg;
579  break;
580  case 'p':
581  o.password = pj_optarg;
582  break;
583  case 'h':
584  usage();
585  return 0;
586  case 'F':
587  o.use_fingerprint = PJ_TRUE;
588  break;
589  case 'T':
590  o.use_tcp = PJ_TRUE;
591  break;
592  case 'S':
593  o.stun_server = pj_optarg;
594  break;
595  case 'N':
596  o.nameserver = pj_optarg;
597  break;
598  default:
599  printf("Argument \"%s\" is not valid. Use -h to see help",
600  argv[pj_optind]);
601  return 1;
602  }
603  }
604 
605  if (pj_optind == argc) {
606  puts("Error: TARGET is needed");
607  usage();
608  return 1;
609  }
610 
611  if ((pos=pj_ansi_strchr(argv[pj_optind], ':')) != NULL) {
612  o.srv_addr = argv[pj_optind];
613  *pos = '\0';
614  o.srv_port = pos+1;
615  } else {
616  o.srv_addr = argv[pj_optind];
617  }
618 
619  if ((status=init()) != 0)
620  goto on_return;
621 
622  //if ((status=create_relay()) != 0)
623  // goto on_return;
624 
625  console_main();
626 
627 on_return:
628  client_shutdown();
629  return status ? 1 : 0;
630 }
631 
void pj_stun_sock_cfg_default(pj_stun_sock_cfg *cfg)
pj_stun_auth_cred_type type
Definition: stun_auth.h:119
pj_status_t pj_ioqueue_destroy(pj_ioqueue_t *ioque)
pj_status_t pjnath_init(void)
Definition: stun_sock.h:79
Definition: turn_session.h:144
int pj_ioqueue_poll(pj_ioqueue_t *ioque, const pj_time_val *timeout)
struct pj_dns_resolver pj_dns_resolver
pj_str_t data
Definition: stun_auth.h:153
void pj_pool_release(pj_pool_t *pool)
int pj_bool_t
Definition: stun_auth.h:114
struct pj_thread_t pj_thread_t
void * pj_memcpy(void *dst, const void *src, pj_size_t size)
Definition: stun_sock.h:219
#define pj_AF_INET()
pj_status_t pj_stun_sock_create(pj_stun_config *stun_cfg, const char *name, int af, const pj_stun_sock_cb *cb, const pj_stun_sock_cfg *cfg, void *user_data, pj_stun_sock **p_sock)
pj_status_t pj_stun_sock_destroy(pj_stun_sock *sock)
pj_status_t pj_stun_sock_start(pj_stun_sock *stun_sock, const pj_str_t *domain, pj_uint16_t default_port, pj_dns_resolver *resolver)
pj_status_t pj_ioqueue_create(pj_pool_t *pool, pj_size_t max_fd, pj_ioqueue_t **ioqueue)
pj_status_t pj_dns_resolver_create(pj_pool_factory *pf, const char *name, unsigned options, pj_timer_heap_t *timer, pj_ioqueue_t *ioqueue, pj_dns_resolver **p_resolver)
int ka_interval
Definition: stun_sock.h:270
void(* on_state)(pj_turn_sock *turn_sock, pj_turn_state_t old_state, pj_turn_state_t new_state)
Definition: turn_sock.h:97
#define PJ_LOG(level, arg)
int pj_status_t
pj_status_t pj_thread_create(pj_pool_t *pool, const char *thread_name, pj_thread_proc *proc, void *arg, pj_size_t stack_size, unsigned flags, pj_thread_t **thread)
Definition: stun_sock.h:100
pj_pool_factory_policy pj_pool_factory_default_policy
Definition: stun_config.h:48
void pj_sockaddr_t
pj_bool_t(* on_status)(pj_stun_sock *stun_sock, pj_stun_sock_op op, pj_status_t status)
Definition: stun_sock.h:170
Definition: stun_auth.h:75
pj_status_t pj_turn_sock_sendto(pj_turn_sock *turn_sock, const pj_uint8_t *pkt, unsigned pkt_len, const pj_sockaddr_t *peer_addr, unsigned addr_len)
pj_str_t info
pj_status_t pj_turn_sock_get_info(pj_turn_sock *turn_sock, pj_turn_session_info *info)
void pj_timer_heap_destroy(pj_timer_heap_t *ht)
pj_sockaddr relay_addr
Definition: turn_session.h:379
Definition: turn_session.h:190
void pj_turn_sock_destroy(pj_turn_sock *turn_sock)
pj_str_t pj_str(char *str)
const char * pj_stun_sock_op_name(pj_stun_sock_op op)
void pj_sockaddr_cp(pj_sockaddr_t *dst, const pj_sockaddr_t *src)
void pj_caching_pool_init(pj_caching_pool *ch_pool, const pj_pool_factory_policy *policy, pj_size_t max_capacity)
pj_status_t pj_turn_sock_set_perm(pj_turn_sock *turn_sock, unsigned addr_cnt, const pj_sockaddr addr[], unsigned options)
PJ_BEGIN_DECL pj_status_t pjlib_util_init(void)
char * pj_sockaddr_print(const pj_sockaddr_t *addr, char *buf, int size, unsigned flags)
void pj_bzero(void *dst, pj_size_t size)
#define PJ_STUN_PORT
Definition: config.h:123
pj_str_t pj_strerror(pj_status_t statcode, char *buf, pj_size_t bufsize)
void(* on_rx_data)(pj_turn_sock *turn_sock, void *pkt, unsigned pkt_len, const pj_sockaddr_t *peer_addr, unsigned addr_len)
Definition: turn_sock.h:83
const char * pj_turn_state_name(pj_turn_state_t state)
struct pj_stun_sock pj_stun_sock
Definition: stun_sock.h:62
unsigned char pj_uint8_t
Definition: turn_session.h:349
int pj_sockaddr_cmp(const pj_sockaddr_t *addr1, const pj_sockaddr_t *addr2)
pj_status_t pj_stun_sock_get_info(pj_stun_sock *stun_sock, pj_stun_sock_info *info)
pj_turn_state_t
Definition: turn_session.h:161
#define PJ_ARRAY_SIZE(a)
pj_turn_state_t state
Definition: turn_session.h:354
Definition: turn_sock.h:68
Definition: turn_session.h:149
pj_sockaddr mapped_addr
Definition: stun_sock.h:198
typedef int(PJ_THREAD_FUNC pj_thread_proc)(void *)
pj_status_t pj_dns_resolver_set_ns(pj_dns_resolver *resolver, unsigned count, const pj_str_t servers[], const pj_uint16_t ports[])
pj_status_t pj_turn_sock_alloc(pj_turn_sock *turn_sock, const pj_str_t *domain, int default_port, pj_dns_resolver *resolver, const pj_stun_auth_cred *cred, const pj_turn_alloc_param *param)
unsigned pj_sockaddr_get_len(const pj_sockaddr_t *addr)
#define PJ_ERR_MSG_SIZE
pj_pool_t * pj_pool_create(pj_pool_factory *factory, const char *name, pj_size_t initial_size, pj_size_t increment_size, pj_pool_callback *callback)
pj_status_t pj_thread_join(pj_thread_t *thread)
pj_status_t pj_turn_sock_bind_channel(pj_turn_sock *turn_sock, const pj_sockaddr_t *peer, unsigned addr_len)
void * pj_stun_sock_get_user_data(pj_stun_sock *stun_sock)
void pj_stun_config_init(pj_stun_config *cfg, pj_pool_factory *factory, unsigned options, pj_ioqueue_t *ioqueue, pj_timer_heap_t *timer_heap)
Definition: stun_config.h:98
pj_status_t pj_thread_destroy(pj_thread_t *thread)
pj_stun_sock_op
Definition: stun_sock.h:69
Definition: stun_sock.h:181
Definition: stun_auth.h:96
struct pj_turn_sock pj_turn_sock
Definition: turn_sock.h:62
void pj_pool_factory_dump(pj_pool_factory *pf, pj_bool_t detail)
unsigned pj_timer_heap_poll(pj_timer_heap_t *ht, pj_time_val *next_delay)
unsigned short pj_uint16_t
pj_status_t pj_stun_sock_sendto(pj_stun_sock *stun_sock, pj_ioqueue_op_key_t *send_key, const void *pkt, unsigned pkt_len, unsigned flag, const pj_sockaddr_t *dst_addr, unsigned addr_len)
pj_status_t pj_init(void)
pj_bool_t(* on_rx_data)(pj_stun_sock *stun_sock, void *pkt, unsigned pkt_len, const pj_sockaddr_t *src_addr, unsigned addr_len)
Definition: stun_sock.h:116
#define PJ_EINVAL
Definition: stun_sock.h:85
pj_status_t pj_timer_heap_create(pj_pool_t *pool, pj_size_t count, pj_timer_heap_t **ht)
#define PJ_UNUSED_ARG(arg)
pj_status_t pj_turn_sock_create(pj_stun_config *cfg, int af, pj_turn_tp_type conn_type, const pj_turn_sock_cb *cb, const pj_turn_sock_cfg *setting, void *user_data, pj_turn_sock **p_turn_sock)
#define PJ_INET6_ADDRSTRLEN
void pj_caching_pool_destroy(pj_caching_pool *ch_pool)

.

 


PJNATH - Open Source NAT traversal helper library supporting STUN, TURN, and ICE
Copyright (C) 2006-2009 Teluu Inc.