Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

README and whitespace cleanup

  • Loading branch information...
commit 0c32f661dc54aeff9c89a4ced3449eb9856a531f 1 parent f3870b0
@msantos authored
View
33 README.md
@@ -26,9 +26,7 @@ Other features include:
## REQUIREMENTS
-procket should work with any version of Erlang after R14A but using
-the latest Erlang release is advisable.
-
+procket works with any version of Erlang after R14A.
## CHANGES
@@ -36,11 +34,11 @@ the latest Erlang release is advisable.
* IPv6 support
### V0.02:
-* procket:listen/1,2 has been renamed procket:open/1,2. procket:listen/2
- is now a wrapper around listen(2)
+* procket:listen/1,2 was renamed procket:open/1,2. procket:listen/2 is
+ now a wrapper around listen(2)
* procket:recvfrom/2 returns {error,eagain} when data is not available
- (previously return nodata)
+ (previously returned nodata)
## EXPORTS
@@ -86,7 +84,7 @@ the latest Erlang release is advisable.
tun or tap devices.
-### Unix Socket Interface
+### BSD Socket Interface
socket(Family, Type, Protocol) -> {ok, FD} | {error, posix()}
@@ -313,10 +311,21 @@ root and make it setuid.
* to make it setuid
+ # Default location
+ sudo chown root priv/procket
+ sudo chmod 4750 priv/procket
+
+ The procket setuid helper can also be placed in a system directory:
+
+ # System directory
sudo cp priv/procket /usr/local/bin
sudo chown root:yourgroup /usr/local/bin/procket
- sudo chmod 750 /usr/local/bin/procket
- sudo chmod u+s /usr/local/bin/procket
+ sudo chmod 4750 /usr/local/bin/procket
+
+ Then pass the progname argument to open/2:
+
+ {ok, FD} = procket:open(53, [{progname, "/usr/local/bin/procket"},
+ {protocol, udp},{type, dgram},{family, inet}]).
* use Linux capabilities: beam or the user running beam can be
given whatever socket privileges are needed. For example, using file
@@ -374,8 +383,10 @@ To build the examples:
2> procket:recvfrom(S, 2048).
{ok,<<0,21,175,89,8,38,0,3,82,3,39,36,8,0,69,0,0,52,242,
0,0,0,52,6,188,81,209,...>>}
- 3> {ok, S1} = gen_udp:open(0, [binary, {fd, S}, {active, false}]).
- 4> gen_udp:recv(S1, 2048).
+ 3> Port = erlang:open_port({fd, S, S}, [binary, stream]).
+ 4> flush().
+ Shell got {#Port<0.1343>,
+ {data,<<224,105,149,59,163>>}}
### Bind to one or more interfaces
View
16 examples/icmp6.erl
@@ -63,7 +63,7 @@ ping(IP) ->
ping(IP, N) ->
crypto:start(),
Id = crypto:rand_uniform(0, 16#FFFF),
- {Family, Protocol, Addr} =
+ {Family, Protocol, Addr} =
case (catch inet:getaddr(IP, inet6)) of
{ok, V6Addr} ->
{inet6, 'ipv6-icmp', V6Addr};
@@ -83,16 +83,14 @@ ping(IP, N) ->
loop(#state{n = N, seq = Seq}) when Seq >= N ->
ok;
-loop(#state{s = S, id = Id, seq = Seq, ip = IP,
+loop(#state{s = S, id = Id, seq = Seq, ip = IP,
family = Family, protocol = Protocol, n = N} = State) ->
Packet = make_packet(Id, Seq, Family),
% io:format("S = ~p, IP = ~p, Family = ~p, Protocol = ~p~n", [S, IP, Family, Protocol]),
ok = gen_udp:send(S, IP, 0, Packet),
- case Family of
- inet6 ->
- Skip = 0;
- _inet ->
- Skip = 20
+ Skip = case Family of
+ inet6 -> 0;
+ _inet -> 20
end,
receive
{udp, S, _IP, _Port, <<_SD:Skip/bytes, Data/binary>>} ->
@@ -128,7 +126,7 @@ make_packet(Id, Seq, Family) ->
?ICMP_ECHO
end,
- CS = makesum(<<Type:8/integer-unsigned-big, 0:8, 0:16,
+ CS = makesum(<<Type:8/integer-unsigned-big, 0:8, 0:16,
Id:16, Seq:16, Mega:32, Sec:32, USec:32, Payload/binary>>),
<<
Type:8/integer-unsigned-big, % Type
@@ -150,7 +148,7 @@ compl(N) when N =< 16#FFFF -> N;
compl(N) -> (N band 16#FFFF) + (N bsr 16).
compl(N,S) -> compl(N+S).
-%% icmp(<<?ICMPV6_ECHO_REPLY:8/integer-unsigned-big, 0:8, Checksum:16,
+%% icmp(<<?ICMPV6_ECHO_REPLY:8/integer-unsigned-big, 0:8, Checksum:16,
%% Id:16, Sequence:16, Payload/binary>>, 'ipv6-icmp') ->
%% {#icmp{
%% type = ?ICMPV6_ECHO_REPLY, code = 0, checksum = Checksum, id = Id,
View
14 src/procket.erl
@@ -1,21 +1,21 @@
%% Copyright (c) 2010-2012, Michael Santos <michael.santos@gmail.com>
%% All rights reserved.
-%%
+%%
%% Redistribution and use in source and binary forms, with or without
%% modification, are permitted provided that the following conditions
%% are met:
-%%
+%%
%% Redistributions of source code must retain the above copyright
%% notice, this list of conditions and the following disclaimer.
-%%
+%%
%% Redistributions in binary form must reproduce the above copyright
%% notice, this list of conditions and the following disclaimer in the
%% documentation and/or other materials provided with the distribution.
-%%
+%%
%% Neither the name of the author nor the names of its contributors
%% may be used to endorse or promote products derived from this software
%% without specific prior written permission.
-%%
+%%
%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
%% "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
%% LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
@@ -111,7 +111,7 @@ recv(Socket,Size) ->
recvfrom(Socket,Size).
recvfrom(Socket,Size) ->
case recvfrom(Socket, Size, 0, 0) of
- {ok, Buf, <<>>} -> {ok, Buf};
+ {ok, Buf, <<>>} -> {ok, Buf};
Error -> Error
end.
recvfrom(_,_,_,_) ->
@@ -364,7 +364,7 @@ progname_priv() ->
case application:get_env( ?MODULE, port_executable ) of
{ok, Executable} -> Executable;
undefined -> filename:join([
- code:priv_dir( ?MODULE ),
+ code:priv_dir( ?MODULE ),
?MODULE
])
end.
View
2  src/procket_ioctl.erl
@@ -33,7 +33,7 @@
-export([
in/0, out/0, void/0,
in/1, out/1, void/1,
- ioc/4,
+ ioc/4,
io/2, ior/3,
iow/3, iowr/3
]).
Please sign in to comment.
Something went wrong with that request. Please try again.