Click here to Skip to main content
15,906,463 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This code works but only once, when it returns FAIL it doesn't return fail again even though it should, however; it does keep running the first part returning ICMP, TCP and UDP IP's....Is it that the MySQL connection is broken? Any help appreciated. Thanks!

if ( bShowTCP )
{
printf("\n -------------------- // -------------------- ");
printf("\n TCP Header:");
              				
int *addressValue = new int();
char *address = LIP; 
inet_pton(AF_INET, address, addressValue);
	if (ip_header->source_ip == *addressValue)
		{
		printf("\n   Source      IP: %s", "0.0.0.0");
		printf("\n   Destination IP: %s", ipDest);
		}
		else
		{
		printf("\n   Source      IP: %s", ipSrc);
		printf("\n   Destination IP: %s", ipDest);
		if (mysql_real_connect(conn,"urlock.db.5513143.hostedresource.com","VendorCheck","Reader1234","urlock",0,NULL,0) !=0)
{
(mysql_query(conn,"SELECT COUNT(*) FROM tblURLIP WHERE IP = inet_aton('ipSrc') And IPStatus = '1' And IPMax = '0'"));
	my_ulonglong i = 0;
	res_set = mysql_store_result(conn);
	my_ulonglong numrows = mysql_num_rows(res_set);
	LEGIT = mysql_fetch_row(res_set);
		if (atoi(LEGIT[i]) == 1)
			{
			printf("\n PASS: %s\n",LEGIT[i]);
			//Insert tblIPAccess
			(mysql_query(conn,"INSERT INTO tblIPAccess (IP , Dwnload)  VALUES(inet_aton('ipSrc'), '1')"));
		//Get Number Of Records
(mysql_query(conn,"SELECT COUNT(*) FROM tblURLAccess WHERE IP = inet_aton('ipSrc') And Dwnload = '1'"));
		my_ulonglong g = 0;
		res_set = mysql_store_result(conn);
		my_ulonglong numrows = mysql_num_rows(res_set);
		TTL = mysql_fetch_row(res_set);
		//Get Quota
(mysql_query(conn,"SELECT (IPQuota) FROM tblURLIP WHERE IP = inet_aton('ipSrc') And IPStatus = '1'"));
        	my_ulonglong h = 0;
		res_set = mysql_store_result(conn);
		MX = mysql_fetch_row(res_set);
		//If Quota and Records Match Set IPMax to 1 or True otherwise do     nothing
		if ((atoi(TTL[g])) < (atoi(MX[h])))
		{
		(mysql_query(conn,"UPDATE tblURLIP SET IPMax '1' WHERE IP = inet_aton('ipSrc')"));
		//printf("Maxed! %s\n");
		mysql_close(conn);
		}
		}
		else
		{
		printf("\n FAIL: %s\n",LEGIT[i]);
		}
		//system("\n  PAUSE");
			}			   
			}
			}
          break;
Posted
Comments
Albert Holguin 4-Aug-11 22:14pm    
wow, that's hard to read... do us all a favor and break up your code and make it readable... that'll help you maintain it in the future as well
Member 7766180 4-Aug-11 22:19pm    
Thanks Albert, I copied direct out of Visual Studio and it was even worse! I tried cleaning it up. Any suggestions are welcome!

1 solution

It looks to me like your code to close the connection is inside a condition. I suspect then that you're not closing your connection. Perhaps if you step through the code in a debugger, you can see where it fails ?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900