struct net_data *
net_data_create(const char *conf_file) {
	struct net_data *net_data;

	net_data = memget(sizeof (struct net_data));
	if (net_data == NULL)
		return (NULL);
	memset(net_data, 0, sizeof (struct net_data));

	if ((net_data->irs = irs_gen_acc("", conf_file)) == NULL) {
		memput(net_data, sizeof (struct net_data));
		return (NULL);
	}
#ifndef DO_PTHREADS
	(*net_data->irs->res_set)(net_data->irs, &_res, NULL);
#endif

	net_data->res = (*net_data->irs->res_get)(net_data->irs);
	if (net_data->res == NULL) {
		(*net_data->irs->close)(net_data->irs);
		memput(net_data, sizeof (struct net_data));
		return (NULL);
	}

	if ((net_data->res->options & RES_INIT) == 0U &&
	    res_ninit(net_data->res) == -1) {
		(*net_data->irs->close)(net_data->irs);
		memput(net_data, sizeof (struct net_data));
		return (NULL);
	}

	return (net_data);
}
示例#2
0
static struct addrlist *
getwire_lookup(u_long address, u_long netmask, int ishost)
{
  struct addrlist *al;
  u_long subnet;
  char netNumberBuf[64];
  char buf[GFBUFLEN], *s;
#ifdef HAVE_IRS_H
  struct nwent *np;
#else /* not HAVE_IRS_H */
  struct netent *np;
#endif /* not HAVE_IRS_H */

  /*
   * Add interface to local network singly linked list
   */
  al = ALLOC(struct addrlist);
  al->ip_addr = address;
  al->ip_mask = netmask;
  al->ip_net_name = NO_SUBNET; /* fill in a bit later */
  al->ip_net_num = "0.0.0.0"; /* fill in a bit later */
  al->ip_next = NULL;

  subnet = ntohl(address) & ntohl(netmask);

  if (ishost)
    np = NULL;
  else {
#ifdef HAVE_IRS_H
    u_long mask = ntohl(netmask);
    static struct irs_acc *irs_gen;
    static struct irs_nw *irs_nw;
    u_long net;
    int maskbits;
    u_char addr[4];

    if (irs_gen == NULL)
#ifdef irs_irp_acc
      /*
       * bsdi4 added another argument to this function, without changing
       * its name.  The irs_irp_acc is the one (hacky) distinguishing
       * feature found in <irs.h> that can differentiate between bsdi3 and
       * bsdi4.
       */
      irs_gen = irs_gen_acc("", NULL);
#else /* not irs_irp_acc */
      irs_gen = irs_gen_acc("");
#endif /* not irs_irp_acc */
    if (irs_gen && irs_nw == NULL)
      irs_nw = (*irs_gen->nw_map)(irs_gen);
    net = ntohl(address) & (mask = ntohl(netmask));
    addr[0] = (0xFF000000 & net) >> 24;
    addr[1] = (0x00FF0000 & net) >> 16;
    addr[2] = (0x0000FF00 & net) >> 8;
    addr[3] = (0x000000FF & net);
    for (maskbits = 32; !(mask & 1); mask >>= 1)
      maskbits--;
    np = (*irs_nw->byaddr)(irs_nw, addr, maskbits, AF_INET);
#else /* not HAVE_IRS_H */
    np = getnetbyaddr(subnet, AF_INET);
    /*
     * Some systems (IRIX 6.4) cannot getnetbyaddr on networks such as
     * "128.59.16.0".  Instead, they need to look for the short form of
     * the network, "128.59.16".  So if the first getnetbyaddr failed, we
     * shift the subnet way from zeros and try again.
     */
    if (!np) {
      u_long short_subnet = subnet;
      while (short_subnet && (short_subnet & 0x000000ff) == 0)
	short_subnet >>= 8;
      np = getnetbyaddr(short_subnet, AF_INET);
      if (np)
	plog(XLOG_WARNING, "getnetbyaddr failed on 0x%x, succeeded on 0x%x",
	     (u_int) subnet, (u_int) short_subnet);
    }
#endif /* not HAVE_IRS_H */
  }