Little things please little minds

I ran the register_service.py script at the same time as the following UDP listener:

#!/usr/bin/python
import socket
HOST='192.168.0.226'
PORT=5004
s = socket.socket( socket.AF_INET , socket.SOCK_DGRAM )
s.bind( (HOST, PORT ) )
buffer = s.recv(1024)
print buffer.encode('hex')

The service shows up in the Audio MIDI setup. When I connected to that server, the output was:

ffff494e00000002663348739ec3dbe341433700

which matched up with expectations !

I’m looking at DPKT (┬áhttp://code.google.com/p/dpkt/ ) to help me construct the data packets in Python seeing as I really don’t have the energy to play around with bytes.

I needed to create a parser for the initial Apple MIDI conversation.

import dpkt
class COMMAND(dpkt.Packet):
 __hdr__ = (
 ('signature', 'H', 0),
 ('command', '2s', 0),
 ('version', 'I', 2),
 ('initiator', 'I', 0),
 ('sender_ssrc', 'I', 0),
 ('name', '4s', ''),
 )

However, I need to look into the fact that name can be any length and is null-terminated. DPKT works on fixed lengths.