pythonsocketsnetwork-programmingsniffer

what is the meaning of this python code: <L in struct.pack("<L",self.src)


My problem is to understand the meaning of: <L in this python code:

self.src_address = socket.inet_ntoa(struct.pack("<L",self.src))

Solution

  • The format-string "<L" in the expression struct.pack("<L",self.src) means that pack interpretes the value in self.src as little-endian ordered unsigned long value. The endianess is a convention, which determines in which direction a sequence of bits are interpreted as a number: from (Big-endian) left to right, or from (Little-endian) right to left.

    Afterwards the unsigned long number is conterted to standard dotted-quad string representation via socket.inet_ntoa()