Skip to content

Commit

Permalink
Tweaked nbd_client.py to properly handle handshake and transport flag…
Browse files Browse the repository at this point in the history
…s in new handshake protocol

Signed-off-by: Waldemar Kozaczuk <[email protected]>
  • Loading branch information
wkozaczuk committed May 16, 2019
1 parent e1292e7 commit 9cb7e73
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions scripts/nbd_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,17 @@ def _old_style_handshake(self, magic):
def _new_style_handshake(self, magic):
assert(magic == 0x49484156454F5054) # Should have received IHAVEOPT
buf = self._s.recv(2)
(self._flags) = struct.unpack(">H", buf)
(handshake_flags,) = struct.unpack(">H", buf)

client_flags = struct.pack('>L', 0)
self._s.send(client_flags)

options = struct.pack('>QLL', 0x49484156454F5054, 1, 0)
self._s.send(options)

buf = self._s.recv(8 + 2)
(self._size, self._flags) = struct.unpack(">QH", buf)
(self._size, transport_flags) = struct.unpack(">QH", buf)
self._flags = (handshake_flags << 16) + transport_flags

# ignore trailing zeroes
self._s.recv(124)
Expand Down

0 comments on commit 9cb7e73

Please sign in to comment.