Menu

data definition has no class or storage

bitshadow
2008-02-07
2012-09-26
  • bitshadow

    bitshadow - 2008-02-07

    i'm posting the following snippet of code that for some reason when i attempt to compile gives me an error msg.

    the code:

    /stun value types/
    typedef unsigned char u_int8;/8 bits == 1byte or a char (2^8-1) = 255 /
    typedef unsigned short u_int16;/16 bits == 2bytes or short (2^16-1)= 65,535/
    typedef unsigned int u_int32;/32 bits == 4bytes or int (2^32-1)/

    /stun header field/
    typedef struct{
    u_int16 msg_t;/16 bit stun message type/
    u_int16 msg_l;/16 bit sizeof stun (payload)/
    u_int8 trans_id[16];/128 bit(16 BYTES) stun client ID from 0-2^(128-1)/
    }xstun_header_t;

    /stun's payload field/
    typedef struct{
    u_int16 msg_attr;/16 bit message attribute/
    u_int16 msg_len;/16 bit length of the payload value/
    }xstun_payload_t;

    /address struct used by mapped,response,source,changed & reflected from addy/
    typedef struct{
    u_int16 addr_family;/always 0x01 first 8bits ignored 2 presereve boundries/
    u_int16 addr_port;
    u_int32 addr_ip;
    }xstun_addr_t;

    /change request value struct/
    typedef struct{
    u_int32 change_request;
    }xstun_change_request_t;

    /username and password value struct/
    typedef struct{
    char user_pwd[MAX_STUN_STRING];
    }xstun_user_pwd_req_t;

    /error code value structure/
    typedef struct{
    u_int16 padding;/21 bits all 0 for padding/
    u_int8 error_class;/represents 1-9 for the error type returned/
    u_int8 error_code_number;/num: 0 - 99 modulo 100 reps error code/
    char error_reason[MAX_STUN_STRING];/reason of the error code/
    }xstun_error_code_t;

    /unknown attributes value struct/
    typedef struct{
    u_int16 unknown_attr[MAX_UNKNOWN_ATTRIBUTES];
    }xstun_unknown_attributes_t;/return of unknown attributes/

    /message integrity value struct used with hmac-sha/
    typedef struct{
    u_int8 hmac[HMAC_BYTES];/padded with zeros for multiple of 64/
    }xstun_message_integrity_t;

    /encapuslate the stun message into user struct/
    typedef struct{
    /message header information/
    xstun_header_t header;
    xstun_payload_t payload;

    /payload address values/
    xstun_addr_t mapped_address;
    xstun_addr_t response_address;
    xstun_addr_t source_address;
    xstun_addr_t changed_address;
    xstun_addr_t reflected_from;

    /payload password/username values/
    xstun_user_pwd_req_t user_name;
    xstun_user_pwd_req_t pass_word;

    /payload hmac,unknown,change request values/
    xstun_message_integrity_t hmac_check;
    xstun_unknown_attributes_t unknown_attribute;
    xstun_change_request_t change_request;

    /payload error code attribute/
    xstun_error_code_t stun_error;
    }xstun_message_t;

    the problem seems to be in the xstun_addr_t and xstun_change_request_t. the only thing they have in common is the
    u_int32 type which of course because dev won't recognize it as a class or storage type then the xstun_message_t becomes invalid as well.i can't for the life of me figure out what i'm doing wrong. can someone please kindly point me in the right direction.

    the error message:
    Compiler: Default compiler
    Building Makefile: "C:\X3\Dependants\xstun\build\Makefile.win"
    Executing make clean
    rm -f ../src/xstun.o libxstun.exe

    gcc.exe -c ../src/xstun.c -o ../src/xstun.o -I"C:/Dev-Cpp/include"

    In file included from ../src/xstun.c:4:
    C:/Dev-Cpp/include/xstun/xstun.h:103: error: syntax error before numeric constant
    C:/Dev-Cpp/include/xstun/xstun.h:103: warning: no semicolon at end of struct or union
    C:/Dev-Cpp/include/xstun/xstun.h:104: warning: data definition has no type or storage class

    C:/Dev-Cpp/include/xstun/xstun.h:135: error: syntax error before numeric constant
    C:/Dev-Cpp/include/xstun/xstun.h:135: warning: no semicolon at end of struct or union
    C:/Dev-Cpp/include/xstun/xstun.h:136: error: syntax error before numeric constant
    C:/Dev-Cpp/include/xstun/xstun.h:137: error: syntax error before numeric constant

    C:/Dev-Cpp/include/xstun/xstun.h:138: error: syntax error before numeric constant
    C:/Dev-Cpp/include/xstun/xstun.h:146: error: syntax error before numeric constant
    C:/Dev-Cpp/include/xstun/xstun.h:146: error: 'xstun_change_request_t' redeclared as different kind of symbol
    C:/Dev-Cpp/include/xstun/xstun.h:104: error: previous declaration of 'xstun_change_request_t' was here
    C:/Dev-Cpp/include/xstun/xstun.h:146: warning: data definition has no type or storage class
    C:/Dev-Cpp/include/xstun/xstun.h:149: error: syntax error before '}' token
    C:/Dev-Cpp/include/xstun/xstun.h:149: warning: data definition has no type or storage class
    C:/Dev-Cpp/include/xstun/xstun.h:183: error: syntax error before '' token
    C:/Dev-Cpp/include/xstun/xstun.h:183: error: syntax error before '
    ' token
    C:/Dev-Cpp/include/xstun/xstun.h:183: warning: data definition has no type or storage class
    C:/Dev-Cpp/include/xstun/xstun.h:186: error: syntax error before '' token
    C:/Dev-Cpp/include/xstun/xstun.h:186: error: syntax error before '
    ' token
    C:/Dev-Cpp/include/xstun/xstun.h:186: warning: data definition has no type or storage class
    C:/Dev-Cpp/include/xstun/xstun.h:189: error: syntax error before '' token
    C:/Dev-Cpp/include/xstun/xstun.h:189: error: syntax error before '
    ' token
    C:/Dev-Cpp/include/xstun/xstun.h:189: warning: data definition has no type or storage class

    make.exe: *** [../src/xstun.o] Error 1

    Execution terminated

     
    • bitshadow

      bitshadow - 2008-02-08

      thanks for answering clifford. the full code follows:

      ifndef XSTUN_H

      define XSTUN_H

      /
      implemenation of RFC4389 stun (simple traversal of udp over nat).
      1)stun client connects to public [stun] server via tcp/ip with request
      2)authentication may or may not be used. stun server sends reply
      3)based on server response client can deduce it's type of nat
      4)stun client and server uses the following message format:
      ------header-------------+-------payload---------------
      -------------------------------------------------------
      | | | | | | |
      |msg_t |msg_l |trans_id |attr_t |attr_l |attr_value|
      | | | | | | |
      -------------------------------------------------------
      stun nat discovery process: declare stun types
      send shared secred request over TCP/TLS (test if all use TLS)
      struct clientinfo = test1, test2, test,3; pass clientinfo to RTP
      /

      /stun communicates on this port/

      define XSTUN_PORT (3478)

      /max attribute understood by stun/

      define MAX_ATTR_UNDERSTOOD (0x7FFF)

      /max string length used in password and username requests/

      define MAX_STUN_STRING (256)

      /max hmac number of bytes a multiple of 60/

      define HMAC_BYTES (120)

      /max number of !known attributes we'll accept/

      define MAX_UNKNOWN_ATTRIBUTES (20)

      /change request flags to use/

      define CHANGE_IP_FLAG (/toogle bit 30/)

      define CHANGE_PORT_FLAG (/toggle bit 31/)

      /IP family represents/

      define IPv4 (0x01)

      /all attributes below this must be understood/

      define STUN_ATTR_LIMIT (0X7FFF)

      /stun comunicates with two message types requests in the header/

      define binding_request (0x0001)

      define binding_response (0x0101)

      define binding_error_response (0x0111)

      define shared_secret_request (0x0002)

      define shared_secret_response (0x0102)

      define shared_secret_error_response (0x0112)

      /each message type requests has attribute types in the payload/

      define mapped_address (0x0001)/ip/port of client/

      define response_address (0x0002)/addy to respond to/

      define change_request (0x0003)/change ip or port/

      define source_address (0x0004)/where request sent from/

      define changed_address (0x0005)/**/

      define username (0x0006)/name of client/

      define password (0x0007)/pwd of client/

      define message_integrity (0x0008)/msg integrity check/

      define error_code (0x0009)/error that occured/

      define unknown_attributes (0x000a)/indicates unknown attribute/

      define reflected_from_address (0x000b)/sender ip irequest came from/

      /error codes recieved from the server/

      define error_400 "bad request"

      define error_401 "unauthorized"

      define error_430 "stale credentials"

      define error_420 "unknown attribute"

      define error_431 "integrity check failure"

      define error_432 "missing username"

      define error_433 "use TLS"

      define error_500 "server error"

      define error_600 "global failure"

      /stun value types/
      typedef unsigned char u_int8;/8 bits == 1byte or a char (2^8-1) = 255 /
      typedef unsigned short u_int16;/16 bits == 2bytes or short (2^16-1)= 65,535/
      typedef unsigned int u_int32;/32 bits == 4bytes or int (2^32-1)/

      /stun header field/
      typedef struct{
      u_int16 msg_t;/16 bit stun message type/
      u_int16 msg_l;/16 bit sizeof stun (payload)/
      u_int8 trans_id[16];/128 bit(16 BYTES) stun client ID from 0-2^(128-1)/
      }xstun_header_t;

      /stun's payload field/
      typedef struct{
      u_int16 msg_attr;/16 bit message attribute/
      u_int16 msg_len;/16 bit length of the payload value/
      }xstun_payload_t;

      /address struct used by mapped,response,source,changed & reflected from addy/
      typedef struct{
      u_int16 addr_family;/always 0x01 first 8bits ignored 2 presereve boundries/
      u_int16 addr_port;
      u_int32 addr_ip;
      }xstun_addr_t;

      /change request value struct/
      typedef struct{
      u_int32 change_request;
      }xstun_change_request_t;

      /username and password value struct/
      typedef struct{
      u_int8 user_pwd[MAX_STUN_STRING];
      }xstun_user_pwd_req_t;

      /error code value structure/
      typedef struct{
      u_int16 padding;/21 bits all 0 for padding/
      u_int8 error_class;/represents 1-9 for the error type returned/
      u_int8 error_code_number;/num: 0 - 99 modulo 100 reps error code/
      char error_reason[MAX_STUN_STRING];/reason of the error code/
      }xstun_error_code_t;

      /unknown attributes value struct/
      typedef struct{
      u_int16 unknown_attr[MAX_UNKNOWN_ATTRIBUTES];
      }xstun_unknown_attributes_t;/return of unknown attributes/

      /message integrity value struct used with hmac-sha/
      typedef struct{
      u_int8 hmac[HMAC_BYTES];/padded with zeros for multiple of 64/
      }xstun_message_integrity_t;

      /encapuslate the stun message into user struct/
      typedef struct{
      /message header information/
      xstun_header_t header;
      xstun_payload_t payload;

      /payload address values/
      xstun_addr_t mapped_address;
      xstun_addr_t response_address;
      xstun_addr_t source_address;
      xstun_addr_t changed_address;
      xstun_addr_t reflected_from;

      /payload password/username values/
      xstun_user_pwd_req_t user_name;
      xstun_user_pwd_req_t pass_word;

      /payload hmac,unknown,change request values/
      xstun_message_integrity_t hmac_check;
      xstun_unknown_attributes_t unknown_attribute;
      xstun_change_request_t change_request;

      /payload error code attribute/
      xstun_error_code_t stun_error;

      }xstun_message_t;

      /the nat types we can get back from stun tests/
      typedef enum{
      udp_not_supported = 0,/can't support UDP/
      full_cone_nat,/public ip anyone can get connect/
      restricted_cone_nat,/have to intiate first/
      port_restricted_nat,/port and ip have to intiate/
      symmetric_nat, /corporate NAT will need TURN/
      }xstun_nat_type;

      /public stun servers for tests before writing our own/

      define stun_server1 "stun.ekiga.net"

      define stun_server2 "stun.fwdnet.net"

      define stun_server3 "stun.sipgate.net"

      define stun_server4 "stun.xten.com"

      define stun_server5 "stunserver.org"

      define stun_server6 "stun1a.voice.re2.yahoo.com"

      define stun_server7 "stun2a.voice.re2.yahoo.com"

      /stun servers without any dns records/

      define stun_server8 "stun01.sipphone.com"

      define stun_server9 "stun.softjoys.com"

      define stun_server10 "stun.voipbuster.com"

      define stun_server11 "stun.voxgratia.org"

      /stun communication socket /
      SOCKET xstun_socket;

      /holds ip, ip family and port information of remote server/
      struct sockaddr_in xstun_server;

      /to get the domain name and decompase to dotted quad ip/
      struct hostent *xstun_domain;

      /initialises the client stun session/
      void xstun_init_stun_session(void);

      /constructs a random transaction id for the stun client/
      xstun_message_t * xstun_make_transaction_id(xstun_message_t *);

      /initialized the header with msg lenth and msg value/
      xstun_message_t * xstun_init_stun_header(xstun_message_t ,char msg_t);

      /initialize the payload with length, type and value/
      xstun_message_t * xstun_init_stun_payload(xstun_message_t ,char attr_t);

      /on error. successful termination and a stun error code is logged/
      void xstun_error();

      endif

      and the error log is:

      Compiler: Default compiler
      Building Makefile: "C:\X3\Dependants\xstun\build\Makefile.win"
      Executing make clean
      Building Makefile: "C:\X3\Dependants\xstun\build\Makefile.win"
      Executing make clean
      rm -f ../src/xstun.o libxstun.a

      gcc.exe -c ../src/xstun.c -o ../src/xstun.o -I"C:/Dev-Cpp/include"

      In file included from ../src/xstun.c:4:
      C:/Dev-Cpp/include/xstun/xstun.h:104: error: syntax error before numeric constant
      C:/Dev-Cpp/include/xstun/xstun.h:104: warning: no semicolon at end of struct or union
      C:/Dev-Cpp/include/xstun/xstun.h:105: warning: data definition has no type or storage class

      C:/Dev-Cpp/include/xstun/xstun.h:137: error: syntax error before numeric constant
      C:/Dev-Cpp/include/xstun/xstun.h:137: warning: no semicolon at end of struct or union
      C:/Dev-Cpp/include/xstun/xstun.h:138: error: syntax error before numeric constant
      C:/Dev-Cpp/include/xstun/xstun.h:139: error: syntax error before numeric constant

      C:/Dev-Cpp/include/xstun/xstun.h:140: error: syntax error before numeric constant
      C:/Dev-Cpp/include/xstun/xstun.h:150: error: syntax error before numeric constant
      C:/Dev-Cpp/include/xstun/xstun.h:150: error: 'xstun_change_request_t' redeclared as different kind of symbol
      C:/Dev-Cpp/include/xstun/xstun.h:105: error: previous declaration of 'xstun_change_request_t' was here
      C:/Dev-Cpp/include/xstun/xstun.h:150: warning: data definition has no type or storage class
      C:/Dev-Cpp/include/xstun/xstun.h:155: error: syntax error before '}' token
      C:/Dev-Cpp/include/xstun/xstun.h:155: warning: data definition has no type or storage class
      C:/Dev-Cpp/include/xstun/xstun.h:193: error: syntax error before '' token
      C:/Dev-Cpp/include/xstun/xstun.h:193: error: syntax error before '
      ' token
      C:/Dev-Cpp/include/xstun/xstun.h:193: warning: data definition has no type or storage class
      C:/Dev-Cpp/include/xstun/xstun.h:196: error: syntax error before '' token
      C:/Dev-Cpp/include/xstun/xstun.h:196: error: syntax error before '
      ' token
      C:/Dev-Cpp/include/xstun/xstun.h:196: warning: data definition has no type or storage class
      C:/Dev-Cpp/include/xstun/xstun.h:199: error: syntax error before '' token
      C:/Dev-Cpp/include/xstun/xstun.h:199: error: syntax error before '
      ' token
      C:/Dev-Cpp/include/xstun/xstun.h:199: warning: data definition has no type or storage class

      make.exe: *** [../src/xstun.o] Error 1

      Execution terminated

       
    • bitshadow

      bitshadow - 2008-02-08

      /change request value struct/
      typedef struct{
      u_int32 change_request; /*line 104
      }xstun_change_request_t;

       
    • cpns

      cpns - 2008-02-08

      Consider the affect of this line:

      define change_request (0x0003)/change ip or port/

      on this code:

      /change request value struct/
      typedef struct{
      u_int32 change_request;
      }xstun_change_request_t;

      It is a common convention to use all-capitals for macro names. Had you adhered to that convention you would have avoided the problem. Note that you have done this more than once with other macro names too.

      Note also that <stdint.h> defines a number of 'exact-width' data types with the advantage of being bothe standard and correct for any particular platform's compiler. The names are similar to yours, e.g: uint32_t, uint8_t, int32_t etc. http://en.wikipedia.org/wiki/Stdint.h

      Clifford

       
      • bitshadow

        bitshadow - 2008-02-08

        Thanks Clifford, you are right i probably should have adhered to that convention and i made the necessary changes and will check out the link you posted. thanks again.

         
    • cpns

      cpns - 2008-02-07

      I wonder why you are concerned about "data definition has no type or storage class" when there are a number of errors before that message. Faced with a syntax error all best are off for parsing the rest of the code, so always fix from the top.

      The error is reported on line 103 of xstun.h. The code you posted has only 78 lines, so it is hard for us to locate the problem. At a guess I would say that you perhaps have an ill-defined macro. For example if you had say:

      define MAX_STUN_STRING = 256 ;

      the member

      char user_pwd[MAX_STUN_STRING];

      would become:

      char user_pwd[= 256 ;];

      which would make no sense to the compiler. A 'correct' definition would be:

      define MAX_STUN_STRING 256

      or in C++ it would be better to have:

      static const int MAX_STUN_STRING = 256 ;

      My guess may be wrong, but you'll have to let us know where line 103 is so we can match the log to the code at least.

      Clifford

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.