From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 4DB6E3858C32 for ; Wed, 10 Apr 2024 14:31:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4DB6E3858C32 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4DB6E3858C32 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712759519; cv=none; b=Yd8dLfhG4MK/TOsoaCtHCIv63Z4Q8jcBdb2wLTk4KrjD4zV+TZ0H0qHhEN0dl+X5SQoXwatC6SlJXiiuVyOaOxrV+MuWv7S5t72PbTz/TDQuOWCtLl3MneuGywADKfDGw/jAbm53RioGeFkuFm/primHvWjidCcwKow3Gw+FpvM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712759519; c=relaxed/simple; bh=NdvK2Hsu6+dskGmQ7q9iwkHK+lkyIDWPE6R+YgRmc7M=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=FiyHBnuaB7L5nM875D+fOXKfbzBYm8Sbs9LHqv1B9IN3DRvfpyV6zETtvXrm8x0H8nNI2otD+8KWgwV0VgkAAiy1+gjpNPzC4T20Kd5+Q+432eF8G7NIBMwLPEpB65oTJG9s/amY5pO7bx8La3n1O48slHnY4O/G9n+go6uy7VA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712759517; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=kbvW+8qAVvrRp8zFPt5Of2tRul2WfWgJwDv6hz7vrNU=; b=K4ixPmUlmfAxRHaOO1gSJvlxoWVqQbLNFVZTalbI17hbH+lCygnzzqeupUC6cpGB80elJj fdp2MAx+rxqg2Okna+m49yQClxzVuSwMFPYfJGl4Po2UmlzmCxxVHoUxEWS9K3BZWN+iah sT9nbTDM5TbRzRDH5hlPPykoEQR9MwM= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-508-mhWIcrHSM4SEbsGooOBxWg-1; Wed, 10 Apr 2024 10:31:55 -0400 X-MC-Unique: mhWIcrHSM4SEbsGooOBxWg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 354D780171B for ; Wed, 10 Apr 2024 14:31:55 +0000 (UTC) Received: from sk-carbon-x9.redhat.com (unknown [10.45.224.126]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7A3C21C060D1; Wed, 10 Apr 2024 14:31:54 +0000 (UTC) From: Sergey Kolosov To: libc-alpha@sourceware.org Cc: Arjun Shankar Subject: [PATCH v2 1/2] libsupport: Add xgetpeername Date: Wed, 10 Apr 2024 16:30:46 +0200 Message-ID: <20240410143138.172319-1-skolosov@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-14.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: The patch adds redirections for getpeername. Reviewed-by: Arjun Shankar --- support/Makefile | 1 + support/xgetpeername.c | 30 ++++++++++++++++++++++++++++++ support/xsocket.h | 1 + 3 files changed, 32 insertions(+) create mode 100644 support/xgetpeername.c diff --git a/support/Makefile b/support/Makefile index 362a51f882..aa57207bdc 100644 --- a/support/Makefile +++ b/support/Makefile @@ -131,6 +131,7 @@ libsupport-routines = \ xfreopen \ xftruncate \ xgetline \ + xgetpeername \ xgetsockname \ xlisten \ xlseek \ diff --git a/support/xgetpeername.c b/support/xgetpeername.c new file mode 100644 index 0000000000..6f448e456a --- /dev/null +++ b/support/xgetpeername.c @@ -0,0 +1,30 @@ +/* getpeername with error checking. + Copyright (C) 2024 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include + +#include +#include +#include + +void +xgetpeername (int fd, struct sockaddr *sa, socklen_t *plen) +{ + if (getpeername (fd, sa, plen) != 0) + FAIL_EXIT1 ("getpeername (%d): %m", fd); +} diff --git a/support/xsocket.h b/support/xsocket.h index 3e44103546..4ac0e1f5ff 100644 --- a/support/xsocket.h +++ b/support/xsocket.h @@ -26,6 +26,7 @@ int xsocket (int, int, int); void xsetsockopt (int, int, int, const void *, socklen_t); void xgetsockname (int, struct sockaddr *, socklen_t *); +void xgetpeername (int, struct sockaddr *, socklen_t *); void xconnect (int, const struct sockaddr *, socklen_t); void xbind (int, const struct sockaddr *, socklen_t); void xlisten (int, int); -- 2.44.0