Skip to content
Commits on Apr 20, 2016
  1. README: fix example

    When passing in an fd to gen_udp:open/2, the port must be set to 0. The
    examples were fixed way back in b5c16f.
    Thanks @philipcristiano!
    committed Apr 20, 2016
Commits on Apr 3, 2016
  1. Remove unused stub function

    Suppress compiler warning about the unused unload().
    committed Apr 3, 2016
Commits on Mar 23, 2016
  1. Use rebar3

    committed Mar 23, 2016
Commits on Aug 3, 2015
  1. Return number of bytes for partial writes

    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, N} - >
                    {_:N/bytes, Rest/binary} = Buf,
                    write_exact(FD, Rest);
                Error ->
    Successful writes of the entire buffer still return 'ok'.
    committed Aug 2, 2015
Commits on Jun 14, 2015
  1. Suppress scan-build warning

    c_src/procket.c:837:23: warning: Access to field 'cmsg_len' results in a dereference of a null pointer (loaded from variable 'cmsg')
            ~~~~          ^
    1 warning generated.
    scan-build: 1 bug found.
    committed Jun 14, 2015
Commits on Jun 8, 2015
  1. Split protocols from socket levels

    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_" ++
    committed Jun 8, 2015
Commits on Jun 7, 2015
  1. Add socket level and optname constants

    Gather a list of constants from the system headers on Linux, OpenBSD,
    FreeBSD and SmartOS.
    committed Jun 7, 2015
Commits on Jun 5, 2015
  1. socket_level/0, socket_optname/0: all constants

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

    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}.
    Thanks to @kellymclaughlin and @jaredmorrow!
    committed Jun 4, 2015
Commits on Jun 3, 2015
  1. Merge pull request #21 from Vagabond/patch-1

    Add {registered, []} to app.src file
    committed Jun 3, 2015
  2. @Vagabond

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

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

    Ignore rebar files

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

    Fix ifdefs

    kellymclaughlin committed Jun 1, 2015
  3. @kellymclaughlin
  4. @kellymclaughlin

    Allow atoms for socket option parameters

    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.
    kellymclaughlin committed Jun 1, 2015
Commits on May 15, 2015
  1. Merge pull request #19 from jaredmorrow/jem-illumos-build

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

    Fix Makefile $(REBAR) variable handling on Illumos

    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.
    jaredmorrow committed May 13, 2015
Commits on Mar 20, 2015
  1. fdopen: only one connection to fd passing socket

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

    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.
    committed Mar 16, 2015
Commits on Feb 19, 2015
  1. Remove integer lookups for family/type/proto

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

    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.
    committed Feb 18, 2015
Commits on Feb 14, 2015
  1. Remove procket_msg module

    committed Feb 14, 2015
  2. Add sendmsg/4,5 and recvmsg/4,5

    Some small fixes and interface changes to sendmsg/5 and recvmsg/4 based
    on the pull request by Andrew Thompson:
    * 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
    * 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
    * 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!
    committed Feb 8, 2015
Commits on Feb 5, 2015
  1. @Vagabond

    Fix sendmsg/recvmsg on FreeBSD/NetBSD/OpenBSD

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

    Make sendmsg and recvmsg actually usable

    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.
    Vagabond committed Feb 4, 2015
Commits on Nov 17, 2014
  1. Use local file operations for slave nodes

    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}]]).
    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,
        (n@foo)4> rpc:call('n@bar', gen_tcp, listen, [0,
    Checking the remote mode, the socket is listening:
        bar$ sudo netstat -ptnl | grep 58
        tcp        0      0    * LISTEN      23902/beam.smp
    Thanks to xingang shi for reporting and debugging this problem!
    committed Nov 17, 2014
Commits on Nov 16, 2014
  1. Attempt to run the setuid helper twice

    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
        procket:open(23, [{exec, ""}]).
    committed Nov 16, 2014
  2. Fix the echo example

    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.
    committed Nov 16, 2014
Something went wrong with that request. Please try again.