【问题标题】:Can I include metadata/header in a tcp packet send over a socket?我可以在通过套接字发送的 tcp 数据包中包含元数据/标头吗?
【发布时间】:2013-12-14 22:21:32
【问题描述】:

我需要通过套接字发送数据包并希望包含一些元信息而不改变数据包内容本身。这可能吗?如果是:我可以在 perl 中做吗?

我正在编写代理服务器,当我向代理服务器发送数据包时,我需要以某种方式包含代理服务器位于客户端和我要使用的服务器之间的应用程序端口。

【问题讨论】:

    标签: perl sockets tcp


    【解决方案1】:

    你可以使用Net::ProxyMod

    Description Net::ProxyMod
    
    This is a small module that allows you to create a proxy for packet alteration
    and debugging. You just need to specify two functions in and outgoing packets 
    will be passed to. In these functions you can then modify the packet if desired. 
    This is useful to get in between an existing client and server for testing 
    purposes.
    
    ProxyMod can be used as a standard proxy or as a transparent proxy together 
    with a firewall package such as ipfw on FreeBSD. Please refer to the ipfw 
    documenation for more information. 
    

    或试试Net::Divert

    Description Net::Divert
    
    The Net::Divert module facilitates the use of divert sockets for packet alteration
    on FreeBSD and MacOSX.
    
    Divert sockets can be bound to a certain port. This port will then receive all 
    packets you divert to it with the help of a divert filter rule. On FreeBSD and 
    MacOSX ipfw allows you to add such a rule. Please refer to the divert and ipfw 
    manpages for more information.
    
    This module allows you to create a divert socket and then just supply a function 
    that will deal with the incoming packets.
    
    new(host,port) will create a new divert object. It will also create a divert 
    socket bound to the specified port at the given host/ip.
    
    getPackets(func) will create a loop getting all incoming packets and pass them 
    onto the specified function you created. This function will be called with two 
    arguments: packet and fwtag. Fwtag contains the rule number where the packet is 
    reinserted. Refer to divert(4) for more information.
    
    putPacket(packet,fwtag) reinsert a packet at the specified fw rule (normally you 
    don't want to alter fwtag, as it is easy to create infinite loops this way)
    

    【讨论】:

      猜你喜欢
      • 2013-09-16
      • 1970-01-01
      • 2019-04-26
      • 2022-11-12
      • 2011-09-09
      • 1970-01-01
      • 2018-05-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多