Hello
Thanks to reply.
I found the same solution:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <pthread.h>
#include <mqueue.h> // required for messages
#include <asm/types.h>
#include <sys/socket.h>
#include <linux/rtnetlink.h>
#include <linux/netlink.h>
void* SDcardManager_thread(void*)
{
int ns = -1;
struct sockaddr_nl sa;
char buf[4096];
struct iovec iov = { buf, sizeof(buf) };
struct msghdr msg = { &sa, sizeof(sa), &iov, 1, NULL, 0, 0 };
int len;
memset (&sa, 0, sizeof(sa));
sa.nl_family = AF_NETLINK;
sa.nl_groups = RTMGRP_LINK | RTMGRP_IPV4_IFADDR;
ns = socket(AF_NETLINK, SOCK_RAW, NETLINK_KOBJECT_UEVENT);
if (ns < 0) {
perror("socket()");
ret=0;
}//end if (ns < 0)
if (bind(ns, (struct sockaddr*)&sa, sizeof(sa))) {
perror("bind()");
ret=0;
}//end if (bind(ns, (struct sockaddr*)&sa, sizeof(sa)))
while (ret) {
len = recvmsg (ns, &msg, 0);
if (len < 0) {
perror("recvmsg()");
break;
}//fi(len < 0)
buf[4095] = 0;
if((strstr(buf,NAME_SD))!=NULL)
{
//sdcard add
if((strstr(buf,NAME_ADD))!=NULL)
{
//todo here your code
}//if((strstr(buf,NAME_ADD))!=NULL)
else
{
//sdcard remove
if((strstr(buf,NAME_REMOVE))!=NULL)
{
//todo here your code
}//if((strstr(buf,NAME_REMOVE))!=NULL)
}//else((strstr(buf,NAME_ADD))!=NULL)
}//fi((strstr(buf,NAME_SD))!=NULL)
}//end while
return ((void*)&ret);
}
Best regards
François.