Line 89: |
Line 89: |
| [[Category: Sub-projects]] | | [[Category: Sub-projects]] |
| [[Category: Sockets]] | | [[Category: Sockets]] |
| + | == Example == |
| + | <tt> <pre> |
| + | /* Dump a tcp socket */ |
| + | |
| + | dst_let = sizeof(addr); |
| + | if (getsockname(sock, (struct sockaddr *) &addr, &dst_let)) { |
| + | pr_perror("connect"); |
| + | return -1; |
| + | } |
| + | dst_let = sizeof(addr); |
| + | if (getpeername(sock, (struct sockaddr *) &dst, &dst_let)) { |
| + | pr_perror("connect"); |
| + | return -1; |
| + | } |
| + | |
| + | so = libsoccr_pause(sock); |
| + | |
| + | dsize = libsoccr_save(so, &data, sizeof(data)); |
| + | if (dsize < 0) { |
| + | pr_perror("libsoccr_save"); |
| + | return -1; |
| + | } |
| + | close(sock); |
| + | |
| + | |
| + | /* Restore a tcp socket */ |
| + | rst = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); |
| + | if (rst == -1) |
| + | return -1; |
| + | |
| + | |
| + | so_rst = libsoccr_pause(rst); |
| + | libsoccr_set_addr(so_rst, 1, &addr, 0); |
| + | libsoccr_set_addr(so_rst, 0, &dst, 0); |
| + | |
| + | queue = libsoccr_get_queue_bytes(so, TCP_RECV_QUEUE, SOCCR_MEM_EXCL); |
| + | libsoccr_set_queue_bytes(so_rst, TCP_RECV_QUEUE, queue, SOCCR_MEM_EXCL); |
| + | queue = libsoccr_get_queue_bytes(so, TCP_SEND_QUEUE, SOCCR_MEM_EXCL); |
| + | libsoccr_set_queue_bytes(so_rst, TCP_SEND_QUEUE, queue, SOCCR_MEM_EXCL); |
| + | |
| + | ret = libsoccr_restore(so_rst, &data, dsize); |
| + | if (ret) |
| + | return -1; |
| + | |
| + | libsoccr_resume(so_rst); |
| + | libsoccr_resume(so); |
| + | </pre> |
| + | </tt> |