msantos / gen_icmp Goto Github PK
View Code? Open in Web Editor NEWErlang interface to ICMP sockets
Home Page: http://listincomprehension.com/2010/12/icmp-ping-in-erlang-part-2.html
License: BSD 3-Clause "New" or "Revised" License
Erlang interface to ICMP sockets
Home Page: http://listincomprehension.com/2010/12/icmp-ping-in-erlang-part-2.html
License: BSD 3-Clause "New" or "Revised" License
rebar compile
==> procket (compile)
/usr/bin/ld: cannot find -lancillary
collect2: ld returned 1 exit status
ERROR: cc c_src/procket.o -Lc_src -lancillary -shared -L/usr/local/lib/erlang/lib/erl_interface-3.7.4/lib -lerl_interface -lei -o priv/procket.so failed with error: 1
I'm using :gen_icmp.ping in an Elixir project.
The code works fine when I run it via mix on my laptop, but when I make a release with distillery and run the same code on CentOS7, the line:
:gen_icmp.ping(addr)
crashes the process without any message.
I'm building the release inside a docker centos7 container. But later trying to run it on a physical CentOS 7 server.
Hi, Any idea how I could return something like :
$ ping friendpaste.com
PING friendpaste.com (94.23.221.113): 56 data bytes
64 bytes from 94.23.221.113: icmp_seq=0 ttl=54 time=36.183 ms
64 bytes from 94.23.221.113: icmp_seq=1 ttl=54 time=321.526 ms
ie, how can I get the ttl ? and packet size (for the last one I guess the payload lenght is OK) .
Hi,
This is not an issue but a feature inquiry (unless it already exists and I've missed it).
I need to send packets (mainly for ping and traceroute) through different interfaces and I couldn't find the way do do it. On the command line with the linux ping
, you can set the option -I <interface>
or -I <address>
and the packets are sent through the interface with the proper source address regardless of the routing table.
Thanks for the great work anyway : this lib is very useful.
Cheers
Maurycy
Hello,
I'm using gen_icmp
in an Elixir project. The compilation fails on macOS.
I've cloned to test it, and sure enough when I run rebar3 compile
it fails with the following error:
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f /Users/tester/clones/gen_icmp/_build/default/lib/procket/c_src/Makefile.ancillary
cc -c -Wall -fPIC -g -O2 -DNDEBUG -DSPARE_SEND_FDS -DSPARE_RECV_FDS fd_send.c
cc -c -Wall -fPIC -g -O2 -DNDEBUG -DSPARE_SEND_FDS -DSPARE_RECV_FDS fd_recv.c
cc -m64 -g -Wall -o /Users/tester/clones/gen_icmp/_build/default/lib/procket/priv/procket -L/Users/tester/clones/gen_icmp/_build/default/lib/procket/c_src procket_cmd.c -lancillary
ld: warning: ignoring file /Users/tester/clones/gen_icmp/_build/default/lib/procket/c_src/libancillary.a, building for macOS-arm64 but attempting to link with file built for unknown-unsupported file format ( 0x21 0x3C 0x61 0x72 0x63 0x68 0x3E 0x0A 0x2F 0x20 0x20 0x20 0x20 0x20 0x20 0x20 )
Undefined symbols for architecture arm64:
"_ancil_send_fd", referenced from:
_procket_pipe in procket_cmd-930b73.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [cmd] Error 1
===> Hook for compile failed!
Since in Elixir land one can override dependencies, I've managed to get it to compile inside my project by using the latest version of procket
with {:procket, git: "https://github.com/msantos/procket", override: true}
, but it would be nice if gen_icmp
could compile without additional workarounds.
Cheers!
Maybe should you replace it with os:timestamp
?
I always get big negative values for Elapsed. Is this fine? How can I make use of it? (like converting it to ms as in ping):
49> gen_icmp:ping(["google.com"]).
[{ok,"google.com",
{216,58,220,14},
{216,58,220,14},
{29619,0,55,-4294971590971590814},
<<" !"#$%&'()+,-./0123456789:;<=>?@abcdefghijk">>}]
50> gen_icmp:ping(["google.com", "google.com", "google.com"]).
[{ok,"google.com",
{216,58,220,14},
{216,58,220,14},
{29619,0,55,-4294971590971590871},
<<" !"#$%&'()+,-./0123456789:;<=>?@abcdefghijk">>},
{ok,"google.com",
{216,58,220,14},
{216,58,220,14},
{29619,1,55,-4294971590971590871},
<<" !"#$%&'()+,-./0123456789:;<=>?@abcdefghijk">>},
{ok,"google.com",
{216,58,220,14},
{216,58,220,14},
{29619,2,55,-4294971590971590872},
<<" !"#$%&'()+,-./0123456789:;<=>?@abcdefghijk">>}]
$ ping google.com
PING google.com (216.58.220.14): 56 data bytes
64 bytes from 216.58.220.14: icmp_seq=0 ttl=56 time=87.072 ms
64 bytes from 216.58.220.14: icmp_seq=1 ttl=56 time=89.757 ms
64 bytes from 216.58.220.14: icmp_seq=2 ttl=56 time=90.696 ms
64 bytes from 216.58.220.14: icmp_seq=3 ttl=56 time=89.885 ms
64 bytes from 216.58.220.14: icmp_seq=4 ttl=56 time=89.419 ms
^C
--- google.com ping statistics ---
5 packets transmitted, 5 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 87.072/89.366/90.696/1.221 ms
Hello!
I have no idea if this problem is related to this project at all but the error mentions it so I figured I'd start here. I'm running an elixir app via releases and I'm seeing some issues with another library I wrote that uses gen_icmp
- error I'm seeing is:
{:error, {:undef, [{:procket, :socket, [:inet, :raw, :icmp], []}, {:gen_icmp, :init, 1, [file: '/app/deps/gen_icmp/src/gen_icmp.erl', line: 233]}, {:gen_server, :init_it, 2, [file: 'gen_server.erl', line: 374]}, {:gen_server, :init_it, 6, [file: 'gen_server.erl', line: 342]}, {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 249]}]}}
I wrote a very thin wrapper around this that I'm currently using: https://github.com/silverp1/elixir-ping
Just wondering if anything in the error happens to jump out at you, I'm a bit stumped. Thank you!
Hi, when I track an IP address, I get the below answer : [timeout,timeout,timeout,timeout,timeout,timeout,timeout,
timeout,timeout,timeout,timeout,timeout,timeout,timeout,
timeout,timeout,timeout,timeout,timeout,timeout,timeout,
timeout,timeout,timeout,timeout,timeout,timeout,timeout,
timeout|...]
how i'can fix it ?
thank.
Do you still plan to add ipv6 support ?
Hi
Currently building procket is broken on at least OS X, this is resolved in the procket master branch.
Procket has not been released with the new rebar3 commit which solves the OS X building.
Would it be possible to either push a new version of procket or to switch to procket master?
Also, to send ICMP on OS X, i need to start the Erlang VM with root privileges, is there a workaround for this?
heya,
i'm trying to use this to send ipv6 icmp ping requests using
gen_icmp:ping("dns.google", [inet6])
this works perfectly fine on linux, but errors with enoprotoopt
on mac -- both machines are in the same network and have a valid IPv6 address assigned to them
what would be the steps to get this working on macos, or what information would you need to figure out why it's not working?
I'm having this error when my laptop doesn't resolve a domain name.
11:24:32.031 [error] GenServer #PID<0.304.0> terminating
** (MatchError) no match of right hand side value: [{:error, 'google.com', :nxdomain}]
src/gen_icmp.erl:532: :gen_icmp."-addr_list0/3-lc$^2/1-0-"/2
src/gen_icmp.erl:514: :gen_icmp.addr_list/4
src/gen_icmp.erl:176: :gen_icmp.ping/3
src/gen_icmp.erl:143: :gen_icmp.ping/2
(nvjorn) lib/nvjorn/workers/icmp.ex:73: Nvjorn.Workers.ICMP.connect/1
(nvjorn) lib/nvjorn/workers/icmp.ex:58: Nvjorn.Workers.ICMP.handle_call/3
(stdlib) gen_server.erl:629: :gen_server.try_handle_call/4
(stdlib) gen_server.erl:661: :gen_server.handle_msg/5
Last message: {:check, %Nvjorn.Services.ICMP{failure_count: 0, host: 'google.com', inet: 'inet', name: 'Google'}}
State: :ok
My own code looks like
result = :gen_icmp.ping(item.host, [List.to_atom(item.inet)])
So I don't think it could be an error from my side (although I may be wrong).
Broken by msantos/pkt@41a9907
==> gen_icmp (compile)
Compiled src/icmp_message.erl
Compiled src/icmp6_message.erl
Compiling src/tracert.erl failed:
src/tracert.erl:268: undefined macro 'PF_INET6'
src/tracert.erl:347: undefined macro 'PF_INET6'
src/tracert.erl:58: function handle_call/3 undefined
Hello,
Linux ubuntu 5.4.0-70-generic #78-Ubuntu SMP Fri Mar 19 13:29:52 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux:
iex(2)> :gen_icmp.ping('192.168.1.1', [ttl: 1])
[
{:ok, '192.168.1.1', {192, 168, 1, 1}, {192, 168, 1, 1}, {15829, 0, 255, 7},
" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNO"}
]
On: Linux smartslot 5.4.66nmc4-dirty #10 SMP PREEMPT Tue Mar 23 05:06:09 PDT 2021 armv7l GNU/Linux:
iex(1)> :gen_icmp.ping('127.0.0.1', [])
[{:error, :timeout, '127.0.0.1', {127, 0, 0, 1}}]
Needless to mention that a standard command line ping works perfectly fine. I am getting timeout in 100% calls. I am not an Erlang expert but wrote few things. I would appreciate any help with debugging this as I do not even know at this stage what might have gone wrong. This is not the only module that involves cross-compilation but this is the only one that works-otherwise. First of all I checked the procket's cross-compile's CFLAGS and LDFLAGS and I haven't noticed anything apparent. Please see below excerpt.
613 ===> Compiling procket
614 make: Entering directory '/mnt/src/agilis_fw/firmware.gvs/deps/lces2/procket/c_src'
615 make -f /mnt/src/agilis_fw/firmware.gvs/deps/lces2/procket/c_src/Makefile.ancillary
616 make[1]: Entering directory '/mnt/src/agilis_fw/firmware.gvs/deps/lces2/procket/c_src'
617 arm-poky-linux-gnueabi-gcc -march=armv7ve -mthumb -mfpu=vfpv4-d16 -mfloat-abi=hard -fstack-protector-strong -D_FORTIFY_SOURCE=2 -Wformat -Wformat-sec>
618 arm-poky-linux-gnueabi-gcc -march=armv7ve -mthumb -mfpu=vfpv4-d16 -mfloat-abi=hard -fstack-protector-strong -D_FORTIFY_SOURCE=2 -Wformat -Wformat-sec>
619 ar cr libancillary.a fd_send.o fd_recv.o
620 ranlib libancillary.a
621 make[1]: Leaving directory '/mnt/src/agilis_fw/firmware.gvs/deps/lces2/procket/c_src'
622 echo "CFLAGS = -O2 -pipe -g -feliminate-unused-debug-types -fPIC -O2 -I -I -I/home/motyl/.local/share/nerves/artifacts/nerves_system_poky-portable->
623 CFLAGS = -O2 -pipe -g -feliminate-unused-debug-types -fPIC -O2 -I -I -I/home/motyl/.local/share/nerves/artifacts/nerves_system_poky-portable-3.1.3->
624 echo "LDFLAGS = -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -fstack-protector-strong -Wl,-z,relro,-z,now -shared -L/home/motyl/.local/share/nerves/art>
625 LDFLAGS = -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -fstack-protector-strong -Wl,-z,relro,-z,now -shared -L/home/motyl/.local/share/nerves/artifacts>
626 arm-poky-linux-gnueabi-gcc -march=armv7ve -mthumb -mfpu=vfpv4-d16 -mfloat-abi=hard -fstack-protector-strong -D_FORTIFY_SOURCE=2 -Wformat -Wformat-sec>
627 arm-poky-linux-gnueabi-gcc -march=armv7ve -mthumb -mfpu=vfpv4-d16 -mfloat-abi=hard -fstack-protector-strong -D_FORTIFY_SOURCE=2 -Wformat -Wformat-sec>
628 arm-poky-linux-gnueabi-gcc -march=armv7ve -mthumb -mfpu=vfpv4-d16 -mfloat-abi=hard -fstack-protector-strong -D_FORTIFY_SOURCE=2 -Wformat -Wformat-sec>
629 make: Leaving directory '/mnt/src/agilis_fw/firmware.gvs/deps/lces2/procket/c_src'
This is probably something silly on my side and I hope to help improving the module's cross-compile build if this would appear to be the case.
Checked with the wireshark and no single ICMP packet is being spit out onto the wire.
With my best wishes
Tomasz Motyl
Hello!
I'am newbie in erlang and elixir. i'am totally misunderstand why :gen_icmp.ping doesnt works in elixir.
elixir@elixir-VirtualBox:~$ uname -a
Linux elixir-VirtualBox 3.19.0-25-generic #26~14.04.1-Ubuntu SMP Fri Jul 24 21:16:20 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
I created test mix project, where i include gen_icmp as dependency
defmodule KV.Mixfile do
use Mix.Project
def project do
[app: :kv,
version: "0.0.1",
elixir: "~> 1.0",
build_embedded: Mix.env == :prod,
start_permanent: Mix.env == :prod,
deps: deps]
end
# Configuration for the OTP application
#
# Type `mix help compile.app` for more information
def application do
[applications: [:logger, :gen_icmp]]
end
defp deps do
[{:gen_icmp, git: "https://github.com/msantos/gen_icmp.git"}]
end
end
then i ran (i'am trying with sudo and without)
sudo mix deps.get
sudo mix deps.compile
sudo mix compile
As i realize, all compiled successfully, because on erlang (but in another folder and with rebar), on same machine all works well.
After that i ran:
elixir@elixir-VirtualBox:~/elixir_test/kv$ iex -S mix
Erlang/OTP 18 [erts-7.0] [source-4d83b58] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]
Interactive Elixir (1.0.5) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> :gen_icmp.ping
ping/1 ping/2 ping/3
iex(1)> :gen_icmp.ping "google.ru"
** (EXIT from #PID<0.95.0>) {:error, :eperm}
Interactive Elixir (1.0.5) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> :gen_icmp.ping("google.com")
** (EXIT from #PID<0.100.0>) {:error, :eperm}
Interactive Elixir (1.0.5) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> :gen_icmp.ping.("google.com")
** (UndefinedFunctionError) undefined function: :gen_icmp.ping/0
(gen_icmp) :gen_icmp.ping()
When i'am run this from sudo - it's behave slighty different
elixir@elixir-VirtualBox:~/elixir_test/kv$ sudo iex -S mix
Erlang/OTP 18 [erts-7.0] [source-4d83b58] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]
Interactive Elixir (1.0.5) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> :gen_icmp.ping
ping/1 ping/2 ping/3
iex(1)> :gen_icmp.ping("ya.ru")
** (FunctionClauseError) no function clause matching in :gen_icmp.ping/3
(gen_icmp) src/gen_icmp.erl:147: :gen_icmp.ping(#PID<0.97.0>, "ya.ru", [])
(gen_icmp) src/gen_icmp.erl:143: :gen_icmp.ping/2
iex(1)> :gen_icmp.ping "ya.com"
** (FunctionClauseError) no function clause matching in :gen_icmp.ping/3
(gen_icmp) src/gen_icmp.erl:147: :gen_icmp.ping(#PID<0.100.0>, "ya.com", [])
(gen_icmp) src/gen_icmp.erl:143: :gen_icmp.ping/2
iex(1)>
Please, tell me what's wrong? Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.