Skip to content

Commit 880bbd3

Browse files
committed
Remove address type variants of bind, connect, sendmsg, sendto
Removes: * `bind_any`, `bind_unix`, `bind_v4`, `bind_v6`, `bind_xdp` in favor of `bind`, * `connect_any`, `connect_unix`, `connect_v4`, `connect_v6` in favor of `connect` (leaving address-less `connect_unspec`) * `sendmsg_v4`, `sendmsg_v6`, `sendmsg_unix`, `sendmsg_xdp`, `sendmsg_any` in favor of `sendmsg_addr` (leaving address-less `sendmsg`) * `sendto_any`, `sendto_v4`, `sendto_v6`, `sendto_unix`, `sendto_xdp` in favor of `sendto`
1 parent 4daf770 commit 880bbd3

14 files changed

+132
-742
lines changed

src/event/epoll.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
//! use rustix::fd::AsFd;
1010
//! use rustix::io::{ioctl_fionbio, read, write};
1111
//! use rustix::net::{
12-
//! accept, bind_v4, listen, socket, AddressFamily, Ipv4Addr, SocketAddrV4, SocketType,
12+
//! accept, bind, listen, socket, AddressFamily, Ipv4Addr, SocketAddrV4, SocketType,
1313
//! };
1414
//! use std::collections::HashMap;
1515
//! use std::os::unix::io::AsRawFd;
1616
//!
1717
//! // Create a socket and listen on it.
1818
//! let listen_sock = socket(AddressFamily::INET, SocketType::STREAM, None)?;
19-
//! bind_v4(&listen_sock, &SocketAddrV4::new(Ipv4Addr::LOCALHOST, 0))?;
19+
//! bind(&listen_sock, &SocketAddrV4::new(Ipv4Addr::LOCALHOST, 0))?;
2020
//! listen(&listen_sock, 1)?;
2121
//!
2222
//! // Create an epoll object. Using `Owning` here means the epoll object will

src/net/send_recv/mod.rs

+1-175
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@
33
#![allow(unsafe_code)]
44

