def generate_local_port():
global _PREVIOUS_LOCAL_PORT<EOL>if _PREVIOUS_LOCAL_PORT is None:<EOL><INDENT>try:<EOL><INDENT>with contextlib.closing(socket.socket(getattr(socket, '<STR_LIT>', -<NUM_LIT:1>), socket.SOCK_RAW)) as s:<EOL><INDENT>s.bind((<NUM_LIT:0>, <NUM_LIT:0>))<EOL>_PREVIOUS_LOCAL_PORT = int(s.getsockname()[<NUM_LIT:0>])<EOL><DEDENT><DEDENT>except OSError:<EOL><INDENT>_PREVIOUS_LOCAL_PORT = <NUM_LIT>  <EOL><DEDENT><DEDENT>return int(_PREVIOUS_LOCAL_PORT)<EOL>
https://github.com/thom311/libnl/blob/libnl3_2_25/lib/socket.c#L63.