c functions to turn off open ports in linux

nmap is a network utility which gives u information about open ports on ur system. for eg

$ nmap 10.226.112.202
PORT STATE SERVICE
7/tcp open echo
13/tcp open daytime
22/tcp open ssh
23/tcp open telnet
37/tcp open time
1100/tcp open unknown

these open ports can be closed manually by editing /etc/inetd.conf file.

I want to write C functions which should close ports by running that c programs. for eg; c function should close above mentioned telnet port on 23.

inetd doesn't work that way. It doesn't "turn ports off", it either listens or doesn't listen on a particular port and runs a certain service when someone connects according to a text file. If you insisted in doing it in C, you'd probably be calling shell scripts with system() to edit inetd.conf then signalling inetd to reload its config file.

In other words it's not a system function you're asking for, this isn't a firewall; you have to ask inetd to do something. You could listen yourself, but then you'd be writing your own inetd from scratch instead of controlling the one that already exists.

1 Like

and to complicate things you may also need to interact with xinetd configuration files which are laid out differently than /etc/inetd.conf.

1 Like