1

On Most Linux Distributions, i was able to list all tcp connections by reading /proc/net/tcp, but this Doesn't exists on solaris, is there a file that i can read tcp connections from on Solaris 11?

thanks.

EDIT: forgot to mention that i'm coding in c.

killercode
  • 1,666
  • 5
  • 29
  • 42
  • 1
    (On Linux, you should be using `ss -t` to list them. The procfs interface is only there because of the compat screamers, but it has been stuck in the past for more than 10 years now.) – jørgensen Jan 04 '12 at 11:32

2 Answers2

4

If you're trying to rewrite netstat, I suggest looking at the source code for it: https://hg.java.net/hg/solaris~on-src/file/tip/usr/src/cmd/cmd-inet/usr.bin/netstat/netstat.c

The important parts are mibopen, which opens /dev/arp and pushes the tcp STREAMS module onto it, and mibget which actually requests the connection information. The code is a bit complicated, so I suggest stepping through the code in a debugger to understand how it works. The key syscalls are open, ioctl, putmsg, and getmsg.

If you just want to see what sockets a process has open, you can inspect /proc/PID/fd, as in pfiles: https://hg.java.net/hg/solaris~on-src/file/tip/usr/src/cmd/ptools/pfiles/pfiles.c

alanc
  • 4,102
  • 21
  • 24
Gabe
  • 84,912
  • 12
  • 139
  • 238
  • i looked at it already, i just couldn't figure out whats going on there or how it works, its not like the linux one at all. – killercode Jan 04 '12 at 09:13
  • You didn't say exactly what you're trying to do, but I updated my answer to include more details. – Gabe Jan 04 '12 at 16:27
0

You should either use netstat -an or pcp

Mike Pennington
  • 41,899
  • 19
  • 136
  • 174