4

Can I view the source code of netstat on my Linux machine?

11

Yes you can. Download it.

But as you don't say what flavor of linux re you using here is couple of examples:

Debian/Ubuntu related:

# What package is the netstat executable in?
apt-file search /usr/bin/netstat
# Now download the source of that package
apt-get source net-tools

CentOS/Red Hat:

yumdownloader --source net-tools
  • I thought that in Linux are some standard places where I can view source code of various commands without need of downloading. – xralf Sep 27 '11 at 9:23
  • apt-get ends with this message Reading package lists... Done Building dependency tree Reading state information... Done E: Unable to find a source package for netstat – xralf Sep 27 '11 at 9:24
  • 1
    Then you'll need to enable the src repos. Go to /etc/apt/sources.list and uncomment the deb-src lines. – hmontoliu Sep 27 '11 at 9:28
  • apt-get with net-tools seems to download it, but where is it saved? – xralf Sep 27 '11 at 9:30
  • 4
    @xralf: you need to explicitly download the source code because most of the distros and users consider it as a waste of space since they trust the build process from the distro. – hmontoliu Sep 27 '11 at 9:30
3

netstat is part of the net-tools suite. The project home page is here: https://sourceforge.net/projects/net-tools/

You can browse the netstat source here: http://sourceforge.net/p/net-tools/code/ci/master/tree/ or view the netstat.c file.

1

Probably you need this: http://www.tazenda.demon.co.uk/phil/net-tools/. If you need more precise answer - use your local package manager to get info about package containing netstat utility.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.