How to trace the send() in client call
Hi All, I need your help. I have written the client server program in which client is sending the packets to the server. I want to trace the "send()" that is used in the client program actually want to trace the system call the packet traverses . How to trace ? Regards
On Mon, May 26, 2014 at 1:48 PM, Robert Clove <cloverobert@gmail.com> wrote:
Hi All,
I need your help. I have written the client server program in which client is sending the packets to the server. I want to trace the "send()" that is used in the client program actually want to trace the system call the packet traverses . How to trace ?
Hi Robert, You can use the strace command line tool. There is an argument to trace only network related syscalls: -e trace=network Trace all the network related system calls. Take a look on the strace manual page for more information. Best regards. -- Augusto Mecking Caringi
Hi Augusto, But there will be other packets also coming from the network like if some one is browsing the net on mozilla. I only want to trace the send() calls that i have used in my code,is that possible? Regards On Tue, May 27, 2014 at 3:49 AM, Augusto Mecking Caringi < augustocaringi@gmail.com> wrote:
On Mon, May 26, 2014 at 1:48 PM, Robert Clove <cloverobert@gmail.com>wrote:
Hi All,
I need your help. I have written the client server program in which client is sending the packets to the server. I want to trace the "send()" that is used in the client program actually want to trace the system call the packet traverses . How to trace ?
Hi Robert,
You can use the strace command line tool.
There is an argument to trace only network related syscalls:
-e trace=network Trace all the network related system calls.
Take a look on the strace manual page for more information.
Best regards.
-- Augusto Mecking Caringi
On Tue, May 27, 2014 at 8:31 AM, Robert Clove <cloverobert@gmail.com> wrote:
But there will be other packets also coming from the network like if some one is browsing the net on mozilla. I only want to trace the send() calls that i have used in my code,is that possible?
Robert, You must specify the PID of your process (to attach strace to a running process), or run your program through strace. Yon can use grep to filter only the write syscall. Regards. -- Augusto Mecking Caringi
Actually what i want to trace is what all netfilter calls the packet trace till it reach destination. Will strace do that because i just ran the strace with client and the server sample program http://www.codeproject.com/Articles/586000/Networking-and-Socket-programming... For the client i got the following result *strace -o /root/Desktop/traceq.txt ./cli* Message from server [root@client Desktop]# cat traceq.txt execve("./cli", ["./cli"], [/* 27 vars */]) = 0 brk(0) = 0x159c000 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fea4c159000 access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory) open("/etc/ld.so.cache", O_RDONLY) = 3 fstat(3, {st_mode=S_IFREG|0644, st_size=68323, ...}) = 0 mmap(NULL, 68323, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fea4c148000 close(3) = 0 open("/lib64/libc.so.6", O_RDONLY) = 3 read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0000\356Ah?\0\0\0"..., 832) = 832 fstat(3, {st_mode=S_IFREG|0755, st_size=1926800, ...}) = 0 mmap(0x3f68400000, 3750152, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x3f68400000 mprotect(0x3f6858b000, 2093056, PROT_NONE) = 0 mmap(0x3f6878a000, 20480, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x18a000) = 0x3f6878a000 mmap(0x3f6878f000, 18696, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x3f6878f000 close(3) = 0 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fea4c147000 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fea4c146000 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fea4c145000 arch_prctl(ARCH_SET_FS, 0x7fea4c146700) = 0 mprotect(0x3f6878a000, 16384, PROT_READ) = 0 mprotect(0x3f67e1f000, 4096, PROT_READ) = 0 munmap(0x7fea4c148000, 68323) = 0 socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 3 connect(3, {sa_family=AF_INET, sin_port=htons(5000), sin_addr=inet_addr("192.168.60.3")}, 16) = 0 read(3, "Message from server", 1023) = 19 fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 6), ...}) = 0 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fea4c158000 write(1, "Message from server\n", 20) = 20 read(3, "", 1023) = 0 exit_group(0) *And for the server i got the following result* strace -o /root/Desktop/trace.txt ./ser socket retrieve success ^C [root@server Desktop]# cat trace traceprocess.sh trace.txt [root@server Desktop]# cat trace.txt execve("./ser", ["./ser"], [/* 26 vars */]) = 0 brk(0) = 0x1727000 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f57e614c000 access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory) open("/etc/ld.so.cache", O_RDONLY) = 3 fstat(3, {st_mode=S_IFREG|0644, st_size=69902, ...}) = 0 mmap(NULL, 69902, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f57e613a000 close(3) = 0 open("/lib64/libc.so.6", O_RDONLY) = 3 read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0000\356\1\2444\0\0\0"..., 832) = 832 fstat(3, {st_mode=S_IFREG|0755, st_size=1926800, ...}) = 0 mmap(0x34a4000000, 3750152, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x34a4000000 mprotect(0x34a418b000, 2093056, PROT_NONE) = 0 mmap(0x34a438a000, 20480, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x18a000) = 0x34a438a000 mmap(0x34a438f000, 18696, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x34a438f000 close(3) = 0 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f57e6139000 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f57e6138000 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f57e6137000 arch_prctl(ARCH_SET_FS, 0x7f57e6138700) = 0 mprotect(0x34a438a000, 16384, PROT_READ) = 0 mprotect(0x34a3a1f000, 4096, PROT_READ) = 0 munmap(0x7f57e613a000, 69902) = 0 socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 3 fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 2), ...}) = 0 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f57e614b000 write(1, "socket retrieve success\n", 24) = 24 bind(3, {sa_family=AF_INET, sin_port=htons(5000), sin_addr=inet_addr("0.0.0.0")}, 16) = 0 listen(3, 10) = 0 accept(3, 0, NULL) = 4 write(4, "Message from server", 19) = 19 close(4) = 0 rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0 rt_sigaction(SIGCHLD, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0 nanosleep({1, 0}, 0x7fffb1502640) = 0 accept(3, 0, NULL) = ? ERESTARTSYS (To be restarted) --- SIGINT (Interrupt) @ 0 (0) --- +++ killed by SIGINT +++ Regards On Tue, May 27, 2014 at 9:26 PM, Augusto Mecking Caringi < augustocaringi@gmail.com> wrote:
On Tue, May 27, 2014 at 8:31 AM, Robert Clove <cloverobert@gmail.com> wrote:
But there will be other packets also coming from the network like if some one is browsing the net on mozilla. I only want to trace the send() calls that i have used in my code,is that possible?
Robert,
You must specify the PID of your process (to attach strace to a running process), or run your program through strace.
Yon can use grep to filter only the write syscall.
Regards.
-- Augusto Mecking Caringi
participants (2)
-
Augusto Mecking Caringi -
Robert Clove