#include #include #define Boolean int #define TRUE 1 #define FALSE 0 #define MAX_PIPE_BUFSIZE 256 Boolean get_ip(char * pv) { FILE * fp; char cmdbuf[128], value[32]; sprintf(cmdbuf,"/sbin/ifconfig eth0 | grep inet | cut -d\":\" -f2 | cut -d\" \" -f1"); fp = popen(cmdbuf, "r"); if (fp == NULL) { // printf("Fail to open pipe\n"); return FALSE; } memset(value,0,sizeof(value)); if (!feof(fp) && fgets(value,MAX_PIPE_BUFSIZE,fp) != NULL) ; // printf("value:%s\n", value); else { printf("ip wrong\n"); return FALSE; } pclose(fp); if(strlen(value) < 10) return FALSE; strcpy(pv,value); return TRUE; } int main(int argc, char const *argv[]) { char ipaddr[16],cmd_line[240]; if(!get_ip(ipaddr)) { system("mpg123 -r 48000 /home/new-speaker/target/share/sounds/get_ip_failed.mp3"); return 0; } strcpy(cmd_line,"cd /home/new-speaker/target/share/sounds/;mpg123 -r 48000 "); int i; for (i=0;i