/* This file is a simple wrapping layer that will transparently attach the DPF library to a program that invokes the standard libc network functions, when statically linked. Note that this module has no effect and will not be included in a program unless special flags are given to the linker. Thus, you may safely ignore this if you are not interested. To force transparent linking, give these flags to the compiler: -Wl,--wrap,socket -Wl,--wrap,bind -Wl,--wrap,listen -Wl,--wrap,connect -Wl,--wrap,accept -Wl,--wrap,select -Wl,--wrap,recv -Wl,--wrap,read -Wl,--wrap,recvfrom -Wl,--wrap,send -Wl,--wrap,sendto -Wl,--wrap,write -Wl,--wrap,close -Wl,--wrap,dup -Wl,--wrap,dup2 -Wl,--wrap,getsockname -Wl,--wrap,getsockaddr -Wl,--wrap,getsockopt -Wl,--wrap,fcntl -Wl,--wrap,fork -Wl,--wrap,execve This will only work with the GNU linker. */ #include "GCB.h" static int inside=0; #define WRAPPER( name, params, args ) \ int __real_##name params ;\ int __wrap_##name params \ {\ if(inside) {\ return __real_##name args ;\ } else {\ int result;\ inside = 1;\ result = DPF_##name args ;\ inside = 0;\ return result;\ }\ } WRAPPER(socket,(int domain, int type, int protocol),(domain,type,protocol)) WRAPPER(bind,(int fd, struct sockaddr *my_addr, socklen_t addrlen),(fd,my_addr,addrlen)) WRAPPER(listen,(int fd, int backlog),(fd,backlog)) WRAPPER(connect,(int fd, const struct sockaddr *serv_addr, socklen_t addrlen),(fd,serv_addr,addrlen)) WRAPPER(accept,(int fd, struct sockaddr * peer, socklen_t *addrlen),(fd,peer,addrlen)) WRAPPER(select,(int maxfd,fd_set *readfds,fd_set *writefds,fd_set *exceptfds,struct timeval *timeout),(maxfd,readfds,writefds,exceptfds,timeout)) WRAPPER(recv,(int fd, void *buf, size_t len, int flags),(fd,buf,len,flags)) WRAPPER(read,(int fd, void *buf, size_t count),(fd,buf,count)) WRAPPER(recvfrom,(int fd, void *buf, size_t len, int flags,struct sockaddr *from, socklen_t *fromlen),(fd,buf,len,flags,from,fromlen)) WRAPPER(send,(int fd, const void *msg, size_t len, int flags),(fd,msg,len,flags)) WRAPPER(sendto,(int fd,const void *msg, size_t len, int flags,const struct sockaddr *to, socklen_t tolen),(fd,msg,len,flags,to,tolen)) WRAPPER(write,(int fd, const void *buf, size_t count),(fd,buf,count)) WRAPPER(close,(int fd),(fd)) WRAPPER(dup,(int fd),(fd)) WRAPPER(dup2,(int oldfd, int newfd),(oldfd,newfd)) WRAPPER(getsockname,(int fd, struct sockaddr * name, socklen_t *namelen),(fd,name,namelen)) WRAPPER(getsockopt,(int fd,int level,int optname,void *opt_val,socklen_t *optlen),(fd,level,optname,opt_val,optlen)) WRAPPER(fcntl,(int fd, int cmd, long arg),(fd, cmd, (void *)arg)) WRAPPER(fork,(),()) WRAPPER(execve,(const char *path, char *const argv[], char *const envp[]),(path,argv,envp))