LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-28-2006, 05:41 AM   #1
noir911
Member
 
Registered: Apr 2004
Posts: 682

Rep: Reputation: Disabled
C time server client error


I just wrote a udp time client from Steven's TCP/IP Illustrated. The server the I am pointing to actually doesn't have a time server. But when I run the code it doesn't give any error & just sits there. Is it because I used "perror" instead of "err_sys" as described in the book? I tried using "err_sys" but it gives this error -

Code:
/tmp//ccx26364.o(.text+0x44): In function `main':
: undefined reference to `err_sys'
Code:
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>

#define BUFFSIZE 150

int
main()
{
    struct sockaddr_in serv;
    char buff[BUFFSIZE];
    int sockfd, n;

    if ((sockfd = socket (AF_INET, SOCK_DGRAM, 0)) < 0 )
//      err_sys ("socket error");
        perror ("socket error");
    bzero ((char *) &serv, sizeof (serv));

    serv.sin_family = AF_INET;
    serv.sin_addr.s_addr = inet_addr ("192.168.1.65");
    serv.sin_port = htons(13);

    if (sendto(sockfd, buff, BUFFSIZE, 0,
                (struct sockaddr *) &serv, sizeof(serv)) != BUFFSIZE)
        //      err_sys ("sendto error");
                perror ("sendto error");

    if (( n = recvfrom(sockfd, buff, BUFFSIZE, 0,
                    (struct sockaddr *) NULL, (int *) NULL )) < 2)
//      err_sys ("receive from error");
        perror ("reeive from error");

    buff [n-2] = 0;
    printf ("%s\n", buff);
    exit(0);
}
 
Old 06-28-2006, 06:30 AM   #2
debulu
Member
 
Registered: May 2006
Location: India
Distribution: Redhat
Posts: 49

Rep: Reputation: 15
My friend the err_sys() call is defined by stevens in the appendix of the book and it is just a wrapper written by the great man. So that is not your problem. Even perror() should work fine. Just give a newline (\n) after the message of perror() and wait for some time while running. It may take a little time to decide the reachability of the host.
Second thing is remove the receive part form the program or exit after first perror(). May be it blocks at that recvfrom() call and sits there.
Code:
              if(sendto fails)
                 {
                    perror("Failed to establish con\n");
                    exit(0);
                  }
Hope helps

Last edited by debulu; 06-28-2006 at 06:36 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
WebDAV - 'client denied by server configuration' error jamesrh Linux - Software 2 03-11-2015 09:19 AM
cs 1.6 server protocol error (46) client (47) cillie Linux - Games 12 12-29-2005 05:09 AM
creating server socket program to handle multiple client at same time cranium2004 Programming 2 03-14-2005 10:58 AM
NFS, client to server, time too large hendrikus Linux - Networking 6 08-18-2004 01:15 PM
NFS, client to server, time too large hendrikus Linux - Networking 2 07-29-2004 05:16 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:49 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration