Problems with a daytime client

I can't get the client to show the date... Nor connect some times... I also recieve a warning on compile...
The warning and files being used are as follows::

ErrHandle.h
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
#include "unp.h"
#include <stdarg.h>				/*	ANSI C header file */
#include <syslog.h>				/* for syslog() */

int		daemon_proc;					 /* set non-zero by daemon_init() */
static void err_doit(int, int, const char *, va_list);

/* Nonfatal error related to a system call.
 * Print a message and return */
 
void err_ret(const char *fmt, ...) {
	va_list ap;
	va_start(ap, fmt);
	err_doit(1, LOG_INFO, fmt, ap);
	va_end(ap);
	return;
}

void err_sys(const char *fmt, ...) {
	va_list ap;
	va_start(ap, fmt);
	err_doit(1, LOG_ERR, fmt, ap);
	va_end(ap);
	return;
}

void err_dump(const char *fmt, ...) {
	va_list ap;
	va_start(ap, fmt);
	err_doit(1, LOG_ERR, fmt, ap);
	va_end(ap);
	abort();						//dump core and terminate
	exit(1);						// Hopefully doesn't get here
}

void err_msg(const char *fmt, ...) {
	va_list ap;
	va_start(ap, fmt);
	err_doit(0, LOG_INFO, fmt, ap);
	va_end(ap);
	return;
}

void err_quit(const char *fmt, ...) {
	va_list ap;
	va_start(ap, fmt);
	err_doit(0, LOG_ERR, fmt, ap);
	va_end(ap);
	exit(1);
}

/* Print a message and return to caller.
 * Caller specifies "errnoflag" and "level" */
 static void err_doit(int errnoflag, int level, const char *fmt, va_list ap) {
 	int		errno_save, n;
 	char		buf[MAXLINE];
 	errno_save = errno;			//Value caller might want printed
 #ifdef HAVE_VSNPRINTF
 	vsnprintf(buf, sizeof(buf), fmt, ap);		// This is safe
 #endif
 	n = strlen(buf);
 	if (errnoflag)
 		vsnprintf(buf + n, sizeof(buf) - n, " : %s", strerror(errno_save) );
 	strcat(buf, "\n");
 	if (daemon_proc) {
 		syslog(level, buf);
 	} else {
 		fflush(stdout);		//incase stdout and stderr are the same
 		fputs(buf, stderr);
 		fflush(stderr);
 	}
 	return;
 }


Daytimeclie.c
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
#include "unp.h"

int main(int argc, char **argv) {
	int		sockfd, n;
	char		recvline[MAXLINE + 1];
	struct  sockaddr_in servaddr;
	
	if(argc != 2)
		err_quit("Usage: ./DTclient <IP address>\n");
	
	if( (sockfd = socket(AF_INET, SOCK_STREAM, 0) ) < 0 )
		err_sys("Socket Error");
	
	bzero(&servaddr, sizeof(servaddr) );
	servaddr.sin_family = AF_INET;
	servaddr.sin_port = htons(13);						/* Daytime Client */
	if (inet_pton(AF_INET, argv[1], &servaddr.sin_addr) <= 0 )
		err_quit(" inet_pton error for %s\n", argv[1]);
		
	if(connect(sockfd, (SA *) &servaddr, sizeof(servaddr) ) < 0)
		err_sys("connect error\n");
		
	while ( (n = read(sockfd, recvline, MAXLINE) ) > 0 ) {  //open while
		recvline[n] = 0;			//Null terminate
		if (fputs ( recvline , stdout ) == EOF )
			printf("fputs error\n");
		} //close while
		if (n < 0 )
			err_sys("read error\n");
		
		exit(0);
}//close main 


Warnings ::
/home/ingenioushax/ErrHandle.h: In function ‘err_doit’:
/home/ingenioushax/ErrHandle.h:66: warning: format not a string literal and no format arguments
well, im still a beginner, but what happens if you try removing the arguments from the syslog on line 66? that could either fix it, or change the errors. try it, tell me what happens, might be able to figure out something.
It got rid of the error, but now it just gives me a blinking line when ran, Doesn't print anything...
hmm... i dunno. so removing the arguments just kinda broke it? hmm. looking back at the error you originally had, try removing only one of the arguments.
Topic archived. No new replies allowed.