tcpdump mailing list archives

Re: Error in the "strcat" function


From: Guy Harris <guy () alum mit edu>
Date: Fri, 02 Feb 2007 11:35:37 -0800

Adelmo Silva wrote:
Jin YunYe wrote:
On 2/2/07, Adelmo Silva <adelmojs () hotmail com> wrote:
Hello,
I have a error:

debian:/home/adelmojs/MONOGRAFIA# gcc teste1.c -lpcap -o teste1
teste1.c: In function 'SNIFFER':
teste1.c:294: warning: passing argument 2 of 'strcat' makes pointer from
integer without a cast
teste1.c:294: error: incompatible types in assignment

THE LINE 294 HAS:
string1 = strcat(string1,ips1[i]);

Could you quote the line where you declare "string1" and "ips1" in your program?

char string1[15], string2[15];

u_char flag, *ips1, *ipd1, *ips2, *ipd2;

That means ips1[i] is a u_char, which is an (unsigned) integer.

If you mean that you want to copy the text starting at the "i"th character in ips1 (where the first character is the 0th character), you want to do

        strcat(string1, &ips1[i]);

because

        1) you want a *pointer* to the text starting at the "i"th character in ips1

and

2) you can't assign anything to string1, as it's an array, not a pointer (arrays are *NOT* pointers in C, although a reference to an array, in most but *NOT* all contexts, is converted to a pointer to the element of the array).

Note also that string1 doesn't get any bigger, as an array, so if its contents are "0123456789", ips1's contents are "abcdefghijklmnopqrstuvwxyz", and i is 5, you will overflow the string1 array.

(Note that none of this has anything to do with libpcap.)
-
This is the tcpdump-workers list.
Visit https://cod.sandelman.ca/ to unsubscribe.


Current thread: