list_t net_driverlist_create (void) { list_t list = malloc (sizeof (*list)); if (list) net_driverlist_clear (list); return list; }
void init() { char temp[1024], nick[1024], addr[1024], newaddr[NET_MAX_ADDRESS_LENGTH]; NET_DRIVERLIST drv; drv = net_driverlist_create(); net_driverlist_clear (drv); net_driverlist_add (drv, netdriver); if (!net_initdrivers (drv)) { printf("Error initialising driver.\n"); exit (1); } printf ("Enter target address: "); fgets (addr, 1024, stdin); while (strchr(addr,'\n')) *strchr(addr,'\n')=0; printf ("Enter nickname: "); fgets (nick, 10, stdin); while (strchr(nick,'\n')) *strchr(nick,'\n')=0; if (!(chan = net_openchannel (netdriver, NULL))) { printf ("Unable to open channel.\n"); exit (2); } printf ("Connecting to %s...\n", addr); net_assigntarget (chan, addr); sprintf (temp, "%c%s", CHAT_MAGIC, nick); net_send (chan, temp, strlen (temp)); while ((!net_query (chan))/* && !conio_kbhit()*/); if (0/*conio_kbhit()*/) { conio_getch(); printf ("Aborted.\n"); exit (3); } { int x = net_receive (chan, temp, 1024, newaddr); if (x == -1) { printf ("Receive error.\n"); exit (5); } temp[x] = 0; } if (strcmp (temp, "OK")) { printf ("Connection refused.\n"); exit (4); } printf ("Connection accepted, redirecting... "); fflush (stdout); net_assigntarget (chan, newaddr); printf ("done.\n"); }
/* net_detectdriver: * Attempts to detect a single driver; returns non-zero if detected. */ int net_detectdriver (int which) { list_t temp, detected; temp = net_driverlist_create(); net_driverlist_clear(temp); net_driverlist_add (temp, which); detected = net_detectdrivers (temp); net_driverlist_destroy (temp); return net_driverlist_test (detected, which); }
void init (void) { char nick[1024], addr[1024]; NET_DRIVERLIST drv; int x; drv = net_driverlist_create(); net_driverlist_clear (drv); net_driverlist_add (drv, netdriver); if (!net_initdrivers (drv)) { printf("Error initialising driver.\n"); exit (1); } printf ("Enter target address: "); fgets (addr, 1024, stdin); while (strchr(addr,'\n')) *strchr(addr,'\n')=0; printf ("Enter nickname: "); fgets (nick, 10, stdin); while (strchr(nick,'\n')) *strchr(nick,'\n')=0; if (!(conn = net_openconn (netdriver, NULL))) { printf ("Unable to open conn.\n"); exit (2); } printf ("Connecting to %s ", addr); fflush (stdout); x = net_connect_wait_cb (conn, addr, callback); if (x) { if (x > 0) puts (" -- user aborted."); else puts (" -- error occured."); net_closeconn (conn); exit (3); } puts (" -- connected."); { char buffer[100]; sprintf (buffer, "/nick %s", nick); net_send_rdm (conn, buffer, strlen (buffer)); } }
/* net_detectdrivers: * Attempts to detect each given driver; returns a list showing which * of those specified was detected. */ list_t net_detectdrivers (list_t which) { net_driverlist_clear (temp_detected_list); net_driverlist_foreach (which, detectdrivers_helper, NULL); return temp_detected_list; }
/* exit_all_drivers: (internal) * Shuts down all network drivers. */ static void exit_all_drivers (void) { net_driverlist_foreach (initialised_drivers, exit_all_drivers_helper, NULL); net_driverlist_clear (initialised_drivers); }