<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    > If we managed to get the port (though I still don't know the
    way)<br>
    Finally, I've managed to do it:<br>
    F = fun(P, Acc) -> case catch prim_inet:getfd(P) of {ok, FD}
    -> [{FD, P} | Acc]; _ -> Acc end end.<br>
    L = lists:foldl(F, [], erlang:ports()).<br>
    Port = proplists:get_value(MyFD, L).<br>
    <br>
    Pay attention that prim_inet is internal module of VM, so it's usage
    should be avoided in any production code!<br>
    <br>
    Salikhov Dinislam<br>
    <br>
    <div class="moz-cite-prefix">On 02/06/2017 05:12 PM, Salikhov
      Dinislam wrote:<br>
    </div>
    <blockquote
      cite="mid:49b5442a-7d16-a2a4-c881-b1fc881e8f75@kaspersky.com"
      type="cite">
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      IIUC, {fd, integer() >= 0} allows to use the socket received
      from socket() C function (or somehow else, but I can't propose
      another way).<br>
      <br>
      > Is there a way to receive controlling process of the socket?<br>
      If we managed to get the port (though I still don't know the way),
      the controlling process can be obtained as following:<br>
      {_, Pid} = erlang:port_info(Port, connected).<br>
      <br>
      <div class="moz-cite-prefix">On 02/06/2017 04:30 PM, Steve Vinoski
        wrote:<br>
      </div>
      <blockquote
cite="mid:CAO+zUOVBqk69XR0UDtTtOpd2TvBx7F24Aq=oGmd9M1CNA+PftA@mail.gmail.com"
        type="cite">
        <div dir="ltr"><br>
          <div class="gmail_extra"><br>
            <div class="gmail_quote">On Mon, Feb 6, 2017 at 8:18 AM,
              Salikhov Dinislam <span dir="ltr"><<a
                  moz-do-not-send="true"
                  href="mailto:Dinislam.Salikhov@kaspersky.com"
                  target="_blank">Dinislam.Salikhov@kaspersky.com</a>></span>
              wrote:<br>
              <blockquote class="gmail_quote" style="margin:0px 0px 0px
                0.8ex;border-left:1px solid
                rgb(204,204,204);padding-left:1ex">Hi!<br>
                <br>
                I have a Unix file descriptor of Erlang VM process.<br>
                I know that it is a TCP socket in ESTABLISHED state.<br>
                Is there a way to receive an Erlang port of the socket?<br>
                Is there a way to receive controlling process of the
                socket?</blockquote>
              <div><br>
              </div>
              <div>See theĀ {fd, integer() >= 0} option that various
                gen_tcp functions can take:</div>
              <div><br>
              </div>
              <div><a moz-do-not-send="true"
                  href="http://erlang.org/doc/man/gen_tcp.html">http://erlang.org/doc/man/gen_tcp.html</a><br>
              </div>
              <div><br>
              </div>
              <div>--steve</div>
            </div>
          </div>
        </div>
      </blockquote>
      <br>
    </blockquote>
    <br>
  </body>
</html>