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);
}