/* * Called from openlog() to allocate print-buffer and * optionally open a file. If file == NULL, print to stderr. */ int _printk_init (int size, const char *file) { if (!printk_buf) { printk_ptr = printk_buf = (char*) malloc (size); if (!printk_ptr) { fprintf (stderr, "_printk_init: allocation failed\n"); return (0); } } #if defined(WIN32) _printk_file = stderr; #endif if (file && (_printk_file = fopen(file,"wt")) == NULL) { fprintf (stderr, "_printk_init: cannot open `%s'\n", file); return (0); } printk_end = printk_ptr + size; RUNDOWN_ADD (printk_exit, 300); return (1); }
/** * Initialize config-hook for TFTP protocol. */ int tftp_init (void) { prev_hook = usr_init; usr_init = tftp_cfg_hook; RUNDOWN_ADD (tftp_exit, 261); return (TRUE); }
void res_init0 (void) { prev_hook = usr_init; usr_init = resolver_init; RUNDOWN_ADD (res_exit, 200); }
void ReadHostsFile (const char *fname) { static BOOL been_here = FALSE; if (!fname || !*fname) return; if (been_here) /* loading multiple hosts files */ { free (hostFname); fclose (hostFile); hostFile = NULL; } hostFname = strdup (fname); if (!hostFname) return; sethostent (1); if (!hostFile) return; been_here = TRUE; while (1) { struct hostent *h = gethostent(); struct _hostent *h2; int i; if (!h) break; h2 = (struct _hostent*) calloc (sizeof(*h2), 1); if (!h2) { outs (hostFname); outsnl (_LANG(" too big!")); break; } for (i = 0; h->h_aliases[i]; i++) h2->h_aliases[i] = strdup (h->h_aliases[i]); h2->h_name = strdup (h->h_name); h2->h_address[0] = *(DWORD*) h->h_addr_list[0]; h2->h_num_addr = 1; if (!h2->h_name) break; h2->h_next = host0; host0 = h2; } #if 0 /* test !! */ { const struct _hostent *h; int i; printf ("\n%s entries:\n", hostFname); for (h = host0; h; h = h->h_next) { printf ("address = %-17.17s name = %-30.30s Aliases:", inet_ntoa(*(struct in_addr*)&h->h_address[0]), h->h_name); for (i = 0; h->h_aliases[i]; i++) printf (" %s,", h->h_aliases[i]); puts (""); } fflush (stdout); } #endif rewind (hostFile); RUNDOWN_ADD (endhostent, 254); }
void ReadNetworksFile (const char *fname) { static BOOL been_here = FALSE; if (!fname || !*fname) return; if (been_here) /* loading multiple network files */ { free (networkFname); fclose (networkFile); networkFile = NULL; } networkFname = strdup (fname); if (!networkFname) return; setnetent (1); if (!networkFile) return; been_here = TRUE; while (1) { struct netent *n = getnetent(); struct _netent *n2; int i; if (!n) break; n2 = (struct _netent*) calloc (sizeof(*n2), 1); if (!n2) { outs (networkFname); outsnl (_LANG(" too big!")); break; } for (i = 0; n->n_aliases[i]; i++) n2->n_aliases[i] = strdup (n->n_aliases[i]); n2->n_net = n->n_net; n2->n_addrtype = n->n_addrtype; n2->n_name = strdup (n->n_name); if (!n2->n_name) break; n2->n_next = network0; network0 = n2; } rewind (networkFile); RUNDOWN_ADD (endnetent, 251); #if 0 /* test */ { struct _netent *n; printf ("\n%s entries:\n", networkFname); for (n = network0; n; n = n->n_next) { int i; printf ("net %-15.15s name %-10.10s Aliases:", inet_ntoa(inet_makeaddr(n->n_net,0)), n->n_name); for (i = 0; n->n_aliases[i]; i++) printf (" %s,", n->n_aliases[i]); puts (""); } fflush (stdout); } #endif }
/** * Initialize the network driver interface. * \return 0 okay. * \return error-code otherwise. */ int _eth_init (void) { int rc; SIO_TRACE (("_eth_init")); if (_eth_is_init) return (0); rc = pkt_eth_init (&_eth_addr); if (rc) return (rc); /* error message already printed */ /* Save our MAC-address incase we change it. Change back at exit. */ memcpy (_eth_real_addr, _eth_addr, sizeof(_eth_real_addr)); switch (_pktdevclass) { case PDCLASS_ETHER: mac_tx_format = eth_mac_format; mac_transmit = eth_mac_xmit; break; case PDCLASS_TOKEN: case PDCLASS_TOKEN_RIF: mac_tx_format = tok_mac_format; mac_transmit = tok_mac_xmit; break; case PDCLASS_FDDI: mac_tx_format = fddi_mac_format; mac_transmit = fddi_mac_xmit; break; case PDCLASS_ARCNET: mac_tx_format = arcnet_mac_format; mac_transmit = arcnet_mac_xmit; break; case PDCLASS_SLIP: case PDCLASS_PPP: case PDCLASS_AX25: /* !! for now */ mac_tx_format = null_mac_format; mac_transmit = null_mac_xmit; break; default: outsnl (_LANG("No supported driver class found")); return (WERR_NO_DRIVER); } memset (TX_BUF(), 0, sizeof(union link_Packet)); memset (&_eth_brdcast, 0xFF, sizeof(_eth_brdcast)); _eth_loop_addr[0] = 0xCF; pkt_buf_wipe(); if (!_eth_get_hwtype(NULL, &_eth_mac_len)) _eth_mac_len = sizeof(eth_address); if (!strcmp(_pktdrvrname,"NDIS3PKT")) _eth_ndis3pkt = TRUE; else if (!strcmp(_pktdrvrname,"SwsVpkt")) _eth_SwsVpkt = TRUE; _eth_is_init = TRUE; RUNDOWN_ADD (_eth_release, 10); return (0); /* everything okay */ }