From patchwork Mon Apr 8 10:25:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Kolosov X-Patchwork-Id: 88160 X-Patchwork-Delegate: arjun.is@lostca.se Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CD9DF3858426 for ; Mon, 8 Apr 2024 10:26:43 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org 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 02C143858D32 for ; Mon, 8 Apr 2024 10:26:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 02C143858D32 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 02C143858D32 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=1712571975; cv=none; b=rrRXbiZUA0/SBZxHEGHjcyLVqbmNE1J+5MCSRW8tgB0EVWSVkTehPpX0TDq/WSAbp1QPBe8XmjZbxvJYPbNBFgjKq3f2sQgFo9rpiIaOK9Ak1sBtVLWswoxBlYT+TtkZYwt9AkTucTfa5Yk3/fAVksmk3Jon6HfhilRXHHPyWoE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712571975; c=relaxed/simple; bh=aMRzstUqrLOTeJTGELL6gCmSWLOW2ckugn2y3AvmbgM=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=etCUTcbJSQXGVkzc/Ba/gWbUWgYWTxBSRA21WoIjmffOi/CXG/oE380msmlfLIhKJZZo3eL7GXovzVtS/isa/3ssN2UmHRTnMIdTIxwzliNsx9nK+j6lqRW4AOL0xY9C9WPRj7tDVkgEfUnUDQ+eAm7aiFC5sRAjO6LfYKYUgDM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712571973; 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=hODdPK2JXBQtwXpaFNSkS5PZNB6AdqqOMkzLqv5Tr6M=; b=D08e7vnW08Et5cFd5L/4zdhvbaFvFKJQBkCCiREmKuDlWQyCJSHOSzeP/eK+pH0Ig4i4jL ttnYKvbCtmUDED3cnsJPQAlFdjvdxh+HhfOO+AnVGHf9TOTv0V8KXE5w2I/ZnmXn5YfxAU L/KbRyKeWZUoFw3lPv36/pD8L2nlkfI= 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-88-lXk9KPkeNBG7xyeIAFAziw-1; Mon, 08 Apr 2024 06:26:12 -0400 X-MC-Unique: lXk9KPkeNBG7xyeIAFAziw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 1816A889F44 for ; Mon, 8 Apr 2024 10:26:12 +0000 (UTC) Received: from sk-carbon-x9.redhat.com (unknown [10.45.225.71]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 98DEC40AE784; Mon, 8 Apr 2024 10:26:11 +0000 (UTC) From: Sergey Kolosov To: libc-alpha@sourceware.org Cc: Sergey Kolosov Subject: [PATCH 1/2] libsupport: Add xgetpeername Date: Mon, 8 Apr 2024 12:25:39 +0200 Message-ID: <20240408102543.18143-1-skolosov@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.9 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 X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org 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);