Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Commits on May 15, 2011
  1. sh printf is portable

Commits on May 14, 2011
  1. Return POSIX atom on error from forked setuid bin

    Add a function to the NIF returning an atom from erl_errno_id().
    Do not distinguish between procket_cmd and procket errors. Return the
    same tuple {error, posix()} on errors.
    Return the POSIX value in hackish way: by echo'ing the return code
    in os:cmd/1. Otherwise, sudo may return failure (for example, if the
    user has not placed the procket command in sudoers.conf. sudo exits
    with a return value of EPERM in this case).
Commits on May 3, 2011
  1. Allow '/' in character device name

    Accomodate character devices kept in a directory under /dev, e.g.,
    the tun device in /dev/net/tun.
Commits on Apr 18, 2011
  1. Compile errors

  2. Allow setuid open of any character device

    Make the bpf device code generic so that the spawned setuid procket
    executable is able to open any character device.
    The code first checks the multiplex device (e.g., /dev/bpf). If it exists
    and no error occurs, the fd is returned to the Erlang side.
    If the muliplexing device does not exist or is not a character device,
    the code will fall back to trying numbered devices.
Commits on Apr 17, 2011
  1. Initial support for BPF on BSDs

    Add support for sending and receiving raw frames on BSD systems.
    Only tested on Mac OS X. The bpf module calls the C interface with
    the appropriate parameters.
Commits on Apr 1, 2011
Commits on Feb 20, 2011
  1. Simplify option handling

Commits on Jan 16, 2011
  1. Allocate pointers to buffers for ioctl requests

    Some ioctl requests require a pointer to a user allocated buffer. For
    struct  iw_point
        void *pointer;
        u_int16_t length;
        u_int16_t flags;
    Would be constructed using:
    {ok, Structure, [Resource]} = procket:alloc([
        {ptr, 4096},                                % buffer
        <<4096:2/unsigned-native-integer-unit:8,    % length
        0:2/native-unsigned-integer-unit:8>>        % flags
    A tuple containing the structure and a list of resources (one for
    each allocated buffer) is returned.
    After calling the ioctl, the contents of the buffer is retrieved by
    using the buf/1 function on the resource.
    NOTE: If the pointer points to somewhere invalid, ioctl will return
    {error, efault}, but if the pointer points somewhere within beam's memory
    space, the VM may crash.
Commits on Dec 25, 2010
  1. Fix sockaddr on BSD

    On SysV type systems, the first field of the struct sockaddr is 2 bytes
    and is set to the protocol family. On BSDs, the first byte is the socket
    address length and the second byte is the protocol family. Add some
    portability goo to deal with it.
  2. Fix for atom socket arguments

  3. Add sendto/2,3

    Add versions of sendto with defaults. sendto/2 corresponds to write and
    sendto/3 corresponds to send.
Commits on Dec 21, 2010
  1. Socket args can be either atoms or integers

    Personally, I prefer the integer macros. Todo: use integer macros when
    mapping atom name -> integer.
  2. Remove fd transfer functions from export

    Remove the functions used for transferring the socket fd between process
    from the export list. TODO: create wrappers for libancillary
Commits on Dec 17, 2010
  1. Remove close/2; add listen/1

    Remove close/2 which removed the Unix socket. Handle the socket deletion
    in Erlang. Add listen/1 which uses a default backlog.
  2. recvfrom/4: return socket address

    Add recvfrom/4 to return the socket address of the packet. recvfrom/4
    takes 2 new args: flags and the size of the socket structure which is
    allocated by the NIF. If the size is not large enough, the socket address
    will be silently truncated.
Commits on Dec 15, 2010
  1. Communicate with Unix sockets

    Break out socket primitives (socket, listen, accept, ...) to allow Erlang
    to create and access Unix sockets. Any type of unprivileged socket can
    be created without spawning the setuid helper.
    Warning: because listen/2 is now a wrapper around the listen(2), the
    procket:listen/1,2 has been renamed to procket:open/1,2.
Commits on Dec 10, 2010
  1. Clean up local socket temp directory

    If a temporary directory was created to hold the Unix socket, delete it
    after the privileged socket has been sent to Erlang.
Commits on Oct 30, 2010
  1. Fix fd leak

    The Unix socket file descriptor was leaked whenever there was an error.
Commits on Oct 6, 2010
  1. Add interface name sanitation

    klaar authored
Commits on Jun 26, 2010
  1. Close any file descriptor

    Re-use procket:close/2 to close any file descriptor. Consequently,
    reverse the arguments to close/2, to take the fd first.
Commits on Jun 24, 2010
  1. Add an NIF setsockopt for promiscous mode

    Add an interface to setsockopt(). procket:setsockopt/4 can be used for
    putting the interface into promiscous mode.  Add packet:promiscuous/2
    convenience function to do that:
    packet:promiscuous(Socket, Ifindex)
Commits on Jun 13, 2010
  1. Add an NIF interface to ioctl()

    Add an Erlang interface to ioctl() using an NIF. For example, to retrieve
    the interface index for the "eth0" interface to use for sending out
    raw packets:
    -define(SIOCGIFINDEX, 16#8933).
    {ok, <<_Ifname:16/bytes, Ifr:8, _/binary>>} = procket:ioctl(S,
            <<"eth0", 0:224>>).
    The value "Ifr" will contain the index that can be used to set the
    sll_ifindex member of struct sockaddr_ll.
  2. Add sendto/4 and bind/2

    sendto/4 takes as arguments:
    * the socket descriptor
    * the buffer to be sent
    * flags
    * a binary representing a struct sockaddr_*
    For example, to send an ICMP echo to, assuming the variable
    "Packet" holds a valid ICMP packet:
    ok = procket:sendto(S, Packet, 0,
            2:16/native,                    % sin_family: PF_INET
            0:16,                           % sin_port
            192:8, 168:8, 100:8, 1:8,       % sin_addr
            0:64                            % sin_zero
    Similarly, bind/2 takes:
    * the socket descriptor
    * a binary representing a struct sockaddr_*
Commits on May 29, 2010
  1. Add NIF versions of recvfrom/sendto

    sendto is untested and disabled. Make sockets non-blocking for NIF
    sendto/recvfrom. Cache atoms and clean up corresponding error functions.
Commits on May 26, 2010
  1. Type conversion is wardsback

  2. Allow arbitrary socket family, type and protocol

    Simplify the procket external command by allowing the user to set
    any protocol, type and family for the socket.
Commits on Mar 9, 2010
  1. Dynamically create path to procket executable too.

    The path to the procket executable can still be set using {progname, ...}.
    By default, figure out the path relative to the module in ebin and run
    it using sudo.
  2. Dynamically create path to NIF relative to module.

    Assumes the lib is in the priv directory.
Commits on Mar 8, 2010
  1. Changes for the R13B04 nif interface.

    Also an excuse to do some clean up.
Commits on Jan 11, 2010
  1. Make the NIF stateless!

    Need to explicitly pass in socket info to the procket NIF, rather than it
    tracking the data internally. This should make it much safer and reliable.
    Changes to the interface:
    open/2 -> open/1 : vestigal protocol arg removed, stick to streams. Erlang module changed to match (along with the bizarre passing in of the port as a protocol, who did that? o_O)
    Returns the socket descriptor listening on the Unix socket: {ok, FD}
    poll/0 -> poll/1 : takes the socket descriptor
    close/0 -> close/2 : close(SocketPath, SocketDescriptor), closes the socket descriptor and deletes the socket path.
Commits on Jan 9, 2010
Something went wrong with that request. Please try again.