Thread: Redefinition errors in when compiling...

  1. #1
    C lover
    Join Date
    Oct 2007
    Location
    Virginia
    Posts
    266

    Redefinition errors in when compiling...

    Not sure what's going on here but I have several linux header files included and when I compile my program I get the below errors... I'm not sure how I should go about fixing it? Am I NOT supposed to use some of these headers? Source is below as well.

    Looking through the headers mentioned in these errors, it's looking like stuff really is defined in multiple places... Like I said, not so sure what to do about it.

    Errors:
    Code:
    codeblox@Lubuntu-pc:~/Programming/C/Network/MITM/src$ gcc -g -o mitm *.c
    In file included from mitm.h:12:0,
                     from create_raw.c:1:
    /usr/include/netpacket/packet.h:22:8: error: redefinition of ‘struct sockaddr_ll’
    In file included from /usr/include/linux/netdevice.h:30:0,
                     from /usr/include/linux/if_arp.h:26,
                     from mitm.h:10,
                     from create_raw.c:1:
    /usr/include/linux/if_packet.h:12:8: note: originally defined here
    In file included from mitm.h:12:0,
                     from create_raw.c:1:
    /usr/include/netpacket/packet.h:51:8: error: redefinition of ‘struct packet_mreq’
    In file included from /usr/include/linux/netdevice.h:30:0,
                     from /usr/include/linux/if_arp.h:26,
                     from mitm.h:10,
                     from create_raw.c:1:
    /usr/include/linux/if_packet.h:261:8: note: originally defined here
    In file included from mitm.h:14:0,
                     from create_raw.c:1:
    /usr/include/net/if.h:44:5: error: expected identifier before numeric constant
    /usr/include/net/if.h:111:8: error: redefinition of ‘struct ifmap’
    In file included from /usr/include/linux/netdevice.h:28:0,
                     from /usr/include/linux/if_arp.h:26,
                     from mitm.h:10,
                     from create_raw.c:1:
    /usr/include/linux/if.h:142:8: note: originally defined here
    In file included from mitm.h:14:0,
                     from create_raw.c:1:
    /usr/include/net/if.h:126:8: error: redefinition of ‘struct ifreq’
    In file included from /usr/include/linux/netdevice.h:28:0,
                     from /usr/include/linux/if_arp.h:26,
                     from mitm.h:10,
                     from create_raw.c:1:
    /usr/include/linux/if.h:176:8: note: originally defined here
    In file included from mitm.h:14:0,
                     from create_raw.c:1:
    /usr/include/net/if.h:176:8: error: redefinition of ‘struct ifconf’
    In file included from /usr/include/linux/netdevice.h:28:0,
                     from /usr/include/linux/if_arp.h:26,
                     from mitm.h:10,
                     from create_raw.c:1:
    /usr/include/linux/if.h:225:8: note: originally defined here
    In file included from mitm.h:12:0,
                     from get_args.c:1:
    /usr/include/netpacket/packet.h:22:8: error: redefinition of ‘struct sockaddr_ll’
    In file included from /usr/include/linux/netdevice.h:30:0,
                     from /usr/include/linux/if_arp.h:26,
                     from mitm.h:10,
                     from get_args.c:1:
    /usr/include/linux/if_packet.h:12:8: note: originally defined here
    In file included from mitm.h:12:0,
                     from get_args.c:1:
    /usr/include/netpacket/packet.h:51:8: error: redefinition of ‘struct packet_mreq’
    In file included from /usr/include/linux/netdevice.h:30:0,
                     from /usr/include/linux/if_arp.h:26,
                     from mitm.h:10,
                     from get_args.c:1:
    /usr/include/linux/if_packet.h:261:8: note: originally defined here
    In file included from mitm.h:14:0,
                     from get_args.c:1:
    /usr/include/net/if.h:44:5: error: expected identifier before numeric constant
    /usr/include/net/if.h:111:8: error: redefinition of ‘struct ifmap’
    In file included from /usr/include/linux/netdevice.h:28:0,
                     from /usr/include/linux/if_arp.h:26,
                     from mitm.h:10,
                     from get_args.c:1:
    /usr/include/linux/if.h:142:8: note: originally defined here
    In file included from mitm.h:14:0,
                     from get_args.c:1:
    /usr/include/net/if.h:126:8: error: redefinition of ‘struct ifreq’
    In file included from /usr/include/linux/netdevice.h:28:0,
                     from /usr/include/linux/if_arp.h:26,
                     from mitm.h:10,
                     from get_args.c:1:
    /usr/include/linux/if.h:176:8: note: originally defined here
    In file included from mitm.h:14:0,
                     from get_args.c:1:
    /usr/include/net/if.h:176:8: error: redefinition of ‘struct ifconf’
    In file included from /usr/include/linux/netdevice.h:28:0,
                     from /usr/include/linux/if_arp.h:26,
                     from mitm.h:10,
                     from get_args.c:1:
    /usr/include/linux/if.h:225:8: note: originally defined here
    In file included from mitm.h:12:0,
                     from main.c:1:
    /usr/include/netpacket/packet.h:22:8: error: redefinition of ‘struct sockaddr_ll’
    In file included from /usr/include/linux/netdevice.h:30:0,
                     from /usr/include/linux/if_arp.h:26,
                     from mitm.h:10,
                     from main.c:1:
    /usr/include/linux/if_packet.h:12:8: note: originally defined here
    In file included from mitm.h:12:0,
                     from main.c:1:
    /usr/include/netpacket/packet.h:51:8: error: redefinition of ‘struct packet_mreq’
    In file included from /usr/include/linux/netdevice.h:30:0,
                     from /usr/include/linux/if_arp.h:26,
                     from mitm.h:10,
                     from main.c:1:
    /usr/include/linux/if_packet.h:261:8: note: originally defined here
    In file included from mitm.h:14:0,
                     from main.c:1:
    /usr/include/net/if.h:44:5: error: expected identifier before numeric constant
    /usr/include/net/if.h:111:8: error: redefinition of ‘struct ifmap’
    In file included from /usr/include/linux/netdevice.h:28:0,
                     from /usr/include/linux/if_arp.h:26,
                     from mitm.h:10,
                     from main.c:1:
    /usr/include/linux/if.h:142:8: note: originally defined here
    In file included from mitm.h:14:0,
                     from main.c:1:
    /usr/include/net/if.h:126:8: error: redefinition of ‘struct ifreq’
    In file included from /usr/include/linux/netdevice.h:28:0,
                     from /usr/include/linux/if_arp.h:26,
                     from mitm.h:10,
                     from main.c:1:
    /usr/include/linux/if.h:176:8: note: originally defined here
    In file included from mitm.h:14:0,
                     from main.c:1:
    /usr/include/net/if.h:176:8: error: redefinition of ‘struct ifconf’
    In file included from /usr/include/linux/netdevice.h:28:0,
                     from /usr/include/linux/if_arp.h:26,
                     from mitm.h:10,
                     from main.c:1:
    /usr/include/linux/if.h:225:8: note: originally defined here
    codeblox@Lubuntu-pc:~/Programming/C/Network/MITM/src$


    Code:
    #ifndef _MITM_H
    #define _MITM_H
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>
    #include <string.h>
    #include <sys/socket.h>
    #include <errno.h>
    #include <linux/if_arp.h>
    #include <netinet/in.h>
    #include <netpacket/packet.h>
    #include <net/ethernet.h>
    #include <net/if.h>
    #include <sys/ioctl.h>
    
    
    
    void get_args(int argc, char ** argv, char ** host_a_ipstr, char ** host_b_ipstr, char ** iface_name);
    int create_raw(char * iface_name);
    
    
    
    #endif
    #include "mitm.h"
    
    int create_raw(char * iface_name)
    {
      int raw;
      struct ifreq req;
      struct sockaddr_ll sll;
    
      memcpy(req.ifr_name, iface_name, IFNAMSIZ);
    
      if((raw = socket(AF_INET, SOCK_RAW, ETHERTYPE_ARP)) == -1)
        {
    
          fprintf(stderr, "socket: %s\n", strerror(errno));
          exit(-1);
    
        }
    
      if(ioctl(raw, SIOGIFINDEX, &req) == -1)
        {
    
          fprintf(stderr, "ioctl: %s\n", strerror(errno));
          exit(-1);
    
        }
    
      sll.sll_family = AF_PACKET;
      sll.sll_protocol = htons(ETHERTYPE_ARP);
      sll.sll_ifindex = req.ifr_ifindex;
    
      if(bind(raw, (struct sockaddr *)&sll, sizeof(sll)) == -1)
        {
    
          fprintf(stderr, "bind: %s\n", strerror(errno));
          exit(-1);
    
        }  
    
      return raw;
    }
    #include "mitm.h"
    
    void get_args(int argc, char ** argv, char ** host_a_ipstr, char ** host_b_ipstr, char ** iface_name)
    {
    
      int opt;
    
      if(argc == 7)
        {
          while((opt = getopt(argc, argv, "abi")) > 0)
    	{
    	  switch(opt)
    	    {
    	    case 'a':
    	      * host_a_ipstr = argv[optind];
    	      break;
    	    case 'b':
    	      * host_b_ipstr = argv[optind];
    	      break;
    	    case 'i':
    	      * iface_name = argv[optind];
    	      break;
    	    default:
    	      break;
    	    }
    	}
        }
      else
        {
    
          fprintf(stderr, "Usage: %s -a [ipaddr] -b [ipaddr] -i [iface]\n", argv[0]);
      
          exit(-1);
        }
    
    }
    #include "mitm.h"
    
    int main(int argc, char ** argv)
    {
      
      char * host_a_ipstr, * host_b_ipstr, * iface_name;
      
      int raw_sock;
      
    
      get_args(argc, argv, &host_a_ipstr, &host_b_ipstr, &iface_name);
    
      raw_sock = create_raw(iface_name);
      
      
    
      return 0;
    }
    Last edited by Syscal; 09-08-2013 at 08:21 PM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    You should start by removing #include <linux/if_arp.h>
    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
    C lover
    Join Date
    Oct 2007
    Location
    Virginia
    Posts
    266
    Hm... That took care of it O_O But see there is some stuff (Constants really) that I need that are defined in that header. Do you see any issue with taking and defining them in my header file?

  4. #4
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by Syscal View Post
    Do you see any issue with taking and defining them in my header file?
    if they change with subsequent versions of linux, you'll need to update them. that's the only problem I can see.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Constants such as what?

    Any constants you should need should be in the user API.
    If they're in the kernel side implementation, chances are they're private and kernel specific.
    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.

  6. #6
    C lover
    Join Date
    Oct 2007
    Location
    Virginia
    Posts
    266
    The specific ones I want are the ARP OpCodes and the Hardware Identifiers (I guess I could use ETHERTYPE_* instead for those since they share a common number space)

    When you say kernel side implementation, are you talking about the header files in the "/usr/include/linux/" directory?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Errors after compiling
    By CroBoss in forum C++ Programming
    Replies: 3
    Last Post: 06-09-2010, 10:21 AM
  2. Compiling errors
    By courtesan in forum C Programming
    Replies: 2
    Last Post: 08-18-2005, 10:52 AM
  3. Compiling errors again
    By Jessica in forum C++ Programming
    Replies: 2
    Last Post: 04-04-2002, 09:47 AM
  4. compiling errors
    By Jessica in forum C++ Programming
    Replies: 5
    Last Post: 04-03-2002, 08:20 PM