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 586FF385B532 for ; Wed, 10 Apr 2024 16:00:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 586FF385B532 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 586FF385B532 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=1712764821; cv=none; b=BdbOW/ArKowyCB04HtwrlqcpTdIxo8aany6Ni6K+a0CWQcqaDTa1+Rr1wSpS8bJjxzFmQEm5J7rDdFew4XLzQoycXXNobZpWDpIri+0f1TEQd99yBWTW48tfi6GyajH41QmLou6NI+hn2QRQLPX+rSfv/jvMgGHUN5B5ECecb6k= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712764821; c=relaxed/simple; bh=NdvK2Hsu6+dskGmQ7q9iwkHK+lkyIDWPE6R+YgRmc7M=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=qtortZerJBVgAmTANVprt1QJ1SvcG4K7c+RovfaE1dzg5e5i3jK2f3B3GllgYtXyxdkCfkhxGWOZK8fQNaA0e9zZhMlHDNxkuhIX/APnMkpxylkqzKYUYOaa2k3hpUjRE1MiZER8mHuOwUTsboIBYJoZ4BkA6cHkGoHjcSvV6K4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712764817; 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=df1c6XhkUUsXvCXrw6wzjSbTKGDqQs9J08ZYYCqhXkeuzwFg9EMb97jHoSJPpSPTAvqa7o 8mejipGYjVwkBXo84OsUgycSF7VOoFj/GTrZtF5282DIN95ETBOnV5FUuWXx06CRpK9UZe diUF/oEhEwMXzpbBdywtWalm5GGlyf4= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-696-nyCHt4OaPMKlC2e9BLAuvQ-1; Wed, 10 Apr 2024 12:00:15 -0400 X-MC-Unique: nyCHt4OaPMKlC2e9BLAuvQ-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 2EC2029ABA04 for ; Wed, 10 Apr 2024 16:00:15 +0000 (UTC) Received: from sk-carbon-x9.redhat.com (unknown [10.45.224.126]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DCAF81C060A6; Wed, 10 Apr 2024 16:00:13 +0000 (UTC) From: Sergey Kolosov To: libc-alpha@sourceware.org Cc: Arjun Shankar Subject: [PATCH v3 1/2] libsupport: Add xgetpeername Date: Wed, 10 Apr 2024 17:58:04 +0200 Message-ID: <20240410160006.176758-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.5 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