|
---------------------------
get ip,use system() call ifconfig>tmp.ip
---------------------------*/
if((ret=system("ifconfig >/tmp/tmp.ip"))==-1)
{
perror("system error");
return(-1);
}
/*-----------------------------
read from tmp.ip,add it to msg[CONT]
-----------------------------*/
if((f_open=fopen("/tmp/tmp.ip","r")) ==NULL)//open /tmp/tmp.ip
{
perror("fopen error");
return(-1);
}
i=0;
while((fread(&ip,1,1,f_open)) !=-1)//read from tmp.ip
{
i++;
if(i>SIZE)//if file is large than SIZE,only read SIZE bytes
break;
}
strncat(ip,"\n.\n",3);//cat "\n.\n" to data
msg[CONT]=ip;
fclos 页码:[1] [2] [3] [4] [5] [6] [7] [8] [9] [10] 第5页、共10页 |