55
use crate::buffer::split_init;
6-
#[cfg(target_os = "linux")]
7-
use crate::net::xdp::SocketAddrXdp;
8-
#[cfg(unix)]
9-
use crate::net::SocketAddrUnix;
10-
use crate::net::{addr::SocketAddrArg, SocketAddrAny, SocketAddrV4, SocketAddrV6};
6+
use crate::net::{addr::SocketAddrArg, SocketAddrAny};
117
use crate::{backend, io};
128
use backend::fd::AsFd;
139
use core::cmp::min;
@@ -217,173 +213,3 @@ pub fn sendto<Fd: AsFd>(
217213
) -> io::Result<usize> {
218214
backend::net::syscalls::sendto(fd.as_fd(), buf, flags, addr)
219215
}
220-
221-
/// `sendto(fd, buf, flags, addr)`—Writes data to a socket to a specific
222-
/// address.
223-
///
224-
/// # References
225-
/// - [Beej's Guide to Network Programming]
226-
/// - [POSIX]
227-
/// - [Linux]
228-
/// - [Apple]
229-
/// - [Winsock]
230-
/// - [FreeBSD]
231-
/// - [NetBSD]
232-
/// - [OpenBSD]
233-
/// - [DragonFly BSD]
234-
/// - [illumos]
235-
/// - [glibc]
236-
///
237-
/// [Beej's Guide to Network Programming]: https://beej.us/guide/bgnet/html/split/system-calls-or-bust.html#sendtorecv
238-
/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/sendto.html
239-
/// [Linux]: https://man7.org/linux/man-pages/man2/sendto.2.html
240-
/// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/sendto.2.html
241-
/// [Winsock]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-sendto
242-
/// [FreeBSD]: https://man.freebsd.org/cgi/man.cgi?query=sendto&sektion=2
243-
/// [NetBSD]: https://man.netbsd.org/sendto.2
244-
/// [OpenBSD]: https://man.openbsd.org/sendto.2
245-
/// [DragonFly BSD]: https://man.dragonflybsd.org/?command=sendto&section=2
246-
/// [illumos]: https://illumos.org/man/3SOCKET/sendto
247-
/// [glibc]: https://sourceware.org/glibc/manual/latest/html_node/Sending-Datagrams.html
248-
pub fn sendto_any<Fd: AsFd>(
249-
fd: Fd,
250-
buf: &[u8],
251-
flags: SendFlags,
252-
addr: &SocketAddrAny,
253-
) -> io::Result<usize> {
254-
backend::net::syscalls::sendto(fd.as_fd(), buf, flags, addr)
255-
}
256-
257-
/// `sendto(fd, buf, flags, addr, sizeof(struct sockaddr_in))`—Writes data to
258-
/// a socket to a specific IPv4 address.
259-
///
260-
/// # References
261-
/// - [Beej's Guide to Network Programming]
262-
/// - [POSIX]
263-
/// - [Linux]
264-
/// - [Apple]
265-
/// - [Winsock]
266-
/// - [FreeBSD]
267-
/// - [NetBSD]
268-
/// - [OpenBSD]
269-
/// - [DragonFly BSD]
270-
/// - [illumos]
271-
/// - [glibc]
272-
///
273-
/// [Beej's Guide to Network Programming]: https://beej.us/guide/bgnet/html/split/system-calls-or-bust.html#sendtorecv
274-
/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/sendto.html
275-
/// [Linux]: https://man7.org/linux/man-pages/man2/sendto.2.html
276-
/// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/sendto.2.html
277-
/// [Winsock]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-sendto
278-
/// [FreeBSD]: https://man.freebsd.org/cgi/man.cgi?query=sendto&sektion=2
279-
/// [NetBSD]: https://man.netbsd.org/sendto.2
280-
/// [OpenBSD]: https://man.openbsd.org/sendto.2
281-
/// [DragonFly BSD]: https://man.dragonflybsd.org/?command=sendto&section=2
282-
/// [illumos]: https://illumos.org/man/3SOCKET/sendto
283-
/// [glibc]: https://sourceware.org/glibc/manual/latest/html_node/Sending-Datagrams.html
284-
#[inline]
285-
#[doc(alias = "sendto")]
286-
pub fn sendto_v4<Fd: AsFd>(
287-
fd: Fd,
288-
buf: &[u8],
289-
flags: SendFlags,
290-
addr: &SocketAddrV4,
291-
) -> io::Result<usize> {
292-
backend::net::syscalls::sendto(fd.as_fd(), buf, flags, addr)
293-
}
294-
295-
/// `sendto(fd, buf, flags, addr, sizeof(struct sockaddr_in6))`—Writes data
296-
/// to a socket to a specific IPv6 address.
297-
///
298-
/// # References
299-
/// - [Beej's Guide to Network Programming]
300-
/// - [POSIX]
301-
/// - [Linux]
302-
/// - [Apple]
303-
/// - [Winsock]
304-
/// - [FreeBSD]
305-
/// - [NetBSD]
306-
/// - [OpenBSD]
307-
/// - [DragonFly BSD]
308-
/// - [illumos]
309-
/// - [glibc]
310-
///
311-
/// [Beej's Guide to Network Programming]: https://beej.us/guide/bgnet/html/split/system-calls-or-bust.html#sendtorecv
312-
/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/sendto.html
313-
/// [Linux]: https://man7.org/linux/man-pages/man2/sendto.2.html
314-
/// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/sendto.2.html
315-
/// [Winsock]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-sendto
316-
/// [FreeBSD]: https://man.freebsd.org/cgi/man.cgi?query=sendto&sektion=2
317-
/// [NetBSD]: https://man.netbsd.org/sendto.2
318-
/// [OpenBSD]: https://man.openbsd.org/sendto.2
319-
/// [DragonFly BSD]: https://man.dragonflybsd.org/?command=sendto&section=2
320-
/// [illumos]: https://illumos.org/man/3SOCKET/sendto
321-
/// [glibc]: https://sourceware.org/glibc/manual/latest/html_node/Sending-Datagrams.html
322-
#[inline]
323-
#[doc(alias = "sendto")]
324-
pub fn sendto_v6<Fd: AsFd>(
325-
fd: Fd,
326-
buf: &[u8],
327-
flags: SendFlags,
328-
addr: &SocketAddrV6,
329-
) -> io::Result<usize> {
330-
backend::net::syscalls::sendto(fd.as_fd(), buf, flags, addr)
331-
}
332-
333-
/// `sendto(fd, buf, flags, addr, sizeof(struct sockaddr_un))`—Writes data to
334-
/// a socket to a specific Unix-domain socket address.
335-
///
336-
/// # References
337-
/// - [Beej's Guide to Network Programming]
338-
/// - [POSIX]
339-
/// - [Linux]
340-
/// - [Apple]
341-
/// - [Winsock]
342-
/// - [FreeBSD]
343-
/// - [NetBSD]
344-
/// - [OpenBSD]
345-
/// - [DragonFly BSD]
346-
/// - [illumos]
347-
/// - [glibc]
348-
///
349-
/// [Beej's Guide to Network Programming]: https://beej.us/guide/bgnet/html/split/system-calls-or-bust.html#sendtorecv
350-
/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/sendto.html
351-
/// [Linux]: https://man7.org/linux/man-pages/man2/sendto.2.html
352-
/// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/sendto.2.html
353-
/// [Winsock]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-sendto
354-
/// [FreeBSD]: https://man.freebsd.org/cgi/man.cgi?query=sendto&sektion=2
355-
/// [NetBSD]: https://man.netbsd.org/sendto.2
356-
/// [OpenBSD]: https://man.openbsd.org/sendto.2
357-
/// [DragonFly BSD]: https://man.dragonflybsd.org/?command=sendto&section=2
358-
/// [illumos]: https://illumos.org/man/3SOCKET/sendto
359-
/// [glibc]: https://sourceware.org/glibc/manual/latest/html_node/Sending-Datagrams.html
360-
#[cfg(unix)]
361-
#[inline]
362-
#[doc(alias = "sendto")]
363-
pub fn sendto_unix<Fd: AsFd>(
364-
fd: Fd,
365-
buf: &[u8],
366-
flags: SendFlags,
367-
addr: &SocketAddrUnix,
368-
) -> io::Result<usize> {
369-
backend::net::syscalls::sendto(fd.as_fd(), buf, flags, addr)
370-
}
371-
372-
/// `sendto(fd, buf, flags, addr, sizeof(struct sockaddr_xdp))`—Writes data
373-
/// to a socket to a specific XDP address.
374-
///
375-
/// # References
376-
/// - [Linux]
377-
///
378-
/// [Linux]: https://man7.org/linux/man-pages/man2/sendto.2.html
379-
#[cfg(target_os = "linux")]
380-
#[inline]
381-
#[doc(alias = "sendto")]
382-
pub fn sendto_xdp<Fd: AsFd>(
383-
fd: Fd,
384-
buf: &[u8],
385-
flags: SendFlags,
386-
addr: &SocketAddrXdp,
387-
) -> io::Result<usize> {
388-
backend::net::syscalls::sendto(fd.as_fd(), buf, flags, addr)
389-
}

