Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Commits on Aug 3, 2015
  1. Return number of bytes for partial writes

    authored
    The write functions (sendto/4, sendmsg/5, write/2, writev/2) have had a
    long standing bug where failure to write the complete buffer was
    silently ignored.
    
    Return a tuple containing the number of bytes written if the complete
    buffer could not be sent. Writes can be continued using something like:
    
        write_exact(FD, Buf) ->
            case procket:write(FD, Buf) of
                ok ->
                    ok;
                {ok, N} - >
                    {_:N/bytes, Rest/binary} = Buf,
                    write_exact(FD, Rest);
                Error ->
                    Error
            end.
    
    Successful writes of the entire buffer still return 'ok'.
Commits on Jun 8, 2015
  1. Split protocols from socket levels

    authored
    Add a new NIF for retrieving the integer protocol values using atoms.
    For socket levels in getsockopt/4 and setsockopt/4, first search
    socket_level/1 before checking socket_protocol/1.
    
    socket_protocol/1 duplicates the hard coded values provided by
    protocol/1. Since protocol/1 is not exported and is used only with
    open/1, it can be replaced with:
    
        protocol(ip) -> socket_protocol('IPPROTO_IP');
        protocol(icmp) -> socket_protocol('IPPROTO_ICMP');
        protocol(tcp) -> socket_protocol('IPPROTO_TCP');
        ...
    
    Or even:
    
        protocol(Constant) ->
            socket_protocol(list_to_atom("IPPROTO_" ++
                        string:to_upper(atom_to_list(Constant)))).
Commits on Jun 5, 2015
  1. socket_level/0, socket_optname/0: all constants

    authored
    Return the list of constants supported on this platform. Code tetris for
    common functions reserved for a future patch.
Commits on Jun 4, 2015
  1. Add NIFs for system constant lookup

    authored
    Add 2 new NIFs to return the socket level (socket_level/1) and the socket
    option name (socket_optname/1) used by getsockopt/4 and setsockopt/4.
    
    Non-portable socket arguments will return {error,unsupported}.
    
    #20
    
    Thanks to @kellymclaughlin and @jaredmorrow!
Commits on Jun 3, 2015
  1. @Vagabond

    Add {registered, []} to app.src file

    Vagabond authored
    Helps avoid problems when generating releases with relx.
Commits on Mar 20, 2015
  1. fdopen: only one connection to fd passing socket

    authored
    Set the backlog of the socket used for passing the fd from the
    privileged process to 0.
Commits on Mar 16, 2015
  1. solaris: fix opening of local socket

    authored
    Opening a socket using the open/2 interface would fail on Solaris because
    the socket type value for the socket used for fd passing was hardcoded.
Commits on Feb 19, 2015
  1. Remove integer lookups for family/type/proto

    authored
    Integer to atom conversion for socket(2) arguments are not used (and are
    not exported, except for family which was exported recently in commit
    91c5e).
    
    A more reliable way of looking up system dependent constants is planned.
Commits on Feb 18, 2015
  1. Fix compilation on Solaris

    authored
    So errno is not thread local on Solaris and is set to 0 by default on
    error. Really Solaris?
    
    On Solaris, compile using POSIX mode which requires c99 mode which fixes
    errno, uses void* instead of c_addr_t* for iovec and various other errors.
    
    Add solaris constants for dgram, stream and raw which differ from other
    unix platforms. Make the send/recvmsg example work on Solaris.
    
    Platform dependent constants need to be fixed in the future. This could
    be done either by adding a lookup table to the NIF or writing a small
    program in C to generate an erlang module at compile time.
    
    Bump version to 0.6.1.
Commits on Feb 14, 2015
  1. Remove procket_msg module

    authored
  2. Add sendmsg/4,5 and recvmsg/4,5

    authored
    Some small fixes and interface changes to sendmsg/5 and recvmsg/4 based
    on the pull request by Andrew Thompson:
    
    #18
    
    * recvmsg: the msg_namelen field is value-result. Resize the source
      address binary to this length. Fixes einval on FreeBSD when passing
      in an overlong socket address as noted in the sendmsg/recvmsg echo
      example
    
    * recvmsg: account for padding in cmsghdr structure when calculating the
      cmsg data length.
    
    * recvmsg: reverse the list of cmsg tuples so the order is the same as
      returned using the CMSG_NXTHDR() macro
    
    * recvmsg: if bufsize or ctrlsize are 0, set the iov_base or msg_name
      to NULL instead of a 0 byte binary
    
    * sendmsg: if buf or sa are empty binaries, set iov_base or msg_name to
      NULL
    
    * cleanup: fix pasto in arg order, memory leaks, change recvmsg to return
      msg_flags as a signed int
    
    The following alterations were made to the interface:
    
    * recvmsg/5: add an extra argument to recvmsg to specify the size
      of sockaddr
    
      recvmsg() with a connected socket and a non-NULL msg_name field
      in the msghdr structure will return EISCONN.
    
      Allow the caller to specify the length of the sockaddr structure (for
      example, 128 bytes is the size of sockaddr_storage which is large enough
      to hold any socket address).
    
      Add recvmsg/4, a version of recvmsg for connected sockets that defaults
      to setting msg_name to NULL.
    
    * recvmsg/sendmsg: make the arg order consistent
    
      Change the order of arguments so the input and output values are in the
      same order and position, recvmsg and sendmsg provide the same order and
      the order reflects sendto()/recvfrom().
    
      The order for arguments and return values is:
    
      * buffer
      * flags
      * control data
      * socket address
    
    TODO: Solaris support
    
    Thanks @Vagabond!
