lynnN
05-02-2003, 02:42 AM
error message:
server.c:97: warning: assignment makes pointer from integer without a cast
server.c:102: dereferencing pointer to incomplete type
server.c:102: dereferencing pointer to incomplete type
int clientsocket(const char *rhost, unsigned short port)
{
struct hostent *ptrh; /* pointer to a host table entry */
struct sockaddr_in sad;/* structure to hold server's address*/
int fd; /* socket descriptor */
memset((char *)&sad, 0, sizeof(sad)); /* clear sockaddr structure */
sad.sin_family = AF_INET; /* set family to Internet */
sad.sin_port = htons((u_short)port);
/* Convert host name to equivalent IP address and copy sad */
ptrh = gethostbyname(rhost);------------------------------------LINE97
if (((char *)ptrh) == NULL) {
fprintf(stderr, "invalid host: %s\n", rhost);
return (-1);
}
memcpy(&sad.sin_addr, ptrh->h_addr, ptrh->h_length);------LINE102
/* Create a socket */
fd = socket(PF_INET, SOCK_STREAM, 0);
if (fd < 0) {
fprintf(stderr, "socket creation failed\n");
return (-1);;
}
/* Connect the socket to the specified server */
if (connect(fd, (struct sockaddr *)&sad, sizeof(sad)) < 0) {
fprintf(stderr, "connect failed\n");
return (-1);
}
return fd;
}
server.c:97: warning: assignment makes pointer from integer without a cast
server.c:102: dereferencing pointer to incomplete type
server.c:102: dereferencing pointer to incomplete type
int clientsocket(const char *rhost, unsigned short port)
{
struct hostent *ptrh; /* pointer to a host table entry */
struct sockaddr_in sad;/* structure to hold server's address*/
int fd; /* socket descriptor */
memset((char *)&sad, 0, sizeof(sad)); /* clear sockaddr structure */
sad.sin_family = AF_INET; /* set family to Internet */
sad.sin_port = htons((u_short)port);
/* Convert host name to equivalent IP address and copy sad */
ptrh = gethostbyname(rhost);------------------------------------LINE97
if (((char *)ptrh) == NULL) {
fprintf(stderr, "invalid host: %s\n", rhost);
return (-1);
}
memcpy(&sad.sin_addr, ptrh->h_addr, ptrh->h_length);------LINE102
/* Create a socket */
fd = socket(PF_INET, SOCK_STREAM, 0);
if (fd < 0) {
fprintf(stderr, "socket creation failed\n");
return (-1);;
}
/* Connect the socket to the specified server */
if (connect(fd, (struct sockaddr *)&sad, sizeof(sad)) < 0) {
fprintf(stderr, "connect failed\n");
return (-1);
}
return fd;
}