nbns

package
v1.0.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Challenge timeouts and retries
	ChallengeTimeout = 2 * time.Second
	ChallengeRetries = 3
)
View Source
const (
	NetBIOSNameLength = 16 // NetBIOS names are exactly 16 bytes
	EncodedNameLength = 32 // Each half-byte becomes a byte in encoded form
	ASCII_A           = 0x41
)

Constants for name encoding

View Source
const (
	// Operation codes
	OpNameQuery    uint16 = 0x0000
	OpRegistration uint16 = 0x2800
	OpRelease      uint16 = 0x3000
	OpWACK         uint16 = 0x3800
	OpRefresh      uint16 = 0x4000
	OpRedirect     uint16 = 0x4800
	OpConflict     uint16 = 0x5000
	OpNodeStatus   uint16 = 0x2100

	// Response codes
	RcodeSuccess     uint16 = 0x0000
	RcodeFormatError uint16 = 0x0001
	RcodeServerError uint16 = 0x0002
	RcodeNameError   uint16 = 0x0003
	RcodeNotImpl     uint16 = 0x0004
	RcodeRefused     uint16 = 0x0005
	RcodeActive      uint16 = 0x0006
	RcodeConflict    uint16 = 0x0007

	// Flags
	FlagResponse      uint16 = 0x8000
	FlagAuthoritative uint16 = 0x0400
	FlagTruncated     uint16 = 0x0200
	FlagRecursion     uint16 = 0x0100
	FlagBroadcast     uint16 = 0x0010

	// Question Type
	QuestionTypeNB     uint16 = 0x0020
	QuestionTypeNBSTAT uint16 = 0x0021

	// Question Class
	QuestionClassIn uint16 = 0x0001 // Internet class
)

Constants for packet types and flags

