我有一個程式,我需要用到重導的方式,但是編譯的卻發生錯誤要怎麼辦?????
#include<dlfcn.h>
#include<sys/types.h>
#include<netinet/in.h>
int connect(int s, struct sockaddr *addr, int addrlen)
{
int optval = 16, a;
int (*system_connect)(int, struct sockaddr *, int);
void *handle = dlopen("/lib/libc-2.3.2.so",RTLD_LAZY);
system_connect = dlsym(handle, "connect");
if(!system_connect)
printf("dlsym failed\n");
if(setsockopt(s, IPPROTO_IP, IP_TOS, (void *)&optval, sizeof(optval))==-1)
perror("setsockopt");
a = system_connect(s, addr, addrlen);
dlclose(handle);
return a;
}
#socklib.c:6: error: conflicting types for `connect'
#/usr/include/sys/socket.h:124: error: previous #declaration of `connect'