我正在尝试传递一些额外的参数,以便它们可以在我的程序的 SIGINT 调用中使用,但是我得到一个编译错误,这实际上是可以实现的还是我被误导了?
如果可以实现,有人可以在这里解释我的错误吗?
void signal_handler(bool &txMode, char* &txData, int &sendresult, int &sockFD,_
char* &txBuffer, struct sockaddr_ll &socket_address);
int main(int argc, char *argv[]) {
unsigned char sourceMAC[6];
unsigned char destMAC[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
bool txMode = true;
char* txBuffer = (char*)operator new(ETH_FRAME_LEN);
unsigned char* txEtherhead = (unsigned char*)txBuffer;
struct ethhdr *eh = (struct ethhdr *)txEtherhead;
int sockFD;
char* txData = txBuffer + headersLength;
struct sockaddr_ll socket_address;
int sendresult = 0;
signal (SIGINT,signal_handler(txMode, txData, sendresult, sockFD, txBuffer,_
socket_address));
return 0;
}
void signal_handler(bool &txMode, char* &txData, int &sendresult, int &sockFD,_
char* &txBuffer, struct sockaddr_ll &socket_address) {
if(txMode==true) {
std::string param;
std::stringstream ss;
ss << "etheratedeath";
param = ss.str();
strncpy(txData,param.c_str(), param.length());
sendresult = sendto(sockFD, txBuffer, ETH_FRAME_LEN, 0,
(struct sockaddr*)&socket_address, sizeof(socket_address));
}
cout << "You killed me!" << endl;
}
我在编译时收到以下错误;
user@machine:~/c/ethernet1$ gcc -o ethernet1 ethernet1.cpp -lrt
ethernet1.cpp: In function ‘int main(int, char**)’:
ethernet1.cpp:358: error: invalid use of void expression
指 main() 中的这一行;
signal (SIGINT,signal_handler(txMode, txData, sendresult, sockFD, txBuffer, socket_address));