help me connect :(

help me connect :(

Post by Aaro » Fri, 10 Sep 1999 04:00:00

Even my lecturer can't figure this 1 out.... help!  Any resolver gurus
know what's happening?

I've got 2 samples. 1st sample was written by my lecturer to display the
contents of hosent structure.  The 2nd sample is my game with his code
(juz that 1 line with gethostbyname()) ported over.  It works perfectly
fine with the 1st sample - any text string gets accepted by

gethostbyname() causes segmentation fault in the 2nd sample though.
I've tried other alternative ways like assigning to a new char ptr,
copying to a new buffer space, & even hardcoding the string into the
function call.  all will still gimme segmentation fault.  The error
pattern I noticed is strings above 11 or 12 chars will produce the fault

"brady.sgt.g" will be accepted & actually queries the DNS server (I can
see it thru the modem). This is generate the "Server host invalid" msg
of course.

"" will cause segmentation fault immediately, without
sending any DNS query packet.

if I try "" gethostbyname() accepts it, but returns invalid
host. I thought gethostbyname() is able to return a hostent struct with
the same addr?  giving "" will produce segmentation fault
again, & "" will get invalid host, & so on.

Anybody knows how gethostbyname manipulates the string?

int main(int argc, char *argv[])
        char *ptr, **pptr, str[INET_ADDRSTRLEN];

        struct hostent  *hptr;

        while (--argc > 0)
                ptr = *++argv;
                printf("%s", ptr);
                if ((hptr = gethostbyname(ptr)) == NULL)
                        fprintf(stderr, " not valid hostname?\n", ptr);
                printf(" official hostname : %s\n", hptr->h_name);

void start_player(char name[NAME + 1], char *servername, uint16_t port,
int pos[2])
   int sockd;
   struct sockaddr_in serversock;
   struct hostent *serverhost;

        /* test param string */
   printf("HMS %s to enter %s:%d at %d long %d lat\n", name, servername,
port, pos[0], pos[1]);

   if ((serverhost = gethostbyname(servername)) == NULL)
      fprintf(stderr, "Server host invalid.\n");

        /* test string */
   printf("Set server socket now...\n");
   bzero(&serversock, sizeof(serversock));
   inet_pton(AF_INET, serverhost->h_addr_list[0], &serversock.sin_addr);
   serversock.sin_family = AF_INET;
   serversock.sin_port = htons(port);



help me connect :(

Post by Kaz Kylhe » Fri, 10 Sep 1999 04:00:00

>int main(int argc, char *argv[])
>        char *ptr, **pptr, str[INET_ADDRSTRLEN];

>        struct hostent  *hptr;

>        while (--argc > 0)
>        {
>                ptr = *++argv;
>                printf("%s", ptr);
>                fflush(stdout);
>                if ((hptr = gethostbyname(ptr)) == NULL)
>                {
>                        fprintf(stderr, " not valid hostname?\n", ptr);

Oops, extra parameter without matching conversion specifier.

Quote:>                        continue;
>                }
>                printf(" official hostname : %s\n", hptr->h_name);

>void start_player(char name[NAME + 1], char *servername, uint16_t port,


You know that this is just a pointer to char, right? The array notation only
has documentary value.

Quote:>int pos[2])

Don't use uint16_t unless you for some reason need a type that is
exactly 16 bits wide. The types type int or short are more than
adquate for representing a port number.

The uint16_t type is a bleeding edge C9X feature, not yet part of
standard C. It is defined in <inttypes.h>, but an implementation doesn't
have to provide it (what if it the hardware have a 16 bit type?)

>   int sockd;
>   struct sockaddr_in serversock;
>   struct hostent *serverhost;

>        /* test param string */
>   printf("HMS %s to enter %s:%d at %d long %d lat\n", name, servername,
>port, pos[0], pos[1]);

If you want to printf() a uint16_t, you have to use a macro
from <inttypes.h> to supply a conversion specifier.

        #include <inttypes.h>

        uint16_t u;


        printf("u = " PRIu16, u);

The PRIu16 macro expands to a little string literal containing the
implementation's appropriate conversion specifier that matches a uint16_t
parameter. Assuming the implementation supports a uint16_t of course.

The new <inttypes.h> interface gives the programmer a way to use the
preprocessor to detect whether exact-sized types are available.
If a type is not available, then there is no typedef for it and
its corresponding macros are absent.  So you can do

        #include <inttypes.h>
        #ifdef UINT16_MAX
        /* uint16_t type is available! */
        /* uint16_t is not available; provide some alternate proram text
           or use #error to indicate that the program can't work. */

Quote:>   if ((serverhost = gethostbyname(servername)) == NULL)
>   {
>      fprintf(stderr, "Server host invalid.\n");
>      exit(PARAM_FAULT);
>   }

You say that the gethostbyname() function crashes. It's impossible to know whyt
his happens because you have not revealed enough context information. The call
simply repeats the servername parameter, but you have not shown how the data
for that parameter came to be.  Without delving into my psychic powers, I can
only guess that maybe it is not a properly null terminated string!

You said that the crash is sensitive to the number of characters in
the string. Perhaps your string buffer doesn't have enough space.
It's easy to misuse a function like strncpy() to cause this kind of
error. For example:

        char host_name[16];

        strncpy(host_name, source_string, sizeof host_name);

In this case, if the source_string is 16 characters or longer, then surely
enough, only 16 bytes get copied into host_name, but host_name then does not
contain a null terminated string!

Or worse!

        strcpy(host_name, source_string);       /* buffer overflow */


1. Talk refused to talk:(:(:(:(

Hello there people:)...
  I had linux kernel 1.2.8 installed in my system. I have a SLIP/PPP
connection using either dip (for SLIP) or pppd/chat (for PPP).
  Now, Most of my network stuff are working fine without any problem at all
except talk. Talk works fine for local chatting. No problem at all. The
problem is when ever I call out to other machine (using the SLIP/PPP line),
nothing has ever happen. It got as far as Checking invitation stuff. Never
  Just out of curiosity I ran netstate to check the udp connection whenever
I have talk running. Running locally (talk that is) I got output as follow:

Active Internet connections
Proto Recv-Q Send-Q Local Address          Foreign Address        (State)
udp        0      0 lucifer.newpaltz.:1328 *:*                    

Which I presumed opened by talk (only one here because the other side hadn't
responded to the call yet).  I also get the same thing whenever I call
someone outside my system to talk. Of course, it never got to the other
system (I was waiting on the other system using telnet for the talk request,
never got there. And I had made sure that mesg was y).

Now when I call *IN* from other system (telnet to another system and run
talk over there to my system), I have (on my system) output as follow:

Active Internet connections
Proto Recv-Q Send-Q Local Address          Foreign Address        (State)

And also from netstat -a, I could find talk/ntalk were still listening.
Seems to me the call from outside didn't get through.

Now, since I haven't done anything to configure talk specifically, is there
anything I have to do to make this connection possible. Since I can't talk
to outside nor can I receive talk request from other hosts, I'm under the
assumption that my talk program somehow is not configured properly.

Any configuration file I have to check?
man, faq, howto, etc to refer to this kind of error?
May be replace my talk/ntalk/talkd/ntalkd with something else and where to
find it/them?
Does it depend on something in the kernel that I have to enable during the
compile time?
Wrong version altogether with the kernel?
Is it possible that talk needs long time to make the connection? (None of my
other stuff that I know of behave like this).
May be my inetd is broken?
If so, how do I check for it?
And where to find the latest version of it?

And while I'm at it, what's the latest version of talk?
Where to find it?
Is there a better chatting program that's backward compatible with talk?
Meaning that the program has more features than talk but at the same time
can be used to communicate with other regular talk program whenever the
program is not available on the other host.

Send comment and reply to:

2. Recommend for quick boot-shutdown?

3. my trashed hard drive. :( :( :(

4. How do I pass a file as input to a script

5. Cannot connect to my own server :(

6. Help: ppp and local network

7. USR 56K external won't connect under Linux :(

8. Can't locate module ppp-compress

9. Nokia 6310 + GPRS - can't connect :(

10. Can't connect to Napster :(

11. ppp connects!... then just sits there :(

12. Two squids don't want to connect :((

13. inetd dies :(:(