Subject: ifconfig and inet
To: None <netbsd-users@netbsd.org>
From: Patrick Welche <prlw1@newn.cam.ac.uk>
List: netbsd-users
Date: 07/30/2002 12:30:52
I may have missed something, but what? I ifconfig fxp0 inet 0.0.0.0, then
run the program below. ifconfig -a now no longer shows an inet line for
fxp0, yet the interface works (can ssh in), so the program must have worked
and set the interface. ifconfig -a not showing it makes me wonder if I 
missed something anyway. Thoughts?

Cheers,

Patrick


#include <sys/ioctl.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <net/if.h>

#include <err.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

int main()
{
  int s;
  struct ifreq ifr;
  struct sockaddr_in *sin;

  s=socket(PF_INET,SOCK_DGRAM,0);
  strncpy(ifr.ifr_name,"fxp0",sizeof(ifr.ifr_name));
  sin=(struct sockaddr_in*)&ifr.ifr_addr;
  sin->sin_family=AF_INET;
  if(inet_pton(AF_INET,"192.168.4.21",&sin->sin_addr)<0)err(1,NULL);
  printf("%s: %s\n",ifr.ifr_name,inet_ntoa(sin->sin_addr));
  if(ioctl(s,SIOCSIFADDR,&ifr)<0)err(1,"SIOCSIFADDR");
  if(ioctl(s,SIOCGIFADDR,&ifr)<0)err(1,"SIOCGIFADDR");
  printf("%s\n",inet_ntoa(sin->sin_addr));
  close(s);

  return 0;
}