This is the mail archive of the
glibc-bugs-regex@sourceware.org
mailing list for the glibc project.
[Bug regex/6722] sscanf bug when parsing lines from /proc/net/tcp
- From: "halesh dot s at gmail dot com" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs-regex at sources dot redhat dot com
- Date: 8 Jul 2008 04:09:50 -0000
- Subject: [Bug regex/6722] sscanf bug when parsing lines from /proc/net/tcp
- References: <20080704200314.6722.lists@roberthogan.net>
- Reply-to: sourceware-bugzilla at sourceware dot org
------- Additional Comments From halesh dot s at gmail dot com 2008-07-08 04:09 -------
(In reply to comment #4)
> Either use %8x:%4hx and kill the bogus casts, or you need to assign to
> int/unsigned int temporaries and copy to the short vars afterwards.
I have not changed the testcase as u mentioned, instead i exchanged the
declaration order of ports...Now its working fine..
Please check the testcase
#include <stdio.h>
#include <sys/types.h>
int main()
{
u_int32_t locaddr, remaddr, uid, inode = 0;
/* changed the order of declaration in testcase provided by robert*/
u_int16_t remport, locport;
FILE *f;
char big_str[256];
f = fopen("/proc/net/tcp", "r");
fgets(big_str,256,f);
printf("%s\n", big_str);
while(fgets(big_str,256,f) != NULL) {
printf("%s\n", big_str);
sscanf(big_str, "%*d: %8x:%4x %8x:%4x %*2x %*8x:%*8x %*2x:%*8x
%*8x %d %*d %u \n",&locaddr, (unsigned int *) &locport, &remaddr, (unsigned int
*) &remport,&uid, &inode);
printf("LocAddr:%x LocPort:%x RemAddr:%x RemPort:%x uid:%d
inode:%d\n",locaddr, locport, remaddr, remport, uid, inode);
}
}
O/P is
........
........
53: C865582B:8116 CD65582B:0016 01 00000000:00000000 02:000082E4 00000000
0 0 3258616 2 195aca80 202 40 0 2 -1
LocAddr:c865582b LocPort:8116 RemAddr:cd65582b RemPort:16 uid:0 inode:3258616
........
........
Results are fine now.
It depends upon alignment of 16 bit variables or what???
--
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at redhat dot com,
| |schwab at suse dot de
http://sourceware.org/bugzilla/show_bug.cgi?id=6722
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.