Git Product home page Git Product logo

rust-rawsock's People

Contributors

spacemeowx2 avatar szymonwieloch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

rust-rawsock's Issues

Panic when sending packet quickly

I'm using wpcap as backend. My program uses multithreading to send packets, but it panics when the rate is fast.

thread '<unnamed>' panicked at 'assertion failed: `(left == right)`
  left: `-1`,
 right: `0`', .....\rawsock-0.3.0\src\wpcap\interface.rs:85:13

Maybe instead of panic here, return a Result::Err(). This is helpful for error handling

Not loading `npcap` when `WinPcap` and `npcap` coexist.

It seems that we prefer npcap. But when WinPcap and npcap coexist, rawsock actually loads WinPcap.

pub const DEFAULT_PATHS: [&'static str; 4] = [
"NPcap\\Packet.dll",
"Packet.dll",
"Npcap\\wpcap.dll",
"wpcap.dll"
];

Since Npcap\wpcap.dll searchs Packet.dll instead of Npcap\Packet.dll(could be seen using procmon), and Npcap\wpcap.dll wouldn't load correctly with wrong Packet.dll.

And because what we need is wpcap.dll, I think all Packet.dll could be removed from default paths.

Solution:

I think it should be an issue about dlopen.

According to the document (npcap-sdk-1.03/docs/npcap-devguide.html#npcap-feature-native in npcap-sdk-1.03.zip), we need to call SetDllDirectory to make wpcap.dll loading right dll.

You need to do the following one step:

Before calling LoadLibrary to load wpcap.dll, call SetDllDirectory to add C:\Windows\System32\Npcap\ to DLL search path.

Crash on macOS

Command: cargo run --example dynamic

Opening packet capturing library
Library opened, version is  pcap libpcap version 1.8.1 -- Apple version 79.200.4
Opening the en0 interface
Interface opened, data link: ethernet
Sending 5 packets:
Sending ICMP ping packet no 0
Sending ICMP ping packet no 1
Sending ICMP ping packet no 2
Sending ICMP ping packet no 3
Sending ICMP ping packet no 4
Receiving 5 packets:
[1]    20518 segmentation fault  cargo run --example dynamic

I think uncomment this two line should work.

//#[cfg(target_os="macos")]
//pub comment: [c_char; 256]

pcap.h

struct pcap_pkthdr {
	struct timeval ts;	/* time stamp */
	bpf_u_int32 caplen;	/* length of portion present */
	bpf_u_int32 len;	/* length this packet (off wire) */
#ifdef __APPLE__
	char comment[256];
#endif
};

different struct timeval on macOS

tv_usec is 64bit unsigned integer.

pub tv_usec: c_long /* and microseconds */

But on macOS, tv_usec is 32bit unsigned integer with 32bit padding:

/usr/include/sys/_types/_timeval.h

#ifndef _STRUCT_TIMEVAL
#define _STRUCT_TIMEVAL		struct timeval

#include <machine/types.h> /* __darwin_time_t */
#include <sys/_types.h> /* __darwin_suseconds_t */

_STRUCT_TIMEVAL
{
	__darwin_time_t	        tv_sec;	        /* seconds */
	__darwin_suseconds_t    tv_usec;        /* and microseconds */
};
#endif /* _STRUCT_TIMEVAL */

/usr/include/sys/_types.h

typedef __int32_t	__darwin_suseconds_t;	/* [???] microseconds */

And using ida to see how the struct looks like:

00000000 timeval         struc ; (sizeof=0x10, align=0x8, copyof_63)
00000000                                         ; XREF: _uv__fs_futime/r
00000000                                         ; _uv__fs_utime/r ...
00000000 tv_sec          dq ?                    ; XREF: _uv_getrusage:loc_1001258B9/r
00000000                                         ; _uv_getrusage+56/r ...
00000008 tv_usec         dd ?                    ; XREF: _uv_getrusage+47/r
00000008                                         ; _uv_getrusage+65/r ...
0000000C                 db ? ; undefined
0000000D                 db ? ; undefined
0000000E                 db ? ; undefined
0000000F                 db ? ; undefined
00000010 timeval         ends

With this declaration, rawsock works fine on my machine.

///Equivalent of C struct timeval_t
#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct TimeVal {
    pub tv_sec: c_long,         /* seconds */
    pub tv_usec: c_uint        /* and microseconds */
}

PF_RING ZC

Hey,

I was going to look into making this work with PF_RING ZC if it doesn't already...
Is that something you've considered / looked at?

Very new to both Rust and userspace networking but currently building a low-latency network application and loving this library already!

Cheers

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.