Click to See Complete Forum and Search --> : Modifying telnetd - message Q problem
tecknophreak
02-28-2003, 03:43 PM
OS: RH8
I'm changing the telnetd for a different use. I'm trying to take the ascii chars which come over the network and send them to another process using message queues. I've been able to parse out all of the chars to my liking, I just can't seem to init a message queue.
Here's a snippet of my init of the Message Queue:
void initMsg(int *msgid, int key, int *file) {
long int msg_to_receive = 0;
*msgid = msgget((key_t)key, 0666 | IPC_CREAT);
}
There's a little more in that code, but that's where the problem occurs. I make a call from the telnet function in telnetd.c.
What's happening when I telnet to my host, I get
Trying 127.0.0.1...
Connected to algorithm (127.0.0.1).
Escape character is '^]'.
Connection closed by foreign host.
If I comment out the msgget(...), it runs normally without this premature exit. Can't I call that function from a service in xinetd?
bastard23
02-28-2003, 05:30 PM
tecknophreak,
Are you getting a segmentation fault? Sounds like telnetd is exiting abnormally. What is the error coming from telnetd. Try running it manually and/or under a debugger? Is msgid or file properly allocated? Checking *msgid and msgsend() for errors? Sorry for the basic answer, but my limited knowledge of System V IPC is that it should be working.
Good Luck,
chris
tecknophreak
02-28-2003, 05:53 PM
Originally posted by bastard23
Sorry for the basic answer, but my limited knowledge of System V IPC is that it should be working.
I hear that bastard. The problem with telnetd, is that it has to be run as a service. You get an error if you don't.
Ok, I was double checking to see if the vars have the mem, and yes they did. I did forget to use &msgid instead of msgid, but even then it stopped.
So, what I did was this, which should work:
int initMsg(int key) {
int msgid;
msgid = msgget((key_t)key, 0666 | IPC_CREAT);
if (msgid == -1) {
return -1;
}
return msgid;
}
bastard23
02-28-2003, 06:05 PM
tecknophreak,
Don't know what version of telnet you have (Redhat's ?), but Debian's telnetd (netkit 0.17) has a -debug <portnum> option. It allows you to start it from the command line and optionally use a different port. Of course, under the BUGS section it has "The source code is not comprehensible." But what telnet code is?
Good Luck,
chris
tecknophreak
03-01-2003, 05:06 PM
bastard (cause it's more fun to write than chris), somehow I missed that. :rolleyes: Huh. Look at how nice that is. thanks.
I now have to check and see if the two programs will talk to each other. The -debug option will come in handy.
I almost want to delete this thread cause I feel so dumb. :confused: oh well, happens
thanks again
bastard23
03-01-2003, 05:35 PM
No worries, plus if you hadn't posted, I wouldn't have known either. Plus your msgget() code means I get to pull out the Stevens book (Advanced Programming in the UNIX Enviroment). Always enlightening.
Have fun,
chris (Pretending someone is yelling "You bastard!!!")
tecknophreak
03-01-2003, 05:53 PM
Originally posted by bastard23
(Advanced Programming in the UNIX Enviroment).
Good book? I still haven't needed to get past Wrox Publishing Beginning Linux Programming.
Well the transfermation is almost done. Just have to look for messages to get sent out, and woohoo.
bastard23
03-01-2003, 06:22 PM
Very good book, yes. Any book by W. Richard Stevens is worth investing in. This book is a little old and won't talk about current implementations, but probably is the reference about UNIX. Check out the TCP/IP books or the networking programming books. If you're doing UNIX/Linux programming you should really get it. It's saturday, so no links, but go a googlin' for more info. There may be better/more up to date books, I just don't own them.
Unfortunately, he passed on in 1999. RIP.
Have fun,
chris