parsing ssid with iwconfig in c

Posted by user1781595 on Stack Overflow See other posts from Stack Overflow or by user1781595
Published on 2012-10-28T22:46:06Z Indexed on 2012/10/28 23:01 UTC
Read the original article Hit count: 137

Filed under:
|
|
|

I am about building a bar for DWM (ubuntu linux), showing wifi details such as the ssid.

Thats my code:

#include <stdio.h>
#include <stdlib.h>


int main( int argc, char *argv[] )
{

  FILE *fp;
  int status;
  char path[1035];

  /* Open the command for reading. */
  fp = popen("iwconfig", "r");
  if (fp == NULL) {
    printf("Failed to run command\n" );
    exit;
  }
   char s[500];

  /* Read the output a line at a time - output it. */
  while (fgets(path, sizeof(path)-1, fp) != NULL) {
    sprintf(s,"%s%s",s, path);
  }
    //printf("%s",s);
  /* close */
  pclose(fp);


    char delimiter[1] = "s";
    char *ptr;

    ptr = strtok(s, delimiter);

        printf("SSID: %s\n", ptr);


  return 0;
}

i am getting overflowerrors and dont know what to do. I dont think, thats a good way to get the ssid either... :/ Suggestions?

© Stack Overflow or respective owner

Related posts about c

    Related posts about linux