hello

j'essaye de savoir quand une connection a changée dans /proc/net/tcp mai sa ne détecte rien
code compilable en c++

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 
#ifndef DEF_ME_NOTIFY
#define DEF_ME_NOTIFY
#include <sys/select.h>
#include <sys/inotify.h>
#include <unistd.h>
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <string>
class c_notify
{
   public:
      c_notify();
      //renvoie 0 si tout ce termine normalment -1 si erreur
      // 1 si le changement a été detecter et s'arrete.
      int start_notify(const std::string & my_path);
   private:
      bool afficher_masque(int mask);
};
 
#endif //fin des macro

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
 
#include "notify.hpp"
c_notify::c_notify(){}
 
//int fd, wd;
 
 
bool c_notify::afficher_masque(int mask)
{
    if (mask & IN_ACCESS)         { return true; }
   else if (mask & IN_MODIFY)      { return true; }
    else if (mask & IN_ATTRIB)      { return true; }
    else if (mask & IN_CLOSE)      { return true; }
    else if (mask & IN_OPEN)      { return true; }
    else if (mask & IN_MOVED_FROM)   { return true; }
    else if (mask & IN_MOVED_TO)   { return true; }
    else if (mask & IN_MOVE_SELF)   { return true; }
    else if (mask & IN_DELETE)      { return true; }
    else if (mask & IN_CREATE)      { return true; }
    else if (mask & IN_DELETE_SELF)   { return true; }
    else if (mask & IN_UNMOUNT)      { return true; }
    else if (mask & IN_Q_OVERFLOW)   { return true; }
    else if (mask & IN_IGNORED)      { return true; }
    else if (mask & IN_ISDIR)      { return true; }
    else { return false; }
}
 
 
int c_notify::start_notify(const std::string & my_path)
{
   size_t r;
    fd_set fds;
    char buffer[8192];
    struct inotify_event *event;
    int fd, wd;
    bool change=false;
 
    /* Initialisation d'inotify */
    fd = inotify_init();
    if (fd < 0) {
        perror("inotify_init");
        return -1;
    }
 
    /* Surveillance du fichier/répertoire passé en paramètre
     * On accepte tous les évènements possibles */
    wd = inotify_add_watch(fd, my_path.c_str(), IN_ALL_EVENTS);
    if (wd < 0) {
        perror("inotify_add_watch");
       return -1;
    }
 
    while (1) {
        FD_ZERO(&fds);
        FD_SET(fd, &fds);
        if (select(fd + 1, &fds, NULL, NULL, 0) <= 0) {
            continue;
        }
 
        /* Obtention des informations sur l'évènement qui vient de se produire */
        r = read(fd, buffer, sizeof(buffer));
        if (r <= 0) {
            perror("read");
       return -1;
        }
 
        event = (struct inotify_event *) buffer;
       // printf("Fichier surveillé n°%d\t", event->wd);
        change=afficher_masque(event->mask);
        if (change == true)
        {
         return 1;
      }
/*
        if (event->len) {
        //    printf("\tObjet : %s", event->name);
        }
        //printf("\n");
*/
    }
 
           return 0; //surveilliance terminée on revoie 0
 
}

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
 
#include <iostream>
#include <string>
#include "notify.hpp"
int main()
{
 
   c_notify c_n;
   std::string p;
   std::cout << "Démarrage" << std::endl;
   p="/proc/net/tcp";
   std::cout << "Arret" << c_n.start_notify(p) <<std::endl;
 
}
si on lance un naviteur ou une session rien n'est detecter ??

Note attention un cat est trouver si vous passer des commande sur les fichier surveillier.

Merci d'avance

_____________