[erlang-questions] How to add a option for inet:getopts
Serge Aleynikov
serge@REDACTED
Fri Jan 19 14:29:51 CET 2007
Kenneth,
Thanks for sharing this preliminary info. As a caveat, it looks to me
that this option would require to run erl with root privileges (that
from the security point of view is not a good thing). There's actually
a work around on Linux for this using 'cap_net_raw' capability, where
you can start the process as root, set the capability and switch to
effective user. This would allow to retain access to a raw socket and
not to be root.
If interested I can provide a sample code.
Regards,
Serge
Kenneth Lundin wrote:
> Hi,
>
> We have preliminary planned to implement a new option called "raw" as
> an extension to the
> inet:getopts(Socket,Options)
> and
> inet:setopts(Socket,Options)
> and all other places where socket options are handled.
>
> The new "raw" option would look something like this:
> {{raw,Level,OptionCode},OptionValue}
>
> Both OptionCode and OptionValue is positive integers assumed to be
> mapped on
> UINT32 in C. Thus the use is limited to OptionValues that fits in an
> UINT32.
> Of course the inet_driver will be updated to support this as well.
>
> With this new raw option it should be possible to use various non
> standard and
> non supported socket options directly from Erlang code.
> Thus the example
>
> 'getsockopt(fd,SOL_IP,SO_ORIGINAL_DST,&server,&slen)'.
>
> could be implemented something like this:
>
> -define(SOL_IP,10). % the value 10 is only an example
> -define(SO_ORIGINAL_DST,47). % the value 47 is only an example
> %% The user has to find the right values from the C header files.
> ....
> inet:getopts(Socket,[{raw,$SOL_IP,$SO_ORIGINAL_DST}])
>
> which should return
>
> [{{raw,$SOL_IP,$SO_ORIGINAL_DST},OptionValue}]
>
> Note that this is preliminary ideas which may be adjusted when we
> implement it.
>
> /Regards Kenneth (Erlang responsible at Ericsson)
>
> On 1/19/07, Serge Aleynikov <serge@REDACTED> wrote:
>> The only way to get this socket option accessible from Erlang is to add
>> support for it in the network driver (inet_drv.c).
>>
>> Serge
>>
>> William Gan wrote:
>> > Hello,
>> >
>> > I am preparing to implement a transparent proxy by erlang, and I
>> need an
>> > equivalent call for
>> > 'getsockopt(fd,SOL_IP,SO_ORIGINAL_DST,&server,&slen)'.
>> >
>> > Can anyone give me some advice how to add such a call in erlang?
>> >
>> > William Gan
More information about the erlang-questions
mailing list