View Source
const (
	// Default ports for NetBIOS name service
	DefaultNBNSPort = 137

	// Timeouts and retry counts
	ReadTimeout  = 5 * time.Second
	WriteTimeout = 5 * time.Second
)
View Source
const (
	// Default TCP port for NetBIOS name service
	DefaultNBNSTCPPort = 137

	// TCP timeouts
	TCPReadTimeout  = 30 * time.Second
	TCPWriteTimeout = 30 * time.Second

	// Maximum message size
	MaxTCPMessageSize = 65535
)
View Source
const (
	// Default UDP port for NetBIOS name service
	DefaultNBNSUDPPort = 137

	// UDP timeouts and buffer sizes
	UDPReadTimeout  = 5 * time.Second
	UDPWriteTimeout = 5 * time.Second
	MaxUDPSize      = 576 // Minimum reassembly buffer size per RFC 1001
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ADDR_ENTRY

type ADDR_ENTRY struct {
	Flags   uint16
	Address uint32
}

POSITIVE NAME QUERY RESPONSE

func (*ADDR_ENTRY) Length

func (n *ADDR_ENTRY) Length() uint16

returns static 6 bytes number

func (*ADDR_ENTRY) Marshal

func (n *ADDR_ENTRY) Marshal() []byte

Marshals ADDR_ENTRY to buffer

type NBNSHeader

type NBNSHeader struct {
	TransactionID uint16
	Flags         uint16
	Questions     uint16
	Answers       uint16
	Authority     uint16
	Additional    uint16
}

NBNSHeader represents the header of a NetBIOS name service packet

type NBNSPacket

type NBNSPacket struct {
	Header     NBNSHeader
	Questions  []NBNSQuestion
	Answers    []NBNSResourceRecord
	Authority  []NBNSResourceRecord
	Additional []NBNSResourceRecord
}

NBNSPacket represents a complete NetBIOS name service packet

func (*NBNSPacket) Marshal

func (p *NBNSPacket) Marshal() ([]byte, error)

Marshal encodes an NBNSPacket into a byte slice

func (*NBNSPacket) Unmarshal

func (p *NBNSPacket) Unmarshal(data []byte) (int, error)

Unmarshal decodes a byte slice into an NBNSPacket

type NBNSQuestion

type NBNSQuestion struct {
	Name  *NetBIOSName
	Type  uint16
	Class uint16
}

NBNSQuestion represents a question section in a NetBIOS name service packet

type NBNSResourceRecord

type NBNSResourceRecord struct {
	Name     *NetBIOSName
	Type     uint16
	Class    uint16
	TTL      uint32
	RDLength uint16
	RData    []byte
}

NBNSResourceRecord represents a resource record in a NetBIOS name service packet

type NameChallenger

type NameChallenger struct {
	// contains filtered or unexported fields
}

NameChallenger handles name conflict detection and resolution

func NewNameChallenger

func NewNameChallenger(nbns *NetBIOSNameServer, handlers *PacketHandler) *NameChallenger

NewNameChallenger creates a new name challenger instance

func (*NameChallenger) ChallengeOwnership

func (c *NameChallenger) ChallengeOwnership(name string, owner net.IP) (bool, error)

ChallengeOwnership verifies if a node still owns a name

func (*NameChallenger) DefendName

func (c *NameChallenger) DefendName(packet *NBNSPacket, response *NBNSPacket)

DefendName actively defends a name against challenges

type NameRecord

type NameRecord struct {
	Name            string
	Type            NameType
	Status          NameStatus
	Owners          []net.IP  // IP addresses of nodes that own this name
	TTL             time.Time // Time-to-live for name registration
	RefreshInterval time.Duration
	ScopeID         string // NetBIOS scope identifier
}

NameRecord represents a registered NetBIOS name and its attributes

type NameStatus

type NameStatus uint8

NameStatus represents the current state of a name

const (
	Active NameStatus = iota
	Conflict
	Releasing
)

type NameType

type NameType uint8

NameType indicates whether a name is unique or group

const (
	Unique NameType = iota // Only one owner allowed
	Group                  // Multiple owners allowed
)

type NetBIOSName

type NetBIOSName struct {
	Name    string
	ScopeID string
}

NetBIOSName represents a NetBIOS name with its scope

func FirstLevelDecode

func FirstLevelDecode(encoded string) (*NetBIOSName, error)

FirstLevelDecode decodes a first level encoded NetBIOS name

func (*NetBIOSName) FirstLevelEncode

func (n *NetBIOSName) FirstLevelEncode() (string, error)

FirstLevelEncode performs the first level encoding of a NetBIOS name as specified in RFC 1001 section 14.1

func (*NetBIOSName) Validate

func (n *NetBIOSName) Validate() error

Validate checks if a NetBIOS name is valid

type NetBIOSNameServer

type NetBIOSNameServer struct {
	// contains filtered or unexported fields
}

NetBIOSNameServer represents a NetBIOS Name Server

func NewNetBIOSNameServer

func NewNetBIOSNameServer(secured bool) *NetBIOSNameServer

NewNetBIOSNameServer creates a new NetBIOS Name Server instance

func (*NetBIOSNameServer) CleanExpiredNames

func (n *NetBIOSNameServer) CleanExpiredNames()

CleanExpiredNames removes names that have exceeded their TTL

func (*NetBIOSNameServer) MarkNameConflict

func (n *NetBIOSNameServer) MarkNameConflict(name string) error

MarkNameConflict marks a name as being in conflict

func (*NetBIOSNameServer) QueryName

func (n *NetBIOSNameServer) QueryName(name string) ([]net.IP, NameType, error)

QueryName looks up a name and returns its owners

func (*NetBIOSNameServer) RefreshName

func (n *NetBIOSNameServer) RefreshName(name string, owner net.IP) error

RefreshName updates the TTL for a name registration

func (*NetBIOSNameServer) RegisterName

func (n *NetBIOSNameServer) RegisterName(name string, nameType NameType, owner net.IP, ttl time.Duration) error

RegisterName attempts to register a name with the name server

func (*NetBIOSNameServer) ReleaseName

func (n *NetBIOSNameServer) ReleaseName(name string, owner net.IP) error

ReleaseName removes a name registration for a specific owner

type PacketHandler

type PacketHandler struct {
	// contains filtered or unexported fields
}

PacketHandler provides common packet handling methods for both TCP and UDP servers

func NewPacketHandler

func NewPacketHandler(nbns *NetBIOSNameServer) *PacketHandler

NewPacketHandler creates a new packet handler instance

type RedirectInfo

type RedirectInfo struct {
	ServerIP   net.IP
	ServerPort uint16
}

RedirectInfo contains information about where to redirect a client

type RedirectManager

type RedirectManager struct {
	// contains filtered or unexported fields
}

RedirectManager handles NBNS redirection

func NewRedirectManager

func NewRedirectManager() *RedirectManager

NewRedirectManager creates a new redirect manager

func (*RedirectManager) AddRedirect

func (r *RedirectManager) AddRedirect(scope string, serverIP net.IP, port uint16)

AddRedirect adds or updates a redirect mapping

func (*RedirectManager) GetRedirect

func (r *RedirectManager) GetRedirect(scope string) (RedirectInfo, bool)

GetRedirect returns redirect information for a scope

func (*RedirectManager) HandleRedirect

func (r *RedirectManager) HandleRedirect(request *NBNSPacket, response *NBNSPacket) bool

HandleRedirect modifies a response packet for redirection if needed

func (*RedirectManager) RemoveRedirect

func (r *RedirectManager) RemoveRedirect(scope string)

RemoveRedirect removes a redirect mapping

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server represents a NetBIOS Name Server

func NewServer

func NewServer(addr string, secured bool) (*Server, error)

NewServer creates a new NBNS server instance

func (*Server) Start

func (s *Server) Start() error

Start begins listening for NBNS requests

func (*Server) Stop

func (s *Server) Stop()

Stop gracefully shuts down the server

type TCPServer

type TCPServer struct {
	// contains filtered or unexported fields
}

TCPServer represents a NetBIOS Name Server TCP component

func NewTCPServer

func NewTCPServer(addr string, nbns *NetBIOSNameServer) (*TCPServer, error)

NewTCPServer creates a new NBNS TCP server instance

func (*TCPServer) Start

func (s *TCPServer) Start() error

Start begins listening for TCP connections

func (*TCPServer) Stop

func (s *TCPServer) Stop()

Stop gracefully shuts down the server

type UDPServer

type UDPServer struct {
	// contains filtered or unexported fields
}

UDPServer represents a NetBIOS Name Server UDP component

func NewUDPServer

func NewUDPServer(addr string, nbns *NetBIOSNameServer) (*UDPServer, error)

NewUDPServer creates a new NBNS UDP server instance

func (*UDPServer) Start

func (s *UDPServer) Start() error

Start begins listening for UDP packets

func (*UDPServer) Stop

func (s *UDPServer) Stop()

Stop gracefully shuts down the server

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL