java.lang.Object
org.cybergarage.upnp.ssdp.SSDPPacket

public class SSDPPacketextends Object
Represents an SSDP packet received over UDP.

This class wraps a DatagramPacket to provide SSDP-specific functionality for parsing and handling UDP packets containing SSDP messages. It provides access to both the raw packet data and parsed SSDP message content.

Key features:

  • DatagramPacket wrapping and management
  • Remote and local address access
  • SSDP message parsing
  • Root device detection
  • Packet data extraction

This class is used by SSDP components to handle incoming UDP packets containing discovery and advertisement messages, providing convenient access to both network information and message content.

  • Field Details

    • dgmPacket

      private DatagramPacket dgmPacket
      /////////////////////////////////////////////
    • localAddr

      private String localAddr
      /////////////////////////////////////////////
    • timeStamp

      private long timeStamp
      /////////////////////////////////////////////
    • packetBytes

      public byte[] packetBytes
      Cached copy of the message bytes, filled in by the first read of the data.
  • Constructor Details

    • SSDPPacket

      public SSDPPacket(byte[] buf, int length)
      Wraps a received SSDP datagram without copying its bytes.
      Parameters:
      buf - the buffer holding the received datagram, wrapped rather than copied
      length - how many bytes of buf this packet spans, in bytes
  • Method Details

    • getDatagramPacket

      public DatagramPacket getDatagramPacket()
      Returns the underlying datagram.
      Returns:
      the wrapped DatagramPacket carrying this SSDP message
    • setLocalAddress

      public void setLocalAddress(String addr)
      Records the local IP address that received this datagram.
      Parameters:
      addr - the local IP address that received the datagram
    • getLocalAddress

      public String getLocalAddress()
      Returns the local IP address that received this datagram.
      Returns:
      the local IP address that received this datagram
    • setTimeStamp

      public void setTimeStamp(long value)
      Records when this datagram was received.
      Parameters:
      value - the receipt time in milliseconds since the epoch
    • getTimeStamp

      public long getTimeStamp()
      Returns when this datagram was received.
      Returns:
      when this datagram was received, in milliseconds since the epoch, or 0
    • getRemoteInetAddress

      public InetAddress getRemoteInetAddress()
      Returns the address this datagram was sent from.
      Returns:
      the InetAddress this datagram was sent from
    • getRemoteAddress

      public String getRemoteAddress()
      Returns the IP address this datagram was sent from.
      Returns:
      the IP address string this datagram was sent from
    • getRemotePort

      public int getRemotePort()
      Returns the UDP port this datagram was sent from.
      Returns:
      the UDP port number this datagram was sent from
    • getData

      public byte[] getData()
      Returns the message bytes, caching them on the first call.
      Returns:
      the UTF-8 message bytes of this datagram, cached in packetBytes once read
    • getHost

      public String getHost()
      Returns the HOST header value.
      Returns:
      the HOST header value, or an empty string if the message carries none
    • getCacheControl

      public String getCacheControl()
      Returns the CACHE-CONTROL header value.
      Returns:
      the CACHE-CONTROL header value, or an empty string if the message carries none
    • getLocation

      public String getLocation()
      Returns the LOCATION header value.
      Returns:
      the LOCATION header value, or an empty string if the message carries none
    • getMAN

      public String getMAN()
      Returns the MAN header value.
      Returns:
      the MAN header value, or an empty string if the message carries none
    • getST

      public String getST()
      Returns the ST header value.
      Returns:
      the ST header value, or an empty string if the message carries none
    • getNT

      public String getNT()
      Returns the NT header value.
      Returns:
      the NT header value, or an empty string if the message carries none
    • getNTS

      public String getNTS()
      Returns the NTS header value.
      Returns:
      the NTS header value, or an empty string if the message carries none
    • getServer

      public String getServer()
      Returns the SERVER header value.
      Returns:
      the SERVER header value, or an empty string if the message carries none
    • getUSN

      public String getUSN()
      Returns the USN header value.
      Returns:
      the USN header value, or an empty string if the message carries none
    • getMX

      public int getMX()
      Returns the MX header as a number of seconds.
      Returns:
      the MX header in seconds, or 0 if it is missing or unparseable
    • getHostInetAddress

      public InetAddress getHostInetAddress()
      Resolves the HOST header to an address.
      Returns:
      the InetAddress named in the HOST header, or the loopback address if that header carries no port
    • isRootDevice

      public boolean isRootDevice()
      Returns whether NT, ST or USN identifies the root device.
      Returns:
      true if the NT, ST or USN header identifies this as the root device
    • isDiscover

      public boolean isDiscover()
      Returns whether this is a discover advertisement.
      Returns:
      true if the MAN header carries the discover advertisement
    • isAlive

      public boolean isAlive()
      Returns whether this is an ssdp:alive advertisement.
      Returns:
      true if the NTS header is ssdp:alive
    • isByeBye

      public boolean isByeBye()
      Returns whether this is an ssdp:byebye advertisement.
      Returns:
      true if the NTS header is ssdp:byebye
    • getLeaseTime

      public int getLeaseTime()
      Returns the advertised lease duration.
      Returns:
      the lease time in seconds, or 0 if the CACHE-CONTROL header carries no usable max-age
    • toString

      public String toString()
      Renders the raw message text.
      Overrides:
      toString in class Object