Strange socket problems on NetBSD.

Ask a Question related to UNIX Programming, Design and Development.

  1. #1

    Default 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

  2. Similar Questions and Discussions

    1. 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,...
    2. #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...
    3. 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...
    4. Really strange problems
      This code: dim before,after before = Request.form("blah") If request.form("submit") = "" OR Request.form("blah") <> RS("txt_threeDigitCode") then...
    5. 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!)...
  3. #2

    Default Re: Strange socket problems on NetBSD.

    Nate Hill <vugdeox@freeshell.org> wrote:
    > 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));
    you can't cast the return value of strlen() to a character pointer. that's
    non-sensical.
    > i = recv(infd, input, strlen(input), 0);
    it's possible that you mean to say sizeof(input) instead of strlen(input).
    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.
    > syslog(LOG_DEBUG, input);
    > send(infd, input, strlen(input), 0);
    strings in C are char arrays (or pointers from char arrays). in order
    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

  4. #3

    Default Re: Strange socket problems on NetBSD.

    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.

    $0.02

    - Bill
    William Ahern Guest

  5. #4

    Default Re: Strange socket problems on NetBSD.

    William Ahern wrote:
    > 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.
    I can't purchase anything. however I have seen this book and Stevens book at
    the library. I will read them.

    --
    Nate Hill <vugdeox@freeshell.org>
    Nate Hill Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139