Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

share|improve this question

3 Answers 3

up vote 7 down vote accepted

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
share|improve this answer
    
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
    
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
3  
@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

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

You can browse the netstat source here: http://cvs.berlios.de/cgi-bin/viewvc.cgi/net-tools/net-tools/netstat.c?view=markup or download the netstat.c file.

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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