我该如何“互连"? Linux中有两个套接字? [英] How can I "interconnect" two sockets in Linux?

查看:67
本文介绍了我该如何“互连"? Linux中有两个套接字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有两个连接的插座.我该如何互连它们?

There are two connected sockets. How can I interconnect them?

  1. 出现在一个套接字上的数据应写入另一个套接字.
  2. EOF/FIN应该很好地传播.如果一个关闭一半,另一个也应该关闭一半.


int client = get_connected_client_socket();
int proxy = get_connected_proxy_socket();
negotiate_with_proxy(proxy);
iterconnect(client, proxy); 
// Now forgot about both client and proxy. 
// System should handle IO/shutdown/close. 
// Ideally even without any support of the user-space process.

Linux可以做到吗?可以通过欺骗连接跟踪来更改现有连接的跟踪状态吗?

Can Linux do it? Can it be done by tricking connection tracking to change tracking status of existing connection?

@related

@related Determine how much can I write into a filehandle; copying data from one FH to the other

推荐答案

您是否了解 splice ().根据您的两个问题,我认为这就是您要去的地方.最后,我检查了您是否无法在一个splice调用中执行此操作,因为这两个文件描述符都不能是套接字.但是您应该能够在2个调用中完成此操作(sockin-> pipe-> sockout).还可以查看 tee().这些可能不完全是您想要的,但据我所知,它们就在球场上.

Are you aware of splice(). Based on your two questions I think this is where you are headed. Last I checked you can't do this in one splice call because both of file descriptors can't be sockets. But you should be able to do it in 2 calls (sockin->pipe->sockout). Also take a look at tee(). These may not be exactly what you want but from what I can figure they are in the ballpark.

这篇关于我该如何“互连"? Linux中有两个套接字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