factor out sockname and peername