Changeset 1300 for pjproject/trunk
- Timestamp:
- May 25, 2007 6:11:35 AM (18 years ago)
- Location:
- pjproject/trunk/pjnath/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjnath/src/pjstun-client/client_main.c
r1275 r1300 42 42 pj_stun_session *sess; 43 43 pj_sock_t sock; 44 pj_sock_t peer_sock; 44 45 pj_thread_t *thread; 45 46 pj_bool_t quit; … … 155 156 PJ_FD_ZERO(&readset); 156 157 PJ_FD_SET(g.sock, &readset); 157 158 n = pj_sock_select(g.sock+1, &readset, NULL, NULL, &timeout); 158 PJ_FD_SET(g.peer_sock, &readset); 159 160 n = (g.peer_sock > g.sock) ? g.peer_sock : g.sock; 161 n = pj_sock_select(n+1, &readset, NULL, NULL, &timeout); 159 162 if (n > 0) { 160 163 if (PJ_FD_ISSET(g.sock, &readset)) { … … 180 183 } else { 181 184 buffer[len] = '\0'; 182 PJ_LOG(3,(THIS_FILE, "Received data : %s", (char*)buffer));185 PJ_LOG(3,(THIS_FILE, "Received data on client sock: %s", (char*)buffer)); 183 186 } 187 188 } else if (PJ_FD_ISSET(g.peer_sock, &readset)) { 189 pj_uint8_t buffer[512]; 190 pj_ssize_t len; 191 pj_sockaddr_in addr; 192 int addrlen; 193 pj_status_t rc; 194 195 len = sizeof(buffer); 196 addrlen = sizeof(addr); 197 rc = pj_sock_recvfrom(g.peer_sock, buffer, &len, 0, &addr, &addrlen); 198 if (rc != PJ_SUCCESS || len <= 0) 199 continue; 200 201 buffer[len] = '\0'; 202 203 if (pj_stun_msg_check(buffer, len, PJ_STUN_IS_DATAGRAM)==PJ_SUCCESS) { 204 pj_stun_msg *msg; 205 206 rc = pj_stun_msg_decode(g.pool, (pj_uint8_t*)buffer, len, 0, 207 &msg, NULL, NULL); 208 if (rc != PJ_SUCCESS) { 209 my_perror("Error decoding packet on peer sock", rc); 210 } else { 211 pj_stun_msg_dump(msg, buffer, sizeof(buffer), NULL); 212 PJ_LOG(3,(THIS_FILE, "Received STUN packet on peer sock: %s", 213 buffer)); 214 } 215 216 } else { 217 PJ_LOG(3,(THIS_FILE, "Received data on peer sock: %s", (char*)buffer)); 218 } 219 184 220 } 221 185 222 } else if (n < 0) 186 223 pj_thread_sleep(50); … … 234 271 pj_assert(status == PJ_SUCCESS); 235 272 273 status = pj_sock_socket(PJ_AF_INET, PJ_SOCK_DGRAM, 0, &g.peer_sock); 274 pj_assert(status == PJ_SUCCESS); 275 276 status = pj_sock_bind_in(g.peer_sock, 0, 0); 277 pj_assert(status == PJ_SUCCESS); 278 236 279 status = pj_sock_socket(PJ_AF_INET, PJ_SOCK_DGRAM, 0, &g.sock); 237 280 pj_assert(status == PJ_SUCCESS); … … 250 293 PJ_LOG(3,(THIS_FILE, "Listening on port %d", (int)pj_ntohs(addr.sin_port))); 251 294 252 pj_memcpy(&g.peer_addr, &addr, sizeof(pj_sockaddr_in)); 295 len = sizeof(g.peer_addr); 296 status = pj_sock_getsockname(g.peer_sock, &g.peer_addr, &len); 253 297 if (g.peer_addr.sin_addr.s_addr == 0) 254 298 pj_gethostip(&g.peer_addr.sin_addr); 299 300 PJ_LOG(3,(THIS_FILE, "Peer is on port %d", (int)pj_ntohs(g.peer_addr.sin_port))); 255 301 256 302 pj_memset(&stun_cb, 0, sizeof(stun_cb)); … … 488 534 489 535 len = strlen(g.data); 490 pj_sock_sendto(g. sock, g.data, &len, 0, &g.relay_addr, sizeof(g.relay_addr));536 pj_sock_sendto(g.peer_sock, g.data, &len, 0, &g.relay_addr, sizeof(g.relay_addr)); 491 537 } 492 538 … … 645 691 646 692 g.data = g.data_buf; 693 pj_ansi_strcpy(g.data, "Hello world"); 647 694 648 695 while((c=pj_getopt_long(argc,argv, "r:u:p:N:hF", long_options, &opt_id))!=-1) { -
pjproject/trunk/pjnath/src/pjstun-srv-test/turn_usage.c
r1289 r1300 1332 1332 if (peer == client->active_peer && !has_magic_cookie) { 1333 1333 pj_stun_usage_sendto(client->tu->usage, client->pkt, bytes_read, 0, 1334 &client-> pkt_src_addr, client->pkt_src_addr_len);1334 &client->client_src_addr, sizeof(pj_sockaddr_in)); 1335 1335 } else { 1336 1336 /* Otherwise wrap in Data Indication */ … … 1353 1353 1354 1354 pj_stun_session_send_msg(client->session, PJ_FALSE, 1355 &client-> pkt_src_addr,1356 client->pkt_src_addr_len,1355 &client->client_src_addr, 1356 sizeof(pj_sockaddr_in), 1357 1357 data_ind); 1358 1358 }
Note: See TracChangeset
for help on using the changeset viewer.