Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 11 Jan 1998 16:32:55 +0300
From:      "Artem Koutchine" <matrix@norilsk.ru>
To:        <questions@freebsd.org>
Subject:   Questions for C programmers (freopen and network apps)
Message-ID:  <01bd1e95$6d351e40$0d00a8c0@matrix.gerpa.ru>

next in thread | raw e-mail | index | archive | help
Hello!!!

I am pretty new to the UNIX programming in C (however, i've been
programming in C for DOS/Windows for 8 years and about 2 years in
perl).

Here's what i need to accomplish:

I need a visual remote control for the server, which a i administer. My
boss,
ORDERED me to make a visual, easily understandable system which other
employees (less technically minded and totaly un-Un*X-oid) can use to
control user accounts (this company is an ISP).

So, since they (employees) will access the server via dialup from a far-away
office, i decided i need something quite secure. Web didn't seem to me as
appropriate way bacause of the way it works, so i decided to make a menu
system attached to a port, so the office managers can telnet to the server's
port and
get a nice shell looking somewhat like TurboVision (if someone can still
remember
how it looks like :)

After about a day of reading man and looking at the sources and figured that
i can
skip all the socket management and just add a new service into /etc/services

myserv    6666/tcp
myserv    6666/udp

then add my program into inetd.conf

myserv    stream     tcp    nowait    root    /usr/local/bin/myprogd
myprogd

Then I used ncurses and wrote a little test program. Itworked.
Then i started to write a fish (a skeleton that is). The idea seemed pretty
steight forward:

1) since inetd does all of  the input/outpurt management i don't even care
about it
2) write SIG handler, which logs out a user when the user is disconnected
3) write the interface and all management functions.

The question i have so far are:

1) It is easy to login a user (just check password and write into my own
"utmp" file his
name and date when he logged into the management system). But the prblem
comes
up when the user wants to logout.  If he does it by going into menu in the
telnet client
and chooses DISCONNECT, the program (myprogd) just terminates without
receiving
any SIGnal. This way i have no chance to logout the manager. I tried many
SIGs and could
not find the proper one. Man says nothing about what happens in this case.
If the
programm does not recice a sig or it is '9' then i have no idea what to do.
What should i do ?
How is it doen in case of telnetd ? (i could not figure it..)

2) I have a log file and some output which can be redirected to a file or to
a stdout. since
the procedure itself is quite big, i decided just put something like

freopen ("/var/log/servlog","a",stdout);

before the main body if the argument says so, and when it exists, i just
restore the
original stdout stream. BUT! I just could not resotore it.
doing:

freopen ("/dev/stdout"."w",stdout");

does not work. Man for freopen says, that freopen is used to this kind of
task, but it says
nothing about how to restore it to original. I also looked at several
sources which use
freopen, but it seems that they restore the original stream simply buy
exiting, which does not
suit me.

3) general question:
I use ncurses. SInce when a user connects to port 6666 the terminal is not
initialized, i just set three env vars:

putenv ("COLUMNS=80");
putenv ("LINES=24');
putenv ("TERM=vt100");

and then call

initscr();

It works fine. But is it the right way ? Maybe there is something terribly
wrong with it. I am asking because i have nothing to compare with. All of
the
progs i saw are made to be run in telnet or normal shell, not as a inetd
child
process. And others just do not use ncurses.

4) Even more general question:
I chose to do the management system this strange way (not but using some
command
in telnet or given a menu when a manager logs in) because i plan in some
distant
future to make a ms windows client for this manager server. This will
require a daemon
which sits just like telnetd and waits for connection. Before this i made
some daemons
in perl, which sit on a port and listen. In perl i had to make my own
socket, bind it
and listen to it. But i guess i could wire those perl scripts to inetd and
forget about all that
socket stuff (since inetd handles that for me. right ?). But it just seems
too EASY. There
must be a catch here. What is that catch ? Am I going the right way ?

5) Are some MUDs made this way  or all muds just usual apps wich are called
when a
user logs into telnetd ?

6) In the light of the above said, i am starting to wonder about the point
of having p-terminals.
It just seems to me now, as ttyps are kind of too abstract and hardly
meaning anything. I even
hardly understand what is the connection between, for example, telnetd and
some p terminal.
I think telnetd would work just find without attaching itself to a terminal,
but it does so, just
because the system is build somewhat around the terminals. (you can't even
send a message
to someone if he is not on a terminal). But as i understand, p terminals are
just points of
reference, not a technical necessity.


Sorry, for such long questions, but i just started digging programming for
UNIX in C and
i can't find any info on web and no books (especially tutorials) around here
(Moscow). So,

7) Are there good resources and tutorials on networks programming in C for
UNIX on WWW ?

Thank you very much for reading this long letter.

Regards,
Artem Koutchine
matrix@norilsk.ru














Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?01bd1e95$6d351e40$0d00a8c0>