Hi all,
I've been working on adding support for raw sockets to Rust (
https://github.com/mozilla/rust/pull/11410), and was looking for input on
the API. I am considering something like the following:
enum Address {
IpAddress(IpAddr),
MacAddress(u8, u8, u8, u8, u8, u8)
}
// OSI Layer to work at, eg to put arbitary packets onto the network
use DataLinkProtocol,
// to implement an IP stack on top of ethernet use
NetworkProtocol(EthernetDataLinkProtocol(IpEthernetProtocol)) etc
enum Protocol {
DataLinkProtocol,
NetworkProtocol(DataLinkProto),
TransportProtocol(NetworkProto)
}
enum DataLinkProto {
EthernetDataLinkProtocol(EthernetProto),
OtherDataLinkProtocol(uint)
}
impl RawSocket {
pub fn new(protocol: Protocol) -> IoResult<RawSocket> {}
// Address would be filled when implementing network/transport
layer protocols
pub fn recvfrom(&mut self, buf: &mut [u8]) -> IoResult<(uint,
Option<Address>)> {}
// Address only required for network/transport
pub fn sendto(&mut self, buf: &[u8], dst: Option<Address>) ->
IoResult<int> {}
}
This gives a nice enum-based way to create a socket (just specify what
level you want to work at), and provides a way to work with protocols which
haven't been included with the enums (using OtherDataLinkProtocol(<arbitary
number>) for example).
Does this seem sufficient? Is there anything I've missed/is there a nicer
way I could express this?
Thanks,
Robert
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev