00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00018
00019
00020 #include <netinet/in.h>
00021 #include <linux/if.h>
00022 #include <sys/ipc.h>
00023 #include <sys/msg.h>
00024 #include <errno.h>
00025 #include <stdio.h>
00026 #include <string.h>
00027 #include "iwc_print.h"
00028
00029
00030
00031
00032 #define VIF_NOTIFY_KEY 1337
00035 typedef struct {
00036 long mtype;
00037 int ioctl_type;
00038 char dev_name[IFNAMSIZ + 1];
00039 } ioctl_msg;
00040
00041 #define IOCTL_MSG_SIZE sizeof(ioctl_msg)
00042 #define VIF_SIOCSIW 0x10
00045
00046
00051 int
00052 iwc_notify_init()
00053 {
00054 int create_flags = IPC_CREAT | 0664;
00055
00056 int old_id = msgget(VIF_NOTIFY_KEY, create_flags | IPC_EXCL);
00057 if (errno == EEXIST)
00058 {
00059 old_id = msgget(VIF_NOTIFY_KEY, 0664);
00060 msgctl(old_id, IPC_RMID, NULL);
00061 }
00062 return msgget(VIF_NOTIFY_KEY, create_flags);
00063 }
00064
00069 int
00070 iwc_notify_remove(int msgq_id)
00071 {
00072 return msgctl(msgq_id, IPC_RMID, NULL);
00073 }
00074
00081 void
00082 iwc_notify_poll(void *msg_handler)
00083 {
00084 ioctl_msg in_buffer;
00085 int msgq_id = -1;
00086
00087 if (msg_handler == NULL)
00088 {
00089 iwc_error("iwc_notify_init(): msg_handler == NULL\n");
00090 return;
00091 }
00092
00093
00094 iwc_notify_init();
00095 memset(&in_buffer, 0, sizeof(ioctl_msg));
00096 while (1)
00097 {
00098
00099 msgq_id = msgget(VIF_NOTIFY_KEY, 0400);
00100 if (msgrcv(msgq_id, &in_buffer, IOCTL_MSG_SIZE, VIF_SIOCSIW, 0) < 0)
00101 {
00102 iwc_error("iwc_notify_poll(): msgrcv (%s)\n", strerror(errno));
00103 return;
00104 }
00105
00106 ((void (*)(int ioctl_type, const char *dev_name)) msg_handler)
00107 (in_buffer.ioctl_type, in_buffer.dev_name);
00108 }
00109 return;
00110 }