LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Kernel (http://www.linuxquestions.org/questions/linux-kernel-70/)
-   -   proc/net/wireless please HELP (http://www.linuxquestions.org/questions/linux-kernel-70/proc-net-wireless-please-help-730819/)

plugo 06-05-2009 01:24 AM

proc/net/wireless please HELP
 
Hello guys, i have some trouble outputting the result of of /proc/net/wireless into my terminal. Somehow it is only showing part of the answer for linkq(), can anybody help me to see what am i missing to display all of the info?? thank you very much.


#include <limits.h>
#include <stdio.h>
#include <stdarg.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <fcntl.h>
#include <sys/signal.h>
#include <sys/wait.h>
#include <sys/resource.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#define BUFLEN 4096



char *
procread(const char *entry)
{
int fd;
char buf[BUFLEN]="";

if ((fd = open(entry, O_RDONLY)) < 0)
return NULL;
else {
read(fd, buf, BUFLEN);
printf("%s",buf);
close(fd);
return strdup(buf);
}
}


void
linkq(int fd)
{
char *lnq, out[BUFLEN] = "";

if ((lnq = procread("/proc/net/wireless")) == NULL)
write(fd, "could not read /proc/net/wireless\n", BUFLEN);
else {

write(fd, out, strlen(out));
free(lnq);
}
}


int
main()
{
int i;
char t;
for(i=0; i<1; i++)
linkq(t);
return 0;
}

plugo 06-05-2009 01:27 AM

here is what i mean,

i get this:


root@pedro-laptop:/home/pedro# cc link.c
root@pedro-laptop:/home/pedro# ./a.out
Inter-| sta-| Quality | Discarded packets | Missed | WE
face | tus | link level noise | nwid crypt frag retry misc | beacon | 22

when i should be getting this:
root@pedro-laptop:/home/pedro# cat /proc/net/wireless
Inter-| sta-| Quality | Discarded packets | Missed | WE
face | tus | link level noise | nwid crypt frag retry misc | beacon | 22
eth1: 0000 5. -41. -87. 0 190 0 482 0 0

plugo 06-05-2009 06:35 PM

any help??

nini09 06-05-2009 07:52 PM

You should check file read return value. Sometime read action is non-complete. For example, you expect to read 4096 byte but 1024 byte is read at first time.

plugo 06-06-2009 04:07 PM

ahh alright, how would i check though? thanx in advance.

plugo 06-08-2009 05:41 PM

any more help?? i would appreciate it a lot!

nini09 06-09-2009 07:01 PM

something like this.

totalLen = BUFLEN;
totalLenRead = 0;
while (totalLen > 0)
{
lenRead = read(socket, readString + totalLenRead, totalLen);
if (lenRead <= 0)
break;
else
{
totalLenRead += lenRead;
totalLen -= lenRead;
}
}


All times are GMT -5. The time now is 05:10 PM.