Generated from Manticore v1.1.5 • 201 packages. View on pkg.go.dev

llmnr

import "github.com/TheManticoreProject/Manticore/network/llmnr"

Index

type Client

Client represents an LLMNR client that can send queries and receive responses.

The Client struct provides methods to create a new client, send queries, and close the client connection. It manages a UDP connection and uses a sync.Map to keep track of ongoing queries.

Fields: - conn: A pointer to the UDP connection used for sending and receiving LLMNR messages. - timeout: The duration to wait for a response before timing out. - queries: A sync.Map that maps query IDs to channels for receiving responses. - closeOnce: Ensures the client is closed only once. - closed: A channel that is closed when the client is closed.

Usage example:

client, err := NewClient()
if err != nil {
    log.Fatalf("Failed to create client: %v", err)
}
defer client.Close()

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

resp, err := client.Query(ctx, "example.local", TypeA)
if err != nil {
    log.Fatalf("Query failed: %v", err)
}
fmt.Printf("Received response: %v\n", resp)
type Client struct {
    Conn      *net.UDPConn
    Timeout   time.Duration
    Queries   sync.Map
    CloseOnce sync.Once
    Closed    chan struct{}
}

func NewClient

func NewClient() (*Client, error)

NewClient creates a new LLMNR client with a UDP connection.

The function initializes a UDP connection for the client to use for sending and receiving LLMNR messages. It sets a default timeout duration for queries and starts a read loop to handle incoming responses.

Returns:

  • A pointer to the newly created Client.
  • An error if the UDP connection could not be created.

Usage example:

client, err := NewClient()
if err != nil {
    log.Fatalf("Failed to create client: %v", err)
}
defer client.Close()

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

resp, err := client.Query(ctx, "example.local", TypeA)
if err != nil {
    log.Fatalf("Query failed: %v", err)
}
fmt.Printf("Received response: %v\n", resp)

func (*Client) Close

func (c *Client) Close() error

Close closes the client connection

func (*Client) Query

func (c *Client) Query(ctx context.Context, name string, qtype llmnr_type.Type) (*message.Message, error)

Query sends an LLMNR query and waits for a response

Subpackages