Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Linux ioctl with Mono

Tags:

mono

ioctl

I'm trying to do ioctl command through Mono framework, but I cant find what I'm looking for.

I'm trying to send command to a DVB card that has a kernel module. I hope someone can link or explain clearly how this can be done. Any example with Mono using kernel modules would be useful I guess.

like image 775
rozon Avatar asked Jun 21 '09 16:06

rozon


4 Answers

Mono does not contain a wrapper for ioctl in Mono.Unix, because ioctl call parameters vary greatly and such a wrapper would be almost useless. You should declare a DllImport for each ioctl you need.

You probably don't need a helper library written in C, however, you may need it during development to extract actual values hidden behind different C preprocessor macros. For example, to expand C header:

#define FE_GET_INFO                _IOR('o', 61, struct dvb_frontend_info)

compile and execute this helper:

#include <linux/dvb/frontend.h>
#include <stdio.h>

int main()
{
  printf("const int FE_GET_INFO = %d;\n", FE_GET_INFO);
  return 0;
}

A short mono mailing list discussion on the topic.

like image 105
skolima Avatar answered Sep 26 '22 15:09

skolima


ioctl isn't supported by Mono AFAIK. Too OS-specific and parameter list depends on actual request. You could try DLLImport

Interop with Native Libraries

like image 29
jitter Avatar answered Sep 22 '22 15:09

jitter


You should write a wrapper library for your exact calls. Look at how Mono.Unix wraps syscalls (google codesearch for Mono.Unix Syscall.cs) to get the idea. Then create a wrapper for each specific ioctl command, which uses your own representation of the data.

As jitter said - you'll need to DLLImport the ioctl itself.

like image 41
viraptor Avatar answered Sep 23 '22 15:09

viraptor


Check for my similar question, and later question on the subject. In this case I'm trying to wrap the Videl4Linux interface, that could be of interest for you.

I really suggest those readings.

like image 28
Luca Avatar answered Sep 26 '22 15:09

Luca