Hi Andreas,

On Sat, Feb 15, 2025 at 02:30:48PM +0000, Andreas Mock wrote:
> Hi all,
> 
> the fetch method 'src' is returning an IP address with type 'ip'.
> As soon as I use it with %[src] I get a human readable string
> representation of that ip address. That means I have something
> like ip2str converter.
> 
> Is there a converter in HAProxy to get the binary representation
> of that ip address?
> 
> IPv4 is 4 bytes. IPv6 is 16 bytes.
> 
> Something like src,ip2bin which would be a 4 byte binary for IPv4
> and a 16 byte binary for IPv6?

Interesting. We indeed don't have anything explicit to do this. Actually
the IP address (IPv4 or IPv6) *is* internally in binary formay and there's
an implicit cast from address to binary that does nothing more than a
memcpy(). If you pass the address to something that consumes a binary
type on input, it will be automatically cast to this type. For example,
if used with a binary stick-table it should automatically cast. Could you
please provide an example of how you're trying to use it where you'd like
to get the binary format that it does not propose ? That might help to
figure if we could for example insert a dummy conversion in between to
force the cast, or any such a thing.

Willy


Reply via email to