src/net/send_recv/msg.rs

+4-156
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use core::mem::{align_of, size_of, size_of_val, take};
1717
use core::ptr::addr_of;
1818
use core::{ptr, slice};
1919

20-
use super::{RecvFlags, ReturnFlags, SendFlags, SocketAddrAny, SocketAddrV4, SocketAddrV6};
20+
use super::{RecvFlags, ReturnFlags, SendFlags, SocketAddrAny};
2121

2222
/// Macro for defining the amount of space to allocate in a buffer for use with
2323
/// [`RecvAncillaryBuffer::new`] and [`SendAncillaryBuffer::new`].
@@ -122,8 +122,7 @@ pub const fn __cmsg_aligned_space(len: usize) -> usize {
122122
unsafe { c::CMSG_SPACE(converted_len) as usize }
123123
}
124124

125-
/// Ancillary message for [`sendmsg`], [`sendmsg_v4`], [`sendmsg_v6`],
126-
/// [`sendmsg_unix`], and [`sendmsg_any`].
125+
/// Ancillary message for [`sendmsg`] and [`sendmsg_addr`].
127126
#[non_exhaustive]
128127
pub enum SendAncillaryMessage<'slice, 'fd> {
129128
/// Send file descriptors.
@@ -160,8 +159,7 @@ pub enum RecvAncillaryMessage<'a> {
160159
ScmCredentials(UCred),
161160
}
162161

