error: request for member ‘err’ in something not a structure or union

This is a discussion on error: request for member ‘err’ in something not a structure or union within the C Programming forums, part of the General Programming Boards category; Hi im writing a socket programmin code for a uni assn and always get an error msg when compiling. Error ...

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    3

    error: request for member ‘err’ in something not a structure or union

    Hi im writing a socket programmin code for a uni assn and always get an error msg when compiling.
    Error message is: error: request for member ‘err’ in something not a structure or union
    UDPclient.c:157: error: request for member ‘errStr’ in something not a structure or union
    UDPclient.c:160: error: request for member ‘x’ in something not a structure or union
    UDPclient.c:161: error: request for member ‘y’ in something not a structure or union
    UDPclient.c:162: error: request for member ‘temp’ in something not a structure or union
    UDPclient.c:163: error: request for member ‘tLeft’ in something not a structure or union
    UDPclient.c:164: error: request for member ‘mLeft’ in something not a structure or union
    UDPclient.c:184: error: request for member ‘mLeft’ in something not a structure or union
    UDPclient.c:185: error: request for member ‘tLeft’ in something not a structure or union

    Code:
    #include <stdio.h>      
    #include <sys/socket.h> /* for socket(), connect(), sendto(), and recvfrom() */
    #include <arpa/inet.h>  /* for sockaddr_in and inet_addr() */
    #include <stdlib.h>     /* for atoi() and exit() */
    #include <string.h>     /* for memset() */
    #include <unistd.h>     /* for close() */
    #include <strings.h>
    #include <time.h>
    #include <sys/types.h>
    #include <netinet/in.h>
    #include <math.h>
    #include <errno.h>
    #include <assert.h>
    
    #define SERV_PORT    31180      /* server UDP port */
    #define SERV_IP		 "149.171.37.233" /* server IP Address */
    #define GRID_SIZE    100        /* 100 x 100 grid */
    #define PASSWD       "thunt10"  /* password in each packet */
    
    #define MAX_MSG_LEN  64        /* max size of any msg */
    #define MAX_TIME     120       /* time (seconds) limit for a game */
    #define MAX_MOVES    100       /* mximum number of moves allowed */
    
    #define MSG_REGISTER    1
    #define MSG_MOVE        2
    
    typedef struct {
      char passwd[8];              /* password */
      unsigned long mType;         /* message type = MSG_REGISTER */
      unsigned long id;            /* student id */
      unsigned short x, y;         /* x and y co-ordinates of starting point */
    } RegMsg_t;
    
    typedef struct {
      char passwd[8];              /* password */
      unsigned long mType;         /* message type = MSG_MOVE */
      unsigned long id;            /* student id */
      char dir;                    /* direction: N, S, E, or W */
      char pad[3];                 /* padding for word-alignment */
    } MoveMsg_t;
    
    typedef struct {
      unsigned long err;           /* error code: 0 if all ok */
      unsigned short x, y;         /* x and y co-ordinates of current location */
      long temp;                   /* temperature */
      unsigned long tLeft;         /* time left */
      unsigned long mLeft;         /* moves left */
      char errStr[108];            /* error string */
    } RespMsg_t;
    
    int main(int argc, char *argv[]) {
    	int sock;                        /* Socket descriptor */
    	int e;
    	long err;
    	int inMsgLen;
    	//int outMsgLen;
    
    	char passwd[8];
    	long temp, tleft, mleft;
    	unsigned short x, y;
    	unsigned long mType, id;
    
    	//long ttaken, mtaken;
    
    	//char dir;
    	//char pad[3];
    
    	char inMsg[MAX_MSG_LEN];
    	//char outMsg[MAX_MSG_LEN];
    
        struct sockaddr_in servAddr;	 /* Echo server address */
        struct sockaddr_in fromAddr;     /* Source address of echo */
    
    	RegMsg_t regmsg;			 	 /* Registration Message */
    	RespMsg_t *respmsg;				 /* Response Message from the Server */
    	//MoveMsg_t movmsg;				 /* Move Message */
    
        //unsigned short echoServPort;     /* Echo server port */
     
        unsigned int fromSize;           /* In-out of address size for recvfrom() */
    
    	unsigned short servPort = 31180; /* Server UDP port number */
    
        char *servIP = "149.171.37.233"; /* IP address of server */
    
    	int regmsgLen;					 /* Length of Registration message */
    
        int respStringLen;               /* Length of received response */
    
    
    
    	/* GETTING REGISTER-MESSAGE PACKAGED & SENT */
        if ((argc < 5) || (argc > 6)) {	  /* Test for correct number of arguments */
        	printf("Please enter <password> <message-type> <student-id> <x-location> <y-location>\n");
    
            exit(1);
        }
    
    	/* Scanning data from user input */
    	strcpy(passwd, argv[1]);    /* First arg: password "thunt10" */
    	mType = atoi(argv[2]);		/* Second arg: message-type */
    	id = atoi(argv[3]);			/* Third arg: student-id */
    	x = atoi(argv[4]);			/* Fourth arg: x-coordinate */
    	y = atoi(argv[5]);			/* Fifth arg: y-coordinate */
    
    	regmsgLen = sizeof(regmsg);
    
        /* Create a datagram/UDP socket */
        if ((sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
            printf("socket() failed");
    	}
    
        /* Construct the server address structure */
        memset(&servAddr, 0, sizeof(servAddr));    		/* Zero out structure */
        servAddr.sin_family = AF_INET;                 	/* Internet addr family */
        servAddr.sin_addr.s_addr = inet_addr(servIP);   /* Server IP address */
        servAddr.sin_port   = htons(servPort);     		/* Server port */
    
    	memset(&regmsg, 0, regmsgLen);
    	strcpy(regmsg.passwd, passwd);
    	regmsg.mType = htonl(mType);
    	regmsg.id = htonl(mType);
    	regmsg.x = htons(x);
    	regmsg.y = htons(y); 
    
        /* Send the string to the server */
        if ((e = sendto(sock, (char *)&regmsg, regmsgLen, 0, (struct sockaddr *)&servAddr, sizeof(servAddr))) != regmsgLen) {
            printf("sendto() sent a different number of bytes than expected");
    	}
      	else if (e < 0) {
    		printf("Error with sending\n");
    		exit(1);
    	}
    
    
        /* RECEIVING A RESPONSE MESSAGE AFTER REGISTRATION */
        fromSize = sizeof(fromAddr);
        respStringLen = recvfrom(sock, (char *)&respmsg, MAX_MSG_LEN, 0, (struct sockaddr *)&fromAddr, &fromSize);
    
        if (servAddr.sin_addr.s_addr != fromAddr.sin_addr.s_addr) {
            fprintf(stderr,"Error: received a packet from unknown source.\n");
            exit(1);
        }
    
    	//respmsg = (RespMsg_t *)&inMsg;
    	err = ntohl(respmsg.err);
    
    	if (err != 0) {
            printf("Registration failed.\n");
    		printf("%s\n", respmsg.errStr);
    	}
    	else {
    		x = ntohs(respmsg.x);
    		y = ntohs(respmsg.y);
    		temp = ntohl(respmsg.temp);
    		tleft = ntohl(respmsg.tLeft);
    		mleft = ntohl(respmsg.mLeft);
    
    		printf("SERVER RESPONSE:\n");
    		printf("x-location = %d\ty-location = %d\n", x, y);
    		printf("temperature = %ld\n", temp);
    		printf("time-left = %ld\n", tleft);
    		printf("moves-left = %ld\n", mleft);
    	}
            return 0;
    }

  2. #2
    Registered User
    Join Date
    Jan 2009
    Posts
    1,485
    It seems like "respmsg" is declared as a pointer to your struct, but you call it like it was a struct, with the dot notation. You need to use something like this:

    Code:
    respmsg->err
    Either that, or dereference it to get to the actual struct.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem Passing Structure Reference To Function
    By soj0mq3 in forum C Programming
    Replies: 9
    Last Post: 04-24-2010, 11:27 AM
  2. union inside structure
    By vijay s in forum C Programming
    Replies: 1
    Last Post: 12-03-2009, 07:21 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM
  4. Structure containing a union of more structures!
    By Bajanine in forum Windows Programming
    Replies: 2
    Last Post: 03-08-2003, 11:53 AM
  5. Serial Communications in C
    By ExDigit in forum Windows Programming
    Replies: 7
    Last Post: 01-09-2002, 10:52 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21