Hello,
I'm observing the above error when executing the program.
Here is an example extract of the relevant code (which works)
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
// Initialise string
char ip_address[16];
char subnet[12];
strcpy(ip_address,"192.168.200.200");
strcpy(subnet,"");
// Process string
int i;
int period_count = 0;
char ch;
int length = strlen(ip_address);
for(i=0;i<length;i++)
{
ch = (ip_address[i]);
if (ch == '.')
{
period_count = period_count + 1;
}
if (period_count == 3)
{
break;
}
strncat(subnet, &ch, 1);
}
printf("Subnet: %s\n",subnet);
return 0;
}
It is difficult for me to post an example of the actual code, without having to post a fair bit of code and some sample input.
The difference between the above example and the actual code that produces the error is that in the code that fails; the field ip_address is initialised as follows:
Code:
strcpy(ip_address,inet_ntoa(source.sin_addr));
The above statement executes without error, however when the above statement is used to initialise the ip_address; program execution subsequently fails here
Code:
strncat(subnet, &ch, 1);
So the issue I have, is that the following code works fine:
Code:
fprintf(logfile , " |-Source IP : %s\n" , inet_ntoa(source.sin_addr) );
Code:
inet_ntoa(source.sin_addr)
is treated as a string
But when I try and use
Code:
strcpy(ip_address,inet_ntoa(source.sin_addr));
As input, while the above statement executes fine. This statement fails
Code:
strncat(subnet, &ch, 1);
Appreciate suggestions on how to workaround
Thanks
VW