I encountered a strange problem with this simple program.
When I run it under kernel 2.1.11* it simply works.. no problem.
But if I run it under kernel 2.0.35, there is a strange fact i can't explain.
If I comment "bzero(&ifr sizeof(struct ifreq));", it works, but if I uncomment
this line, it outputs a wrong IP.

My system is a Pentium 90, Libc-5.4.44, gcc-2.7.2.1
Have I mentionned enough properties of my system?
If yes, Could someone explain to me where is the problem?

-------------------------------
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <netinet/in.h>

main(int argc, char *argv[])
{
  struct ifreq ifr;
  struct sockaddr_in isa;
  int sockfd;
  
  sockfd=socket(AF_INET, SOCK_RAW, 255);
/* Just try to uncomment the following line */
/*  bzero(&ifr, sizeof(struct ifreq)); */
  strcpy(ifr.ifr_name, argv[1]);
  if (ioctl(sockfd, SIOCGIFADDR, &ifr) < 0) {
    perror("ioctl()");
    exit(0);
  }
  bcopy(&ifr.ifr_addr, &isa, sizeof(struct sockaddr_in));
  printf("Address: %s\n", inet_ntoa(isa.sin_addr.s_addr));
  close(sockfd);
}
-----------------

Reply via email to