Difference between port conversion functions

The file bro.bif in the src directory contains two functions to convert count
values into ports.

    function count_to_port%(c: count, t: transport_proto%): port
        %{
        return new PortVal(c, (TransportProto)(t->InternalInt()));
        %}

    function to_port%(num: count, proto: transport_proto%): port
        %{
        return new PortVal(num, (TransportProto)proto->AsEnum());
        %}

How do they differ and which one should be used? It looks like they do
the same but have a slightly different implementation. If that's the
case, can we remove one?

    Matthias

How do they differ and which one should be used?

FWIW, darned if I know why there are two.

    Vern

Yeah, looks like one can go. We should keep the one which's naming is
more consistent with other coverters; which I believe should be
count_to_port because the first argument is a specific type (and not
"any" as other to_* function use). This is out of my memory though,
worth checking.

Robin

> function count_to_port%(c: count, t: transport_proto%): port
> function to_port%(num: count, proto: transport_proto%): port

Yeah, looks like one can go. We should keep the one which's naming is
more consistent with other coverters; which I believe should be
count_to_port because the first argument is a specific type (and not
"any" as other to_* function use). This is out of my memory though,
worth checking.

I double-checked it and it is indeed the case. In fact, the to_*
functions are all string converters and (should) have a signature of the
form

    to_TYPE(s: string): TYPE

As such, to_port(...) would have to be changed to

    to_port(s: string) : port

if we want to be consistent.

    Matthias

         %{
         return new PortVal(num, (TransportProto)proto->AsEnum());
         %}

We should probably use the above implementation though, because AFAIK AsEnum() does type checking whereas InternalInt() won't.

cu
Gregor