Thread: error: syntax error before 'struct'

  1. #1
    Eager young mind
    Join Date
    Jun 2006
    Posts
    342

    error: syntax error before 'struct'

    I am a little perplexed here . Not able to make out what could be causing this error :

    Code:
         1 #include <stdio.h>
          2 #include <errno.h>
          3 #include <linx.h>
          4 #include <linx_socket.h>
          5 #include <linx_ioctl.h>
          6 #include "linx_basic.sig"
          7 #include "linx_basic.h"
          8
          9 /*
         10  *    LINX example client
         11  */
         12
         13 int main()
         14 {
         15   int listen_sd, tran_sd,temp;
         16   struct sockaddr_linx server_addr;
         17   struct sockaddr_linx client_addr;
         18   char buf[10];
         19
         20   client_addr.family=AF_LINX;
         21
         22   listen_sd = socket(PF_LINX, SOCK_DGRAM ,0);
         23   printf(" listen_sd = %d\n",listen_sd);
         24     temp=ioctl(listen_sd,LINX_IOCTL_HUNT,DX1/linx_basic_client);
         25   printf("temp =%d\n",temp);
         26
         27   tran_sd=ioctl(listen_sd,LINX_IOCTL_HUNT,DX2/linx_basic_server);
         28   printf("tran_sd = %d\n",tran_sd);
         29
         30   server_addr.spid=tran_sd;
         31   temp=recvfrom(tran_sd,buf,10,0,(struct sockaddr*)&server_addr,sizeof(server_addr));
         32   printf("bytes received = %d\n",temp);
         33   printf(" %s \n",buf);
         34
         35   close(tran_sd);
         36   close(listen_sd);
         37   return 0;
         38 }
    And these are the error messages that I got :

    Code:
    Building linx_basic
    linx_basic_client.c: In function 'main':
    linx_basic_client.c:24: warning: implicit declaration of function 'ioctl'
    linx_basic_client.c:24: warning: implicit declaration of function '_IOWR'
    linx_basic_client.c:24: error: syntax error before 'struct'
    linx_basic_client.c:27: error: syntax error before 'struct'
    linx_basic_client.c:31: warning: passing argument 6 of 'recvfrom' makes pointer from integer without a cast
    linx_basic_client.c:35: warning: implicit declaration of function 'close'
    make: *** [linx_basic] Error 1
    I think I have included the "linx_socket.h" and the "linx_ioctl.h" files correctly. I got a lot of errors before i included them in. Though, the first two warnings indicate that something could be wrong there too.
    Also, The errors are pointing to line 24 and 27 , but the struct declaration statements are in lines 16 and 17.
    Should I post any other relevant info?
    In the middle of difficulty, lies opportunity

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    I would guess you need to
    #include <unistd.h>
    as well, to get ioctl() prototyped and _IOWR defined.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Eager young mind
    Join Date
    Jun 2006
    Posts
    342
    Did that, The last warning got knocked off... But the rest still remain :
    Code:
    Building linx_basic
    linx_basic_client.c: In function 'main':
    linx_basic_client.c:25: warning: implicit declaration of function 'ioctl'
    linx_basic_client.c:25: warning: implicit declaration of function '_IOWR'
    linx_basic_client.c:25: error: syntax error before 'struct'
    linx_basic_client.c:28: error: syntax error before 'struct'
    linx_basic_client.c:32: warning: passing argument 6 of 'recvfrom' makes pointer from integer without a cast
    make: *** [linx_basic] Error 1
    In the middle of difficulty, lies opportunity

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Hmpf, ioctl() would seem to be in ioctl.h, not unistd.h

    > DX1/linx_basic_client
    I've no idea what that looks like - but having a division seems odd to me.

    Try
    gcc -E prog.c > prog.i
    to see what the code really looks like after the pre-processor has done it's work, to see if the result actually makes any kind of sense.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    The last error you're getting is because you need to pass a pointer to a socklen_t variable that holds the size of the struct. You can't pass the size directly.
    If you understand what you're doing, you're not learning anything.

  6. #6
    Eager young mind
    Join Date
    Jun 2006
    Posts
    342
    My mistake.. I had not read the doc for the ioctl correctly. The problem was with the argument.
    In the middle of difficulty, lies opportunity

  7. #7
    Eager young mind
    Join Date
    Jun 2006
    Posts
    342
    What makes ioctl generate an error of this kind :
    Code:
    ioctl: Cannot allocate memory
    and this is what dmesg gives :
    Code:
    LINX: ERROR - Could not allocate kernel memory to hold the hunt name.
    In the middle of difficulty, lies opportunity

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Global Variables
    By Taka in forum C Programming
    Replies: 34
    Last Post: 11-02-2007, 03:25 AM
  2. Replies: 10
    Last Post: 05-18-2006, 11:23 PM
  3. What's wrong with my search program?
    By sherwi in forum C Programming
    Replies: 5
    Last Post: 04-28-2006, 09:57 AM
  4. Tutorial review
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 03-22-2004, 09:40 PM
  5. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 03:58 PM