├── wrapper.h ├── .gitmodules ├── .gitignore ├── Cargo.toml ├── examples ├── inittest.rs └── host.rs ├── README.md ├── LICENSE └── src └── lib.rs /wrapper.h: -------------------------------------------------------------------------------- 1 | #include "vendor/enet/include/enet/enet.h" -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "vendor/enet"] 2 | path = vendor/enet 3 | url = https://github.com/lsalzman/enet.git 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled files 2 | *.o 3 | *.so 4 | *.rlib 5 | *.dll 6 | 7 | # Executables 8 | *.exe 9 | 10 | # Generated by Cargo 11 | /target/ 12 | 13 | /.vscode/ 14 | 15 | # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries 16 | # More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock 17 | Cargo.lock 18 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "enet-sys" 3 | version = "1.0.4" 4 | authors = ["Roland Ruckerbauer "] 5 | description = "Low level bindings to the enet C library" 6 | license = "MIT" 7 | repository = "https://github.com/ruabmbua/enet-sys" 8 | links = "enet" 9 | build = "build.rs" 10 | 11 | [build-dependencies] 12 | bindgen = "0.65.1" 13 | cmake = "0.1.44" 14 | -------------------------------------------------------------------------------- /examples/inittest.rs: -------------------------------------------------------------------------------- 1 | extern crate enet_sys; 2 | 3 | use enet_sys::{enet_deinitialize, enet_initialize}; 4 | 5 | fn main() { 6 | println!("Starting test of enet bindings..."); 7 | if unsafe { enet_initialize() } < 0 { 8 | panic!("Error on enet initialization."); 9 | } 10 | println!("Enet initialized."); 11 | unsafe { 12 | enet_deinitialize(); 13 | } 14 | println!("Enet deinitialized."); 15 | } 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Raw rust bindings to the [enet](http://enet.bespin.org/) C library. 2 | 3 | # Dependencies 4 | 5 | * C, or C cross compiler for your target platform 6 | 7 | ## Ubuntu 8 | 9 | Dependencies for Ubuntu can be installed with 10 | 11 | ```bash 12 | sudo apt update 13 | sudo apt install build-essential clang cmake 14 | ``` 15 | 16 | ## Archlinux 17 | 18 | ```bash 19 | pacman -S base-devel clang cmake 20 | ``` 21 | 22 | # Cloning 23 | `enet-sys` uses git submodules, either clone it with the `--recursive` option, or run: 24 | ``` git 25 | git submodule init 26 | git submodule update 27 | ``` 28 | after cloning it. 29 | 30 | **Note:** If you add enet-sys as a dependency to your `Cargo.toml`, cargo will do this for you automatically. 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2018 Roland Ruckerbauer 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /examples/host.rs: -------------------------------------------------------------------------------- 1 | extern crate enet_sys; 2 | 3 | use enet_sys::ENetAddress; 4 | use enet_sys::{enet_deinitialize, enet_initialize}; 5 | use enet_sys::{enet_host_create, enet_host_destroy}; 6 | 7 | fn main() { 8 | println!("Starting test of host creation..."); 9 | if unsafe { enet_initialize() } < 0 { 10 | panic!("Error on enet initialization."); 11 | } 12 | println!("Enet initialized."); 13 | 14 | println!("creating ENet server host..."); 15 | 16 | // default localhost on port 12345 17 | let address = ENetAddress { 18 | host: 0, 19 | port: 12345, 20 | }; 21 | 22 | unsafe { 23 | let server = enet_host_create( 24 | &address, // address to bind the server host to 25 | 32, // allow up to 32 clients and/or outgoing connections 26 | 2, // allow up to 2 channels to be used, 0 and 1 27 | 0, // assume any amount of incoming bandwidth 28 | 0, 29 | ); // assume any amount of outgoing bandwidth 30 | if server.is_null() { 31 | panic!("error: host create returned null") 32 | } 33 | println!("...ENet server host created"); 34 | 35 | println!("server: {:p}", server); 36 | println!("server peers: {:p}", server.as_ref().unwrap().peers); 37 | println!("server &packetData: {:p}", &(*server).packetData); 38 | println!("server &serviceTime: {:p}", &(*server).serviceTime); 39 | println!("server channelLimit: {}", (*server).channelLimit); 40 | println!("server peerCount: {}", server.as_ref().unwrap().peerCount); 41 | println!("server connectedPeers: {}", (*server).connectedPeers); 42 | println!("server randomSeed: {:?}", (*server).randomSeed); 43 | println!("server socket: {:?}", (*server).socket); 44 | 45 | enet_host_destroy(server); 46 | } 47 | 48 | unsafe { 49 | enet_deinitialize(); 50 | } 51 | println!("Enet deinitialized."); 52 | } 53 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | #![allow(non_upper_case_globals)] 2 | #![allow(non_camel_case_types)] 3 | #![allow(non_snake_case)] 4 | #![allow(improper_ctypes)] 5 | #![allow(deref_nullptr)] 6 | 7 | include!(concat!(env!("OUT_DIR"), "/bindings.rs")); 8 | 9 | /// enet size_t type alias for keeping compatible with previous 10 | /// versions of this crate. 11 | #[deprecated] 12 | pub type size_t = usize; 13 | 14 | // Items, that could not be generated with bindgen, because they involentarily create valid doctests in their comments. 15 | 16 | #[doc = " ENet packet structure."] 17 | #[doc = ""] 18 | #[doc = " An ENet data packet that may be sent to or received from a peer. The shown"] 19 | #[doc = " fields should only be read and never modified. The data field contains the"] 20 | #[doc = " allocated data for the packet. The dataLength fields specifies the length"] 21 | #[doc = " of the allocated data. The flags field is either 0 (specifying no flags),"] 22 | #[doc = " or a bitwise-or of any combination of the following flags:"] 23 | #[doc = ""] 24 | #[doc = " ENET_PACKET_FLAG_RELIABLE - packet must be received by the target peer"] 25 | #[doc = " and resend attempts should be made until the packet is delivered"] 26 | #[doc = ""] 27 | #[doc = " ENET_PACKET_FLAG_UNSEQUENCED - packet will not be sequenced with other packets"] 28 | #[doc = " (not supported for reliable packets)"] 29 | #[doc = ""] 30 | #[doc = " ENET_PACKET_FLAG_NO_ALLOCATE - packet will not allocate data, and user must supply it instead"] 31 | #[doc = ""] 32 | #[doc = " ENET_PACKET_FLAG_UNRELIABLE_FRAGMENT - packet will be fragmented using unreliable"] 33 | #[doc = " (instead of reliable) sends if it exceeds the MTU"] 34 | #[doc = ""] 35 | #[doc = " ENET_PACKET_FLAG_SENT - whether the packet has been sent from all queues it has been entered into"] 36 | #[doc = "@sa ENetPacketFlag"] 37 | #[repr(C)] 38 | #[derive(Copy, Clone)] 39 | pub struct _ENetPacket { 40 | #[doc = "< internal use only"] 41 | pub referenceCount: usize, 42 | #[doc = "< bitwise-or of ENetPacketFlag constants"] 43 | pub flags: enet_uint32, 44 | #[doc = "< allocated data for packet"] 45 | pub data: *mut enet_uint8, 46 | #[doc = "< length of data"] 47 | pub dataLength: usize, 48 | #[doc = "< function to be called when the packet is no longer in use"] 49 | pub freeCallback: ENetPacketFreeCallback, 50 | #[doc = "< application private data, may be freely modified"] 51 | pub userData: *mut ::std::os::raw::c_void, 52 | } 53 | 54 | pub type ENetPacket = _ENetPacket; 55 | --------------------------------------------------------------------------------