Skip to content

Commit

Permalink
feat(ipv4): return source address when forwarded
Browse files Browse the repository at this point in the history
when processing in the client
  • Loading branch information
stakach committed Aug 4, 2021
1 parent 929fbf4 commit 543fc65
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion shard.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: bacnet
version: 0.10.4
version: 0.10.5
crystal: ">= 0.36.1"

dependencies:
Expand Down
2 changes: 2 additions & 0 deletions src/bacnet/client/ipv4.cr
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ class BACnet::Client::IPv4
def received(message : BACnet::Message::IPv4, address : Socket::IPAddress)
Log.trace { "received #{message.data_link.request_type} message from #{address.inspect} - #{message.application.class}" }

address = message.data_link.forwarded_address if message.data_link.request_type.forwarded_npdu?

app = message.application
case app
in Nil
Expand Down
10 changes: 9 additions & 1 deletion src/bacnet/virtual_link_control/ipv4_bvlci.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require "../../bacnet"
require "./ipv4_message"
require "socket/address"

module BACnet
# BACnet Virtual Link Control Interface
Expand Down Expand Up @@ -51,12 +52,19 @@ module BACnet
Request::DeleteForeignDeviceTableEntry,
}.includes? request_type
}) do
uint32 :ip
uint8 :ip1
uint8 :ip2
uint8 :ip3
uint8 :ip4
uint16 :port
end

uint16 :register_ttl, onlyif: ->{ request_type.register_foreign_device? }

enum_field UInt16, result_code : Result = Result::Success, onlyif: ->{ request_type.bvcl_result? }

def forwarded_address
Socket::IPAddress.new("#{address.ip1}.#{address.ip2}.#{address.ip3}.#{address.ip4}", address.port.to_i)
end
end
end

0 comments on commit 543fc65

Please sign in to comment.