toto je m?j zdroj?k
#include <mysql/mysql.h>
#include <stdio.h>
char prikaz[20]="ping -c 2 10.0.0.3";//totto mi ne?lo nadefinovat lok?ln? hl?silo:
//neopr?vn?n? p??stup k pam?ti
int main()
{
MYSQL *mysql;
MYSQL_RES *res;
MYSQL_ROW row;
char* query;
char* ping;
int t,r;
mysql_init(mysql);
if (!mysql_real_connect(mysql,"localhost","root",
"ginger","ping",0,NULL,0))
printf( "Error connecting to database: %sn",mysql_error(mysql));
else printf("Connected...n");
query="select * from ip";
t=mysql_real_query(mysql,query,(unsigned int) strlen(query));
if (t)
{
printf("Error making query: %sn",
mysql_error(mysql));
}
else printf("Query made...n");
res=mysql_store_result(mysql);
row=mysql_fetch_row(res);
ping=(char *) malloc(20);
sprintf(ping,"ping -c 2 %s",row[1]);
printf("Tady by mel za??t vykon?vat ping pomoc? funkce systemn");
system("ping -c 2 10.0.0.3");
system(ping);
system(prikaz);
printf("Tady by mel skon?itn");
/*printf("po?et sloupcu=%dn",mysql_num_fields(res));
printf("po?et radku=%dn",mysql_num_rows(res));
printf("Verze serveru %sn",mysql_get_server_info(mysql));*/
mysql_free_result(res);
mysql_close(mysql);
return 0;
}
A toto je m?j v?stup
tommassino@tuxhouse:~/program$ ./mysql
Connected...
Query made...
Tady by mel za??t vykon?vat ping pomoc? funkce system
Tady by mel skon?it
tommassino@tuxhouse:~/program$
jinak rozhodn? by m?li fungovat v?echny t?? způsoby toho vol?n? system.nebot tady je progr?mek kde to funguje jak m?
jeho zdroj?k
#include<stdio.h>
int main()
{
char *string;
char *ip;
char prikaz[20]="ping -c 2 10.0.0.3";
ip="10.0.0.3";
string=(char *) malloc(20);
sprintf(string,"ping -c 2 %s",ip);
printf("nnping ?islo jedna:n");
system(string);
printf("nping ?islo dva:nn");
system(prikaz);
printf("nping ?islo tri:nn");
system("ping -c 2 10.0.0.3");
return 0;
}
a jeho o?ek?v?n? v?stup
ping ?islo jedna:
PING 10.0.0.3 (10.0.0.3) 56(84) bytes of data.
64 bytes from 10.0.0.3: icmp_seq=1 ttl=64 time=0.187 ms
64 bytes from 10.0.0.3: icmp_seq=2 ttl=64 time=0.175 ms
--- 10.0.0.3 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 999ms
rtt min/avg/max/mdev = 0.175/0.181/0.187/0.006 ms
ping ?islo dva:
PING 10.0.0.3 (10.0.0.3) 56(84) bytes of data.
64 bytes from 10.0.0.3: icmp_seq=1 ttl=64 time=0.182 ms
64 bytes from 10.0.0.3: icmp_seq=2 ttl=64 time=0.176 ms
--- 10.0.0.3 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 999ms
rtt min/avg/max/mdev = 0.176/0.179/0.182/0.003 ms
ping ?islo tri:
PING 10.0.0.3 (10.0.0.3) 56(84) bytes of data.
64 bytes from 10.0.0.3: icmp_seq=1 ttl=64 time=0.182 ms
64 bytes from 10.0.0.3: icmp_seq=2 ttl=64 time=0.173 ms
--- 10.0.0.3 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 999ms
rtt min/avg/max/mdev = 0.173/0.177/0.182/0.014 ms
tommassino@tuxhouse:~/program$