title: Regarding struct.unpack() in python
body: <p>Level: Beginner. I am currently working on sniffers with python using raw sockets.
  I have a general question regarding the format specifiers to be used in unpack() provided by struct module. As we use this method to unpack the data according to the format specifiers specified. I have seen a lot of sniffer programmes using unpack() to decode the packet information from hexadecimal form.
  for an example in order to extract the ethernet header information following code can be used:</p>
  
  <pre><code>ethHeader = struct.unpack("!6s6s2s", ethernetHeader)
  </code></pre>
  
  <p>Here the ethernetHeader is variable that contains the actual ethernet header data captured earlier from a raw socket. Now my questions is how can one know which format specifier to use for a header? How can I know in advance that the ethernet addresses are in string format or in some other format? Is there any documentation for this too. I read python docs related to unpack() but didn't find any info. Similarly in the case of IP addresses the code is something like this:</p>
  
  <pre><code>ipAddresses = struct.unpack("!12s4s4s", IPAddresses)
  </code></pre>
  
  <p>Here the IPAddresses is variable that contains the actual IP addresses information captured earlier from a raw socket. Once again how can I know that I have to use strings as format specifiers (!12s4s4s).
  Thanks.</p>