Ask a Question related to UNIX Programming, Design and Development.
-
Nate Hill #1
Strange socket problems on NetBSD.
As an exercise, I'm writing an ident server on my NetBSD box. I've searched
everywhere and can't find anything about these problems. The four relevant
lines are:
//syslog(LOG_DEBUG, (char *)strlen(input));
i = recv(infd, input, strlen(input), 0);
syslog(LOG_DEBUG, input);
send(infd, input, strlen(input), 0);
Now, the reason that the first line is commented is that, if uncommented it
somehow bypasses the next three... read() doesn't block and send() doesn't
do anything:
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Connection closed by foreign host.
Now, if I comment that I get normal behavior except the input isn't
stored/sent correctly:
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
foobar
foobConnection closed by foreign host.
It only returns the first four characters all times. I also had similar
behavior at one point: It return the first three then a question mark -
foo?. When I use sizeof(input) I get loads of random characters.
--
Nate Hill <vugdeox@freeshell.org>
Nate Hill Guest
-
Socket problems in Pocket PC 2003 SE
I've developed an application for an IPAQ PDA (in OpenLaszlo, to say the truth :embarrassment; and projected with Zinc 2.0) compiled for Flash 7,... -
#28136 [Com]: Problems with connection of a non blocking socket
ID: 28136 Comment by: fakeman at i dot ua Reported By: daniele-dll at yahoo dot it Status: No Feedback Bug... -
Flash player 9 beta FreeBSD NetBSD firefox blows
In Ubuntu I was able to install flash player 9.0.21.78 beta and I was able to run Wubbzy in www.nickjr.com using firefox. In NetBSD I did the same... -
Really strange problems
This code: dim before,after before = Request.form("blah") If request.form("submit") = "" OR Request.form("blah") <> RS("txt_threeDigitCode") then... -
Compile report: ruby 1 8 pv 4 @ netbsd - current (success)
Yo, today compiled (successfully) ruby-1.8.0-preview 4 on NetBSD 1.6U (i.e. NetBSD -current from like 17 days ago) and it only had (without -Wall!)... -
William Ahern #2
Re: Strange socket problems on NetBSD.
Nate Hill <vugdeox@freeshell.org> wrote:
you can't cast the return value of strlen() to a character pointer. that's> As an exercise, I'm writing an ident server on my NetBSD box. I've searched
> everywhere and can't find anything about these problems. The four relevant
> lines are:
>
> //syslog(LOG_DEBUG, (char *)strlen(input));
non-sensical.
it's possible that you mean to say sizeof(input) instead of strlen(input).> i = recv(infd, input, strlen(input), 0);
but then make sure input is defined as char input[SOME_SIZE], and not char
*input. of course, you better make sure the ident protocol guarantees you
are sent a fixed sized datum.
strings in C are char arrays (or pointers from char arrays). in order> syslog(LOG_DEBUG, input);
> send(infd, input, strlen(input), 0);
to use strlen() you need the string to be terminated by NUL character: '\0'.
odds are the data you are being sent isn't terminated by a NUL character, but
more likely a newline '\n'.
i think you need to revisit some very basic C lessons.
read the comp.lang.c FAQ.
- Bill
William Ahern Guest
-
William Ahern #3
Re: Strange socket problems on NetBSD.
Nate Hill <vugdeox@freeshell.org> wrote:
in that case, buy the "C Programming Lanuage" (2nd Edition), authored by> Thanks for the answers, I will try to look at it again.
>>>> i think you need to revisit some very basic C lessons.
> Revisit? I never learned any basic C.
>
> I think my first C book was "Mastering Algorithms with C".
Brian Kernighan and Dennis Ritchie (aka the K&R book). this is requisite,
even if you are an ace programmer in some other language. i'm usually the
last person to push for a dead-tree book, but this book is a must.
it's thin and packed w/ everything you'll need to know about ANSI C.
the best tutorial and the best reference, period.
then, once you start reading the book, run through the comp.lang.c FAQ:
[url]http://www.eskimo.com/~scs/C-faq/top.html[/url]
sometimes it helps to read the answer in order to learn the question.
stick w/ ANSI C and ANSI C library routines for awhile before you move
on to Unix interfaces. you can still do an ident server w/o direct
access to the sockets. inetd can fire up your program and connect
stdin/stdout to the socket. that way you can use fread()/fwrite() (ANSI
interface) rather than read()/write() or send()/recv() (Unix interface).
it doesn't hurt to lurk on comp.lang.c. some of those guys write the
language standards, literally.
$0.02
- Bill
William Ahern Guest
-
Nate Hill #4
Re: Strange socket problems on NetBSD.
William Ahern wrote:
I can't purchase anything. however I have seen this book and Stevens book at> Nate Hill <vugdeox@freeshell.org> wrote:>>> Thanks for the answers, I will try to look at it again.
>>>>>>> i think you need to revisit some very basic C lessons.
>> Revisit? I never learned any basic C.
>>
>> I think my first C book was "Mastering Algorithms with C".
> in that case, buy the "C Programming Lanuage" (2nd Edition), authored by
> Brian Kernighan and Dennis Ritchie (aka the K&R book). this is requisite,
> even if you are an ace programmer in some other language. i'm usually the
> last person to push for a dead-tree book, but this book is a must.
> it's thin and packed w/ everything you'll need to know about ANSI C.
> the best tutorial and the best reference, period.
>
> then, once you start reading the book, run through the comp.lang.c FAQ:
>
> [url]http://www.eskimo.com/~scs/C-faq/top.html[/url]
>
> sometimes it helps to read the answer in order to learn the question.
>
> stick w/ ANSI C and ANSI C library routines for awhile before you move
> on to Unix interfaces. you can still do an ident server w/o direct
> access to the sockets. inetd can fire up your program and connect
> stdin/stdout to the socket. that way you can use fread()/fwrite() (ANSI
> interface) rather than read()/write() or send()/recv() (Unix interface).
>
> it doesn't hurt to lurk on comp.lang.c. some of those guys write the
> language standards, literally.
the library. I will read them.
--
Nate Hill <vugdeox@freeshell.org>
Nate Hill Guest



Reply With Quote

