Hi,

I'm working on a small school assignment where I should make my program on a Solaris that connects to a server with TCP and gets a 32-bit integer that contains the time which should then be displayed on the command line.

Now, I don't know much unix and although I've done some programming in Java this is my first program in C.

I think I've connected to the server and downloaded the 4 bytes, but now I don't know how to make them display correctly.

Here are my questions:

1) I wish to see the value of the 4 bytes I downloaded. I've made an attempt in the code. But it doesn't look like any of the examples I've got; 2208988800 should correspond to 00:00 1 jan 1970 GMT and -1297728000 should correspond to 00:00 17 nov 1858 GMT. I get -63.

2) I have no idea about the timeformat of these 4 bytes. I think the time format is standardized but I don't know the specification or where to look for it, or how to convert it, so I'd like to know where I should look for this.

3) Why doesn't my casting work on the last line of code? I'd like to print it as an unsigned int, but still get the signed -63.

Seron

Below is my code
Code:
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <sys/types.h>
#include <time.h>

#define SERVER_PORT 37

int main() {
    
    char *time;
    int sock, byte_count;
    struct sockaddr_in sin;
    struct hostent *hp;
    char *host;

    host = "roman.ludat.lth.se";
    hp = gethostbyname(host);
    if(!hp) {
	printf("unknown host: %s\n", host);
	exit(-1);
    }

    bzero((char *)&sin, sizeof(sin));
    sin.sin_family = AF_INET;
    bcopy(hp->h_addr, (char *)&sin.sin_addr, hp->h_length);
    sin.sin_port = htons(SERVER_PORT);

    if((sock = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
	perror("socket");
	exit(-1);
    }

    if(connect(sock, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
	perror("connect");
	exit(-1);
    }
    
    byte_count = recv(sock, time, 4, 0);
    printf("*time = %d\n", (unsigned int)*time);
}