Example #1
0
File: main.c Project: Agochka/klibc
static void postprocess_device(struct netdev *dev)
{
	if (dev->ip_netmask == INADDR_ANY) {
		dev->ip_netmask = inet_class_netmask(dev->ip_addr);
		printf("IP-Config: %s guessed netmask %s\n",
		       dev->name, my_inet_ntoa(dev->ip_netmask));
	}
	if (dev->ip_broadcast == INADDR_ANY) {
		dev->ip_broadcast =
		    (dev->ip_addr & dev->ip_netmask) | ~dev->ip_netmask;
		printf("IP-Config: %s guessed broadcast address %s\n",
		       dev->name, my_inet_ntoa(dev->ip_broadcast));
	}
}
Example #2
0
File: main.c Project: Agochka/klibc
static void dump_device_config(struct netdev *dev)
{
	char fn[40];
	FILE *f;

	snprintf(fn, sizeof(fn), "/tmp/net-%s.conf", dev->name);
	f = fopen(fn, "w");
	if (f) {
		write_option(f, "DEVICE", dev->name);
		write_option(f, "IPV4ADDR",
				my_inet_ntoa(dev->ip_addr));
		write_option(f, "IPV4BROADCAST",
				my_inet_ntoa(dev->ip_broadcast));
		write_option(f, "IPV4NETMASK",
				my_inet_ntoa(dev->ip_netmask));
		write_option(f, "IPV4GATEWAY",
				my_inet_ntoa(dev->ip_gateway));
		write_option(f, "IPV4DNS0",
				my_inet_ntoa(dev->ip_nameserver[0]));
		write_option(f, "IPV4DNS1",
				my_inet_ntoa(dev->ip_nameserver[1]));
		write_option(f, "HOSTNAME",  dev->hostname);
		write_option(f, "DNSDOMAIN", dev->dnsdomainname);
		write_option(f, "NISDOMAIN", dev->nisdomainname);
		write_option(f, "ROOTSERVER",
				my_inet_ntoa(dev->ip_server));
		write_option(f, "ROOTPATH", dev->bootpath);
		write_option(f, "filename", dev->filename);
		fclose(f);
	}
}
Example #3
0
static void hugsprim_my_inet_ntoa_6(HugsStackPtr hugs_root)
{
    HsWord32 arg1;
    HsPtr res1;
    arg1 = hugs->getWord32();
    res1 = my_inet_ntoa(arg1);
    hugs->putPtr(res1);
    hugs->returnIO(hugs_root,1);
}
Example #4
0
File: main.c Project: Agochka/klibc
static void print_device_config(struct netdev *dev)
{
	printf("IP-Config: %s complete (from %s):\n", dev->name,
	       my_inet_ntoa(dev->serverid ? dev->serverid : dev->ip_server));
	printf(" address: %-16s ", my_inet_ntoa(dev->ip_addr));
	printf("broadcast: %-16s ", my_inet_ntoa(dev->ip_broadcast));
	printf("netmask: %-16s\n", my_inet_ntoa(dev->ip_netmask));
	printf(" gateway: %-16s ", my_inet_ntoa(dev->ip_gateway));
	printf("dns0     : %-16s ", my_inet_ntoa(dev->ip_nameserver[0]));
	printf("dns1   : %-16s\n", my_inet_ntoa(dev->ip_nameserver[1]));
	if (dev->hostname[0])
		printf(" host   : %-64s\n", dev->hostname);
	if (dev->dnsdomainname[0])
		printf(" domain : %-64s\n", dev->dnsdomainname);
	if (dev->nisdomainname[0])
		printf(" nisdomain: %-64s\n", dev->nisdomainname);
	printf(" rootserver: %s ", my_inet_ntoa(dev->ip_server));
	printf("rootpath: %s\n", dev->bootpath);
	printf(" filename  : %s\n", dev->filename);
}
Example #5
0
static void sh_utmp_addlogin (struct SH_UTMP_S * ut)
{
  struct log_user   * user     = userlist;
  struct log_user   * userold  = userlist;
#ifdef HAVE_UTTYPE  
  struct log_user   * username = userlist;
#endif

  char   ttt[TIM_MAX];
#ifdef HAVE_UTTYPE
  volatile int    status;
#endif

  SL_ENTER(_("sh_utmp_addlogin"));

  if (ut->ut_line[0] == '\0')
    SL_RET0(_("sh_utmp_addlogin"));

  /* for some stupid reason, AIX repeats the wtmp entry for logouts
   * with ssh
   */
  if (memcmp (&save_utmp, ut, sizeof(struct SH_UTMP_S)) == 0)
    {
      memset(&save_utmp, (int) '\0', sizeof(struct SH_UTMP_S));
      SL_RET0(_("sh_utmp_addlogin"));
    }
  memcpy (&save_utmp, ut, sizeof(struct SH_UTMP_S));

  /* Take the address to keep gcc from putting them into registers. 
   * Avoids the 'clobbered by longjmp' warning. 
   */
  sh_dummy_userold = (void*) &userold;
  sh_dummy_user    = (void*) &user;

  /* ------- find user -------- 
   */
  while (user != NULL) 
    {
      if (0 == sl_strncmp((char*)(user->ut_tty), ut->ut_line, UT_LINESIZE) ) 
	break;
      userold = user;
      user = user->next;
    }

#ifdef HAVE_UTTYPE  
  while (username != NULL) 
    {
      if (0 == sl_strncmp(username->name, ut->ut_name, UT_NAMESIZE) ) 
	break;
      username = username->next;
    }
#endif
  
#ifdef HAVE_UTTYPE  
  /* ---------- LOGIN -------------- */
  if (ut->ut_type == USER_PROCESS) 
    {
      if (user == NULL)
	{
	  user = SH_ALLOC(sizeof(struct log_user));
	  user->next       = userlist;
	  userlist         = (struct log_user *) user;
	}
      (void) sl_strlcpy((char*)(user->ut_tty),  ut->ut_line, UT_LINESIZE+1);
      (void) sl_strlcpy((char*)(user->name),    ut->ut_name, UT_NAMESIZE+1);
#ifdef HAVE_UTHOST
      (void) sl_strlcpy((char*)(user->ut_host), ut->ut_host, UT_HOSTSIZE+1);
#else
      user->ut_host[0] = '\0';
#endif
#ifdef HAVE_UTADDR
#ifdef HAVE_UTADDR_V6
      my_inet_ntoa(ut->ut_addr_v6, user->ut_ship, SH_IP_BUF);
#else
      my_inet_ntoa(ut->ut_addr, user->ut_ship, SH_IP_BUF);
#endif
#endif
      user->time = ut->ut_time;

      if (username == NULL                              /* not yet logged in */
          || 0 == sl_strncmp(ut->ut_line, _("ttyp"), 4) /* in virt. console  */
          || 0 == sl_strncmp(ut->ut_line, _("ttyq"), 4) /* in virt. console  */
	  ) {
	status = sh_utmp_login_a((char*)user->name);
	SH_MUTEX_LOCK(mutex_thread_nolog);
	(void) sh_unix_time (user->time, ttt, TIM_MAX);
	sh_error_handle( ShUtmpLoginSolo, FIL__, __LINE__, 0,
#if defined(HAVE_UTHOST) && defined(HAVE_UTADDR)
			 MSG_UT_LG1X,
#elif defined(HAVE_UTHOST)
			 MSG_UT_LG1A,
#else
			 MSG_UT_LG1B,
#endif
			 user->name,
			 user->ut_tty,
#if defined(HAVE_UTHOST) && defined(HAVE_UTADDR)
			 user->ut_host,
			 user->ut_ship,
#elif defined(HAVE_UTHOST)
			 user->ut_host,
#endif
			 ttt,
			 status
			 );
	SH_MUTEX_UNLOCK(mutex_thread_nolog);
      } else
	if (0 == sh_utmp_is_virtual(ut->ut_line, (char*)user->ut_host))
	  {       
	    status = sh_utmp_login_a((char*)user->name);
	    SH_MUTEX_LOCK(mutex_thread_nolog);
	    (void) sh_unix_time (user->time, ttt, TIM_MAX);
	    sh_error_handle( ShUtmpLoginMulti, FIL__, __LINE__, 0,
#if defined(HAVE_UTHOST) && defined(HAVE_UTADDR)
			     MSG_UT_LG2X,
#elif defined(HAVE_UTHOST)
			     MSG_UT_LG2A,
#else
			     MSG_UT_LG2B,
#endif
			     user->name,
			     user->ut_tty,
#if defined(HAVE_UTHOST) && defined(HAVE_UTADDR)
			     user->ut_host,
			     user->ut_ship,
#elif defined(HAVE_UTHOST)
			     user->ut_host,
#endif
			     ttt,
			     status
			     );
	    SH_MUTEX_UNLOCK(mutex_thread_nolog);
	  }
      
      sh_utmp_login_morechecks(ut);
      goto out;
    }


  /* ---------  LOGOUT ---------------- */
  else if (ut->ut_name[0] == '\0'
	   || ut->ut_type == DEAD_PROCESS  /* solaris does not clear ut_name */
	   )
    {
      if (user != NULL)
	{
#if defined(__linux__)
	  if (0 == sh_utmp_is_virtual(ut->ut_line, (char*)user->ut_host)) {
#endif
	    status = sh_utmp_login_r((char*)user->name);
	    SH_MUTEX_LOCK(mutex_thread_nolog);
	    (void) sh_unix_time (ut->ut_time, ttt, TIM_MAX);
	    sh_error_handle( ShUtmpLogout, FIL__, __LINE__, 0,
#if defined(HAVE_UTHOST) && defined(HAVE_UTADDR)
			     MSG_UT_LG3X,
#elif defined(HAVE_UTHOST)
			     MSG_UT_LG3A,
#else
			     MSG_UT_LG3B,
#endif
			     user->name,
			     user->ut_tty,
#if defined(HAVE_UTHOST) && defined(HAVE_UTADDR)
			     user->ut_host,
			     user->ut_ship,
#elif defined(HAVE_UTHOST)
			     user->ut_host,
#endif
			     ttt,
			     status
			     );
	    SH_MUTEX_UNLOCK(mutex_thread_nolog);
	    userold->next = user->next;
	    if (user == userlist)
	      userlist = user->next;
	    sh_utmp_logout_morechecks((struct log_user *)user);
	    SH_FREE((struct log_user *)user);
	    user = NULL;
#if defined(__linux__)
	  }
#endif
	}
      else
	{
	  (void) sl_strlcpy(terminated_line, ut->ut_line, UT_HOSTSIZE);
	  SH_MUTEX_LOCK(mutex_thread_nolog);
	  (void) sh_unix_time (ut->ut_time, ttt, TIM_MAX);
	  sh_error_handle( ShUtmpLogout, FIL__, __LINE__, 0,
			   MSG_UT_LG3C,
			   terminated_line,
			   ttt, 0
			   );
	  SH_MUTEX_UNLOCK(mutex_thread_nolog);
	}
      goto out;
    }

  /* default */
  goto out;

  /* #ifdef HAVE_UTTYPE                   */
#else

  if (user == NULL)   /* probably a login */
    {
      user = SH_ALLOC(sizeof(struct log_user));
      sl_strlcpy(user->ut_tty,  ut->ut_line, UT_LINESIZE+1);
      sl_strlcpy(user->name,    ut->ut_name, UT_NAMESIZE+1);
#ifdef HAVE_UTHOST
      sl_strlcpy(user->ut_host, ut->ut_host, UT_HOSTSIZE+1);
#endif
#ifdef HAVE_UTADDR
#ifdef HAVE_UTADDR_V6
      my_inet_ntoa(ut->ut_addr_v6, user->ut_ship, SH_IP_BUF);
#else
      my_inet_ntoa(ut->ut_addr, user->ut_ship, SH_IP_BUF);
#endif
#endif
      user->time       = ut->ut_time;
      user->next       = userlist;
      userlist         = user;

      SH_MUTEX_LOCK(mutex_thread_nolog);
      (void) sh_unix_time (user->time, ttt, TIM_MAX);
      sh_error_handle( ShUtmpLoginSolo, FIL__, __LINE__, 0,
#if defined(HAVE_UTHOST) && defined(HAVE_UTADDR)
		       MSG_UT_LG1X,
#elif defined(HAVE_UTHOST)
		       MSG_UT_LG1A,
#else
		       MSG_UT_LG1B,
#endif
		       user->name,
		       user->ut_tty,
#if defined(HAVE_UTHOST) && defined(HAVE_UTADDR)
		       user->ut_host,
		       user->ut_ship,
#elif defined(HAVE_UTHOST)
		       user->ut_host,
#endif
		       ttt,
		       1
		       );
      SH_MUTEX_UNLOCK(mutex_thread_nolog);
      sh_utmp_login_morechecks(ut);
    }
  else  /* probably a logout */
    {
      SH_MUTEX_LOCK(mutex_thread_nolog);
      (void) sh_unix_time (ut->ut_time, ttt, TIM_MAX);
      sh_error_handle( ShUtmpLogout, FIL__, __LINE__, 0,
#if defined(HAVE_UTHOST) && defined(HAVE_UTADDR)
		       MSG_UT_LG2X,
#elif defined(HAVE_UTHOST)
		       MSG_UT_LG2A,
#else
		       MSG_UT_LG2B,
#endif
		       user->name,
		       user->ut_tty,
#if defined(HAVE_UTHOST) && defined(HAVE_UTADDR)
		       user->ut_host,
		       user->ut_ship,
#elif defined(HAVE_UTHOST)
		       user->ut_host,
#endif
		       ttt,
		       1
		       );
      SH_MUTEX_UNLOCK(mutex_thread_nolog);
      sh_utmp_logout_morechecks(user);
      userold->next = user->next;
      if (user == userlist)       /* inserted Apr 4, 2004 */
	userlist = user->next;
      SH_FREE(user);
      user = NULL;
    }

#endif

 out:
  sh_dummy_user    = NULL;
  sh_dummy_userold = NULL;

  SL_RET0(_("sh_utmp_addlogin"));
}