Bonjour à tous,

Mon code segfault actuellement sur un readdir que je fais:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
 
while ((entry = readdir(dirp)) != NULL)
 {
   printf("%s\n", entry->d_name);
 }
Pour information voici le code en entier:

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
int     main(int ac, char **av)
{
  struct        dirent  *entry;
  struct sockaddr_in sin;
  struct protoent *pre;
  const char    *ip_adress;
  DIR   *dirp;
  FILE  *fd;
  char  *buffer;
  char  s[4096];
  char  *ret_s;
  int   sock;
  int   error;
  int   port;
  int   b;
  int   ret;
 
  if (ac != 3)
    exit(EXIT_FAILURE);
  port = atoi(av[2]);
  ip_adress = av[1];
  buffer = malloc(sizeof(char*));
  pre = getprotobyname("TCP");
  sock = socket(AF_INET, SOCK_STREAM, pre->p_proto);
  sin.sin_family = AF_INET;
  sin.sin_addr.s_addr = inet_addr(ip_adress);
  sin.sin_port = htons(port);
  error = connect(sock, (const struct sockaddr *)&sin, sizeof(sin));
  while (1)
    {
      b = read(0, buffer, 2048);
      buffer[b] = '\0';
      if (ret = strcmp(buffer, "exit") == 10)
        return (0);
      if (ret = strcmp(buffer, "ls") == 10)
        {
          fd = fopen("/home/france_m/my_ftp/serv_conf", "r");
          ret_s = fgets(s, 4096, fd);
          if (s == NULL)
            {
              printf("\33[1;31mfile empty\033[0m\n");
              exit(EXIT_FAILURE);
            }
          if (dirp = opendir(s) == NULL)
            {
              printf("\33[1;31mdirp = NULL\033[0m\n");
              exit(EXIT_FAILURE);
            }
          while ((entry = readdir(dirp)) != NULL)
            {
              printf("%s\n", entry->d_name);
            }
        }
    }
}
Merci par avance pour votre aide, car la je bloque un peu