Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
branch: master
Commits on Jun 14, 2015
  1. Suppress scan-build warning

    authored
    c_src/procket.c:837:23: warning: Access to field 'cmsg_len' results in a dereference of a null pointer (loaded from variable 'cmsg')
            cmsg->cmsg_len=CMSG_LEN(cdata_field.size);
            ~~~~          ^
    1 warning generated.
    scan-build: 1 bug found.
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 7, 2015
  1. Add socket level and optname constants

    authored
    Gather a list of constants from the system headers on Linux, OpenBSD,
    FreeBSD and SmartOS.
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. Merge pull request #21 from Vagabond/patch-1

    authored
    Add {registered, []} to app.src file
  2. @Vagabond

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

    Vagabond authored
    Helps avoid problems when generating releases with relx.
Commits on Jun 2, 2015
  1. @kellymclaughlin
  2. @jaredmorrow
  3. @jaredmorrow
  4. @jaredmorrow

    Ignore rebar files

    jaredmorrow authored
Commits on Jun 1, 2015
  1. @jaredmorrow
  2. @kellymclaughlin

    Fix ifdefs

    kellymclaughlin authored
  3. @kellymclaughlin
  4. @kellymclaughlin

    Allow atoms for socket option parameters

    kellymclaughlin authored
    Allow the use of atoms representing the names for socket option level
    and option_name parameters. This provides a way for applications using
    the procket libary that need to manipulate or inspect socket options to
    work across different operating systems without a lot of brittle
    application-level checking. These changes affect the setsocketopt and
    getsockopt functions and the previous behavior of accepting integers for
    the level and option_name parameters is still intact.
Commits on May 15, 2015
  1. Merge pull request #19 from jaredmorrow/jem-illumos-build

    authored
    Fix Makefile $(REBAR) variable handling on Illumos
Commits on May 13, 2015
  1. @jaredmorrow

    Fix Makefile $(REBAR) variable handling on Illumos

    jaredmorrow authored
    On solaris flavors, `which` has: sometimes poor behavior of
    not returning proper exit codes or printing errors to STDOUT
    rather than STDERR.  All of this is to say, the makefile didn't
    behave correctly on Solaris. $(REBAR) ended up being set to
    "rebar not found" which made the compile target less than happy.
    
    I added a print-* target to test this easier.  Simply
    `make print-VAR` to see the value.  So `make print-REBAR`
    will show you the value of $REBAR.
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, ""}]).
  2. Fix the echo example

    authored
    The behaviour of gen_tcp:listen/2 seems to have changed at some point:
    if a non-zero port is passed in, the inet driver attempts to bind this
    port, even if an 'fd' parameter exists in the options.
    
    Setting the port to 0 seems to force inet to use the fd option.
Commits on Nov 14, 2014
  1. Merge pull request #16 from arashbm/master

    authored
    adding empty applications parameter
  2. @arashbm
  3. @arashbm

    Update procket.app.src

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

    authored
Something went wrong with that request. Please try again.