Skip to content
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'.
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_" ++
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.
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!
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.
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.
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.
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.
Commits on Feb 14, 2015
  1. 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!
Commits on Feb 5, 2015
  1. @Vagabond

    Fix sendmsg/recvmsg on FreeBSD/NetBSD/OpenBSD

    Vagabond committed
    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 committed
    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

    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!
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, ""}]).
Commits on Jan 27, 2014
  1. Display bad arguments in error

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

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

Commits on Jan 17, 2014
Commits on Dec 18, 2013
  1. Remove unnecessary case clause

    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 26, 2013
Commits on Aug 17, 2013
  1. Add an example of setting the IPv6 hop limit

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

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

    The procket helper will only open devices under the /dev directory.
    Append "/dev/" to the device name for the permissions check.
Commits on May 26, 2013
  1. Add support for sendmsg/recvmsg

    In preparation for support of socket ancillary data (RFC3542, Unix
    sockets, ...), add support for sendmsg(2) and recvmsg(2).
    recvmsg/3 and sendmsg/3 require a struct msghdr to be prepared
    containing pointers to allocated memory (to be read into and to be
    read from respectively). This buffer will have to be allocated using
Commits on May 19, 2013
  1. Remove unused function

Commits on May 17, 2013
  1. Merge branch 'master' of

  2. Add support for getsockopt(2)

Commits on May 3, 2013
Commits on Sep 23, 2012
  1. README and whitespace cleanup

Commits on Jul 30, 2012
  1. Inaccessible devices should not return an error

    get_progname/2 should only return a string.
Something went wrong with that request. Please try again.