tracedump
single application IP packet sniffer

inject.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2011-2012 IITiS PAN Gliwice <http://www.iitis.pl/>
00003  * Author: Paweł Foremski <pjf@iitis.pl>
00004  * Licensed under GNU GPL v. 3
00005  */
00006 
00007 #ifndef _INJECT_H_
00008 #define _INJECT_H_
00009 
00010 #include <stdbool.h>
00011 #include <stdint.h>
00012 #include <sys/socket.h>
00013 #include <linux/net.h>
00014 #include <netinet/in.h>
00015 #include <sys/user.h>
00016 #include <libpjf/lib.h>
00017 
00018 #include "tracedump.h"
00019 
00026 void inject_escape_socketcall(struct tracedump *td, struct pid *sp);
00027 
00032 void inject_restore_socketcall(struct tracedump *td, struct pid *sp);
00033 
00035 enum arg_type {
00036         AT_LAST = 0,   
00037         AT_VALUE,      
00038         AT_MEM_IN,     
00039         AT_MEM_INOUT   
00040 };
00041 
00056 int32_t inject_socketcall(struct tracedump *td, struct pid *sp, uint32_t sc_code, ...);
00057 
00059 static inline int inject_autobind(struct tracedump *td, struct pid *sp, int fd)
00060 {
00061         struct sockaddr_in sa = {
00062                 .sin_family = AF_INET,
00063                 .sin_port   = 0,
00064                 .sin_addr   = { INADDR_ANY }
00065         };
00066 
00067         return inject_socketcall(td, sp, SYS_BIND,
00068                 AT_VALUE, fd,
00069                 AT_MEM_IN, sizeof sa, &sa,
00070                 AT_VALUE, sizeof sa,
00071                 AT_LAST);
00072 }
00073 
00076 static inline int inject_getsockname_in(struct tracedump *td, struct pid *sp, int fd, struct sockaddr_in *sa)
00077 {
00078         socklen_t size = sizeof *sa;
00079         int rc;
00080 
00081         rc = inject_socketcall(td, sp, SYS_GETSOCKNAME,
00082                 AT_VALUE, fd,
00083                 AT_MEM_INOUT, sizeof *sa, sa,
00084                 AT_MEM_INOUT, sizeof size, &size,
00085                 AT_LAST);
00086 
00087         if (size != sizeof *sa || sa->sin_family != AF_INET)
00088                 return -2;
00089         else
00090                 return rc;
00091 }
00092 
00094 static inline int inject_getsockopt(struct tracedump *td, struct pid *sp,
00095         int fd, int level, int optname,
00096         void *optval, socklen_t *optlen)
00097 {
00098         return inject_socketcall(td, sp, SYS_GETSOCKOPT,
00099                 AT_VALUE, fd,
00100                 AT_VALUE, level,
00101                 AT_VALUE, optname,
00102                 AT_MEM_INOUT, *optlen, optval,
00103                 AT_MEM_INOUT, sizeof(socklen_t), optlen,
00104                 AT_LAST);
00105 }
00106 
00107 #endif
 All Data Structures Files Functions Variables Enumerations Enumerator Defines