Subject: storage size of ifr6 isn't know

From: "Su Po-chou" <[email-masked]>
Date: Sat, 16 Aug 2003 01:08:02 +0800

Hi all,
          I wrote a program which want to show my ipv6 addr, but it does work.
          Could there anyone can give me some suggestions?   Thanks.

                 When I compile my code, it will show       
  
                 [root@localhost else]# gcc -o ipmac ipmac.c
                 ipmac.c: In function `main':
                 ipmac.c:33: storage size of `ifr6' isn't known
                 [root@localhost else]#

Below is my source code.

#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <net/if.h>
#include <net/if_arp.h>
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <netdb.h>

char iface[] = "eth1";
int
main (int argc, char **argv)
{
  int s;
  char mac[6];
  char ip[12];
  struct sockaddr_in6 sa6;
  struct in6_ifreq ifr6;
  unsigned long prefix_len;

  s = socket (AF_INET6, SOCK_STREAM, 0);
  if (s < 0)
    {
      printf ("socket screwup\n");
      exit (1);
    }
  
memset(&ifr6, 0, sizeof(ifr6));
strncpy(ifr6.ifr_name, iface, sizeof(ifr6.ifr_name));
 
memcpy((char *) &ifr6.ifr6_addr, (char *) &sa6.sin6_addr,
      sizeof(struct in6_addr));
  
  if (ioctl (s, SIOCDIFADDR, &ifr6) < 0)
    printf ("ip screwed up\n");

  /* then printf the addr */

  return 0;
}