163-
/// Buffer for sending ancillary messages with [`sendmsg`], [`sendmsg_v4`],
164-
/// [`sendmsg_v6`], [`sendmsg_unix`], and [`sendmsg_any`].
162+
/// Buffer for sending ancillary messages with [`sendmsg`] and [`sendmsg_addr`].
165163
///
166164
/// Use the [`push`] function to add messages to send.
167165
///
@@ -596,8 +594,7 @@ impl FusedIterator for AncillaryDrain<'_> {}
596594
/// `sendmsg(msghdr)`—Sends a message on a socket.
597595
///
598596
/// This function is for use on connected sockets, as it doesn't have
599-
/// a way to specify an address. See the [`sendmsg_v4`], [`sendmsg_v6`]
600-
/// [`sendmsg_unix`], [`sendmsg_xdp`], and [`sendmsg_any`] to send
597+
/// a way to specify an address. See [`sendmsg_addr`] to send
601598
/// messages on unconnected sockets.
602599
///
603600
/// # References
@@ -659,155 +656,6 @@ pub fn sendmsg_addr(
659656
backend::net::syscalls::sendmsg_addr(socket.as_fd(), addr, iov, control, flags)
660657
}
661658

662-
/// `sendmsg(msghdr)`—Sends a message on a socket to a specific IPv4 address.
663-
///
664-
/// # References
665-
/// - [POSIX]
666-
/// - [Linux]
667-
/// - [Apple]
668-
/// - [FreeBSD]
669-
/// - [NetBSD]
670-
/// - [OpenBSD]
671-
/// - [DragonFly BSD]
672-
/// - [illumos]
673-
///
674-
/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/sendmsg.html
675-
/// [Linux]: https://man7.org/linux/man-pages/man2/sendmsg.2.html
676-
/// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/sendmsg.2.html
677-
/// [FreeBSD]: https://man.freebsd.org/cgi/man.cgi?query=sendmsg&sektion=2
678-
/// [NetBSD]: https://man.netbsd.org/sendmsg.2
679-
/// [OpenBSD]: https://man.openbsd.org/sendmsg.2
680-
/// [DragonFly BSD]: https://man.dragonflybsd.org/?command=sendmsg&section=2
681-
/// [illumos]: https://illumos.org/man/3SOCKET/sendmsg
682-
#[inline]
683-
pub fn sendmsg_v4<Fd: AsFd>(
684-
socket: Fd,
685-
addr: &SocketAddrV4,
686-
iov: &[IoSlice<'_>],
687-
control: &mut SendAncillaryBuffer<'_, '_, '_>,
688-
flags: SendFlags,
689-
) -> io::Result<usize> {
690-
backend::net::syscalls::sendmsg_addr(socket.as_fd(), addr, iov, control, flags)
691-
}
692-
693-
/// `sendmsg(msghdr)`—Sends a message on a socket to a specific IPv6 address.
694-
///
695-
/// # References
696-
/// - [POSIX]
697-
/// - [Linux]
698-
/// - [Apple]
699-
/// - [FreeBSD]
700-
/// - [NetBSD]
701-
/// - [OpenBSD]
702-
/// - [DragonFly BSD]
703-
/// - [illumos]
704-
///
705-
/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/sendmsg.html
706-
/// [Linux]: https://man7.org/linux/man-pages/man2/sendmsg.2.html
707-
/// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/sendmsg.2.html
708-
/// [FreeBSD]: https://man.freebsd.org/cgi/man.cgi?query=sendmsg&sektion=2
709-
/// [NetBSD]: https://man.netbsd.org/sendmsg.2
710-
/// [OpenBSD]: https://man.openbsd.org/sendmsg.2
711-
/// [DragonFly BSD]: https://man.dragonflybsd.org/?command=sendmsg&section=2
712-
/// [illumos]: https://illumos.org/man/3SOCKET/sendmsg
713-
#[inline]
714-
pub fn sendmsg_v6<Fd: AsFd>(
715-
socket: Fd,
716-
addr: &SocketAddrV6,
717-
iov: &[IoSlice<'_>],
718-
control: &mut SendAncillaryBuffer<'_, '_, '_>,
719-
flags: SendFlags,
720-
) -> io::Result<usize> {
721-
backend::net::syscalls::sendmsg_addr(socket.as_fd(), addr, iov, control, flags)
722-
}
723-
724-
/// `sendmsg(msghdr)`—Sends a message on a socket to a specific Unix-domain
725-
/// address.
726-
///
727-
/// # References
728-
/// - [POSIX]
729-
/// - [Linux]
730-
/// - [Apple]
731-
/// - [FreeBSD]
732-
/// - [NetBSD]
733-
/// - [OpenBSD]
734-
/// - [DragonFly BSD]
735-
/// - [illumos]
736-
///
737-
/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/sendmsg.html
738-
/// [Linux]: https://man7.org/linux/man-pages/man2/sendmsg.2.html
739-
/// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/sendmsg.2.html
740-
/// [FreeBSD]: https://man.freebsd.org/cgi/man.cgi?query=sendmsg&sektion=2
741-
/// [NetBSD]: https://man.netbsd.org/sendmsg.2
742-
/// [OpenBSD]: https://man.openbsd.org/sendmsg.2
743-
/// [DragonFly BSD]: https://man.dragonflybsd.org/?command=sendmsg&section=2
744-
/// [illumos]: https://illumos.org/man/3SOCKET/sendmsg
745-
#[inline]
746-
#[cfg(unix)]
747-
pub fn sendmsg_unix<Fd: AsFd>(
748-
socket: Fd,
749-
addr: &super::SocketAddrUnix,
750-
iov: &[IoSlice<'_>],
751-
control: &mut SendAncillaryBuffer<'_, '_, '_>,
752-
flags: SendFlags,
753-
) -> io::Result<usize> {
754-
backend::net::syscalls::sendmsg_addr(socket.as_fd(), addr, iov, control, flags)
755-
}
756-
757-
/// `sendmsg(msghdr)`—Sends a message on a socket to a specific XDP address.
758-
///
759-
/// # References
760-
/// - [Linux]
761-
///
762-
/// [Linux]: https://man7.org/linux/man-pages/man2/sendmsg.2.html
763-
#[inline]
764-
#[cfg(target_os = "linux")]
765-
pub fn sendmsg_xdp<Fd: AsFd>(
766-
socket: Fd,
767-
addr: &super::SocketAddrXdp,
768-
iov: &[IoSlice<'_>],
769-
control: &mut SendAncillaryBuffer<'_, '_, '_>,
770-
flags: SendFlags,
771-
) -> io::Result<usize> {
772-
backend::net::syscalls::sendmsg_addr(socket.as_fd(), addr, iov, control, flags)
773-
}
774-
775-
/// `sendmsg(msghdr)`—Sends a message on a socket to a specific address.
776-
///
777-
/// # References
778-
/// - [POSIX]
779-
/// - [Linux]
780-
/// - [Apple]
781-
/// - [FreeBSD]
782-
/// - [NetBSD]
783-
/// - [OpenBSD]
784-
/// - [DragonFly BSD]
785-
/// - [illumos]
786-
///
787-
/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/sendmsg.html
788-
/// [Linux]: https://man7.org/linux/man-pages/man2/sendmsg.2.html
789-
/// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/sendmsg.2.html
790-
/// [FreeBSD]: https://man.freebsd.org/cgi/man.cgi?query=sendmsg&sektion=2
791-
/// [NetBSD]: https://man.netbsd.org/sendmsg.2
792-
/// [OpenBSD]: https://man.openbsd.org/sendmsg.2
793-
/// [DragonFly BSD]: https://man.dragonflybsd.org/?command=sendmsg&section=2
794-
/// [illumos]: https://illumos.org/man/3SOCKET/sendmsg
795-
#[inline]
796-
pub fn sendmsg_any<Fd: AsFd>(
797-
socket: Fd,
798-
addr: Option<&SocketAddrAny>,
799-
iov: &[IoSlice<'_>],
800-
control: &mut SendAncillaryBuffer<'_, '_, '_>,
801-
flags: SendFlags,
802-
) -> io::Result<usize> {
803-
match addr {
804-
None => backend::net::syscalls::sendmsg(socket.as_fd(), iov, control, flags),
805-
Some(addr) => {
806-
backend::net::syscalls::sendmsg_addr(socket.as_fd(), addr, iov, control, flags)
807-
}
808-
}
809-
}
810-
811659
/// `recvmsg(msghdr)`—Receives a message from a socket.
812660
///
813661
/// # References

0 commit comments

Comments
 (0)