在客户端套接字代码中取消引用错误

use*_*670 0 c sockets

直到yday我的代码运行正常,但今天我得到client.c:61:25:错误:解除引用指向不完整类型client.c:63:16:错误:解除指向不完整类型的指针

这些行再次写在下面.任何形式的帮助将不胜感激.

               #include <stdio.h>
               #include <stdlib.h>
               #include <string.h>
               #include <math.h>
               #include <sys/types.h> 
               #include <sys/socket.h>
               #include <netinet/in.h>
               #define MAXPROFILES  2

              int main(int argc, char *argv[])
          {
              int sockfd, portno, n;
              struct sockaddr_in serv_addr;
              struct hostent *server;
              unsigned char buf[1024];

              struct profile_t 
           {
              unsigned char length;
              unsigned char type;
              unsigned char *data;
           };

              typedef struct profile_datagram_t
          {
             unsigned char src[4];
             unsigned char dst[4];
             unsigned char ver;
             unsigned char n;
             struct profile_t profiles[MAXPROFILES];    
          } header;

             header outObj;

             if (argc < 3) {
             fprintf(stderr,"usage: %s hostname port\n", argv[0]);
             exit(0);
          }
             portno = atoi(argv[2]); //Convert ASCII to integer
             sockfd = socket(AF_INET, SOCK_STREAM, 0); // socket file descriptor


             if (sockfd < 0) 
             error("ERROR DETECTED !!! Problem in opening socket\n");

             server = gethostbyname(argv[1]);
             if (server == NULL) {
             fprintf(stderr,"ERROR DETECTED !!!, no such server found \n");
             exit(0);
           }

            bzero((char *) &serv_addr, sizeof(serv_addr)); //clear the memory for server address

            serv_addr.sin_family = AF_INET;    
            bcopy((char *)server->h_addr, 
                   (char *)&serv_addr.sin_addr.s_addr,
                                    server->h_length);

            serv_addr.sin_port = htons(portno);

            printf("Client 1 trying to connect with server host %s on port %d\n", argv[1], portno); 


            if (connect(sockfd,(struct sockaddr *)&serv_addr,sizeof(serv_addr)) < 0) 
            error("ERROR in connection");

            printf("SUCCESS !!! Connection established \n");
Run Code Online (Sandbox Code Playgroud)

错误是行:

                          *bcopy((char *)server->h_addr, 
                                  (char *)&serv_addr.sin_addr.s_addr,
                                    server->h_length);*
Run Code Online (Sandbox Code Playgroud)

Kar*_*ath 6

您尚未包含gethostbyname的声明:

#include <netdb.h>
Run Code Online (Sandbox Code Playgroud)

编译 -Wall

warning: implicit declaration of function ‘gethostbyname’
Run Code Online (Sandbox Code Playgroud)

关于错误消息:编译器基本上告诉您它不知道如何访问struct的字段,因为它从未看到它的定义.