First,
I am rather new to C programming or at least don't use it enough to get used to it.
My question,
What part of my script needs to do is monitor a port and record the PACKETS and WHO sent them into a multidimensional array. Also I want it to know if that IP address is already in the array and if it is just update the PACKET.
Like:
[Array][1] = [IP][PACKET]
[Array][2] = [IP][PACKET]
I know in C you have to declare variables first so the processor can allocate the right amount of memory, but in my program I will not know exactly how many packets there are going to be. It is safe to say (If I have to) that theres not going to be more than 100max .
And than in the end I need to return that array so a different function can use it.
How would i go about doing this?
First I know i need to declare my array/char with 100 slots with 2 slots in each of them. Let me know if this is correct.
Expand|Select|Wrap|Line Numbers
- char * array[100][2];
In word form: search all number 0 slots in array for 2.0.0.2 if 1 array slot 1 = buf;
Expand|Select|Wrap|Line Numbers
- array[i][0] = inet_ntoa(a.sin_addr);
- array[i][1] = buf;
Now for laughs lets try to print that data with printf()
Expand|Select|Wrap|Line Numbers
- while(i < sizeof(array)) {
- printf("%d - %s\n", i ,array[i][0] );
- i++;
- }
Thanks in advance for any help received?
Cheers :)