Skip to content

IP address in OpcUa:Hostname is truncated at the first dot when building the ApplicationUri #38

Description

@drusteeby

Summary

OpcApplicationConfiguration.HostnameLabel returns everything before the first . in the hostname:

public string HostnameLabel => _hostname.Contains('.')
    ? _hostname[.._hostname.IndexOf('.')]
    : _hostname;

That is intended to strip a DNS suffix (plc.example.com -> plc), but for an IP address it produces nonsense. With OpcUa:Hostname=10.128.128.14 the server's ApplicationUri becomes urn:OpcPlc:10.

Configuring the hostname as an IP is a normal thing to do when clients connect by IP and endpointMustExist style checks compare the advertised endpoint URL against the one they dialled (this is what the Pico MES hub does).

Suggested fix

Skip the label truncation when the hostname parses as an IPAddress (both v4 and v6), and use the full address in the URI, e.g. urn:OpcPlc:10.128.128.14. Add a unit test for the IP case alongside the existing hostname behaviour.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions