Inferno
Inferno

Reputation: 47

Erlang: How to make an UDP packet

How can I make an UDP packet in Erlang? The backbone of packets:

byte 0-3: SAMP byte 4: 127 byte 5: 0 byte 6: 0 byte 7: 1 byte 8: first byte of '7777' byte 9: second byte of '7777' byte 10: 'i'

Upvotes: 1

Views: 467

Answers (1)

rvirding
rvirding

Reputation: 20916

<<SAMP:32,127,0,0,1,7777:16,$i>>

assuming SAMP is a variable and 'i' is the character "i".

Look at Bit Syntax Expressions for the syntax of binaries and Bit Syntax Examples for more examples. The second one has an example of writing an IP packet in one bit syntax expression/pattern, which is very neat.

Upvotes: 2

Related Questions