Welcome to Tech Support Forum home to more then 136,000 problems solved. Issues have included: Spyware, Malware, Virus Issues, Windows, Microsoft, Linux, Networking, Security, Hardware, and Gaming Getting your problem solved is as easy as:
1. Registering for a free account
2. Asking your question
3. Receiving an answer

Registered members:
* Get free support
* Communicate privately with other members (PM).
* Removal of this message
* See fewer ads.
* And much more..

 





Want to know how to post a question? click here Having problems with spyware and pop-ups? First Steps
Go Back   Tech Support Forum > Networking Forum > Networking Support
User Name
Password
Site Map Register Donate Rules Blogs Mark Forums Read

Networking Support General Networking Support Forum

Reply
 
Thread Tools
Old 03-17-2007, 03:00 AM   #1 (permalink)
Registered User
 
Join Date: Mar 2007
Posts: 10
OS: fedora5


how to compare

Quote:
[root@localhost src]# cat /proc/net/dev
Inter-| Receive | Transmit
face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed
lo: 3679006 16314 0 0 0 0 0 0 3679006 16314 0 0 0 0 0 0
eth0:14562108 62251 0 0 0 0 0 0 7789381 41532 0 0 0 0 0 0
sit0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
[root@localhost src]# cat /proc/net/dev
Inter-| Receive | Transmit
face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed
lo: 3679006 16314 0 0 0 0 0 0 3679006 16314 0 0 0 0 0 0
eth0:14562108 62251 0 0 0 0 0 0 7789381 41532 0 0 0 0 0 0
sit0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
it is fine.
but how can i compare these last two prints of "etho"
that is
eth0:14562108 62251 0 0 0 0 0 0 7789381 41532 0 0 0 0 0 0

eth0:14562108 62251 0 0 0 0 0 0 7789381 41532 0 0 0 0 0 0

the above two lines comes when net is down.
so, how can i compare these two lines programatically
i tried like this
Quote:
char print()
{

FILE* FD;
char buf[256] = {0};
char buf1[256] = {0};
char buf2[256] = {0};
char buf3[256] = {0};
char* linkstatus = NULL;

FD = popen ("cat /proc/net/dev ", "r");

if (FD)
{
fgets (buf, sizeof (buf), FD);
buf[strlen(buf) - 1] = '\0';
fgets (buf1, sizeof (buf1), FD);
buf1[strlen(buf) - 1] = '\0';
fgets (buf2, sizeof (buf2), FD);
buf2[strlen(buf1) - 1] = '\0';
fgets (buf3, sizeof (buf3), FD);
buf3[strlen(buf2) - 1] = '\0';
linkstatus = strstr (buf3, "eth0");
printf("buf3=%s\n",buf3);
printf("linkstatus=%s\n",linkstatus);
}

pclose (FD);

if (strcmp (linkstatus, ":")!=NULL)
{

printf ("Success \n");

}
else
{
printf ("Unplugged \n");

}
return -1;
}
this code prints only present

i have to store the previous prints also

then ony i can compare prev. eth0
and present eth0

if these are not equal net is up
else net is down

help me in this way

thank you in advance
munna_dude is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Bookmark on Thread SoupReddit!
Reply With Quote
Old 03-21-2007, 12:35 AM   #2 (permalink)
Registered User
 
Join Date: Mar 2007
Posts: 10
OS: fedora5


thank you for quick replay

hi

some times it is not showing proper output

i tried like this

[root@localhost ~]# cat /proc/net/dev | grep eth0 | sed 's/^[ \t]*//' | cut -d" " -f2
6052555

some times it has spaces immediately after eth0:
eth0: 6046602 20579 3302 73 1104 0 0 0 307233

some times it may have more one spaces, some times it has no spaces.

can you please help me to get the number immediately after eth0:


thank you in advance
munna_dude is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Bookmark on Thread SoupReddit!
Reply With Quote
Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT -7. The time now is 12:08 PM.



Copyright 2001 - 2008, Tech Support Forum

Search Engine Friendly URLs by vBSEO

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