Commits on Feb 5, 2015
  1. @Vagabond

    Fix sendmsg/recvmsg on FreeBSD/NetBSD/OpenBSD

    Vagabond authored
    Some padding/length issues needed to be fixed, but now the
    sendmsg/recvmsg echo test works on all 3 BSDs and on Linux.
  2. @Vagabond

    Make sendmsg and recvmsg actually usable

    Vagabond authored
    Instead of passing in a binary that is treated as the 'msghdr' struct,
    pass in data needed to construct an appropriate msghdr struct and also
    return useful result data, including the control data.
    
    Documentation and an example are also included.
Commits on Nov 17, 2014
  1. Use local file operations for slave nodes

    authored
    Opening a socket on a slave node using the procket setuid helper would
    fail, due to file operations being performed on the master:
    
        1> slave:start('bar', 'n', "-env ERL_LIBS /path/to/erlang").
    
        (n@foo)3> rpc:call('n@bar', procket, open, [58, [{protocol,tcp},{family,inet},{type,stream}]]).
        {badrpc,{'EXIT',{{badmatch,{error,enoent}},
                [{procket,fdopen,1,[{file,"src/procket.erl"},{line,258}]},
                 {procket,open,2,[{file,"src/procket.erl"},{line,191}]},
                 {rpc,'-handle_call_call/6-fun-0-',5,
                 [{file,"rpc.erl"},{line,205}]}]}}}
    
    The failure happens because procket creates a temporary directory to
    store the unix socket used to pass the fd from the helper into the NIF.
    Because slave nodes defer file operations to the master, the temp
    directory would be created on the master but would be attempted to be
    used on the slave.
    
    The work around was to manually specify the location of the unix socket
    using the 'pipe' option:
    
        rpc:call('n@bar', procket, open, [58, [{pipe, "/tmp/procket.s"}, {protocol,tcp},{family,inet},{type,stream}]]).
    
    Fix by bypassing the file server using the prim_file module directly.
    Slave nodes now should work without any other setup:
    
        (n@foo)3> rpc:call('n@bar', procket, open, [58,
                [{protocol,tcp},{family,inet},{type,stream}]]).
        {ok,14}
        (n@foo)4> rpc:call('n@bar', gen_tcp, listen, [0,
                [{fd,14}]]).
        {ok,#Port<7189.783>}
    
    Checking the remote mode, the socket is listening:
    
        bar$ sudo netstat -ptnl | grep 58
        tcp        0      0 0.0.0.0:58              0.0.0.0:* LISTEN      23902/beam.smp
    
    Thanks to xingang shi for reporting and debugging this problem!
Commits on Nov 16, 2014
  1. Attempt to run the setuid helper twice

    authored
    In many situations, the procket setuid helper may be permitted to bind
    the socket without any extra work:
    
        * beam could be running as root
        * the helper could be setuid or setgid
        * the process may have a capability set
        * the process may be permitted to access a device file or port
    
    Simplify the convoluted logic for launching the procket setuid helper
    by running the helper twice: without sudo and with sudo. If the caller
    wants to suppress this behaviour, the 'exec' option can be passed in to
    open/2:
    
        procket:open(23, [{exec, ""}]).
Commits on Nov 14, 2014
  1. @arashbm
  2. @arashbm

    Update procket.app.src

    arashbm authored
Commits on Nov 12, 2014
  1. Support compilation on Solaris

    authored
Commits on Jan 27, 2014
  1. Display bad arguments in error

    authored
Commits on Jan 22, 2014
  1. procket: return badarg

    authored
Commits on Jan 21, 2014
  1. procket: throw -> error

    authored
Commits on Jan 17, 2014
Commits on Dec 19, 2013
  1. Allow atoms in io* funs

    authored
    Take integers or atoms in ioc, iow, iorw, to allow lookup of values
    based on platform.
    
    From dialyzer:
    
    bpf.erl:120: The call bpf:ior(66,'gseesent',4) will never return since it differs in the 2nd argument from the success typing arguments: (integer(),integer(),integer())
    bpf.erl:181: The call bpf:iow(66,'sseesent',4) will never return since it differs in the 2nd argument from the success typing arguments: (integer(),integer(),integer())
Commits on Dec 18, 2013
  1. Remove unnecessary case clause

    authored
    From dialyzer:
    
    procket.erl:204: The variable Error can never match since previous
    clauses completely covered the type {'ok',_}
    
    The code should be changed to return an error, rather than crashing but
    the code will currently crash in fdopen.
Commits on Dec 11, 2013
Commits on Dec 1, 2013
Commits on Nov 28, 2013
Commits on Nov 26, 2013
Commits on Nov 3, 2013
  1. bpf: use the ioctl functions from procket_ioctl

    authored
    Fix an unresolved function call to the obsolete inout/1.
Commits on Aug 17, 2013
  1. Add an example of setting the IPv6 hop limit

    authored
    Set the default hop limit for this socket.
Commits on Jul 2, 2013
  1. Merge branch 'send-recv-msg'

    authored
Commits on Jun 7, 2013
  1. Correct check for character device

    authored
    The procket helper will only open devices under the /dev directory.
    Append "/dev/" to the device name for the permissions check.
Something went wrong with that request. Please try again.