1.在linux環境下,調用execl:if((pid=fork())<0){
printf("fork error\n");
}else if(pid==0){ /*child*/
if(execl("/sbin/ifconfig","ifconfig","eth0","hw","ether",eth0_num,NULL)<0){ exit(1);
}else{ exit(0);
}
}2.其中eth0_num變量是另一個函數調用返回的,是一個指針:函數調用原型:int read_data(int addr,char* data,int len)
實際調用方式:read_data(4, eth0_num,6);/*從地址4,讀6個字節,到eth0_num*/3.但是運行的時候回報錯:ifconfig: invalid hw-addr4.我打印eth0_num的值是:0x7e8b8bf4打印*eth0_num,*(eth0_num+1),*(eth0_num+2)的值是: 00 90 8f值沒錯,但是一直行不通,我試過另一種方式直接復制char *eth0_num="1eed19271ab3";然后調用execl,不使用從函數調用read_data的參數,就能ifconfig成功5.各位給個意見,看如何才能通過傳變量參數的方式,因為我需要從其他地方讀值回來
- 1 回答
- 0 關注
- 1168 瀏覽
添加回答
舉報
0/150
提交
取消