MCPcopy Create free account
hub / github.com/secdev/scapy / NetBIOSNameField

Class NetBIOSNameField

scapy/fields.py:1928–1967  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1926
1927
1928class NetBIOSNameField(StrFixedLenField):
1929 def __init__(self, name, default, length=31):
1930 # type: (str, bytes, int) -> None
1931 StrFixedLenField.__init__(self, name, default, length)
1932
1933 def h2i(self, pkt, x):
1934 # type: (Optional[Packet], bytes) -> bytes
1935 if x and len(x) > 15:
1936 x = x[:15]
1937 return x
1938
1939 def i2m(self, pkt, y):
1940 # type: (Optional[Packet], Optional[bytes]) -> bytes
1941 if pkt:
1942 len_pkt = self.length_from(pkt) // 2
1943 else:
1944 len_pkt = 0
1945 x = bytes_encode(y or b"") # type: bytes
1946 x += b" " * len_pkt
1947 x = x[:len_pkt]
1948 x = b"".join(
1949 struct.pack(
1950 "!BB",
1951 0x41 + (b >> 4),
1952 0x41 + (b & 0xf),
1953 )
1954 for b in x
1955 )
1956 return b" " + x
1957
1958 def m2i(self, pkt, x):
1959 # type: (Optional[Packet], bytes) -> bytes
1960 x = x[1:].strip(b"\x00")
1961 return b"".join(map(
1962 lambda x, y: struct.pack(
1963 "!B",
1964 (((x - 1) & 0xf) << 4) + ((y - 1) & 0xf)
1965 ),
1966 x[::2], x[1::2]
1967 )).rstrip(b" ")
1968
1969
1970class StrLenField(StrField):

Callers 7

NetBIOS_DSClass · 0.90
NBNSQueryRequestClass · 0.90
NBNSQueryResponseClass · 0.90
NBNSWackResponseClass · 0.90
NBTDatagramClass · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…