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_initdriver: * Initialises a single driver. Returns non-zero on success. */ int net_initdriver (int which) { list_t temp, inited; temp = net_driverlist_create(); net_driverlist_clear(temp); net_driverlist_add (temp, which); inited = net_initdrivers (temp); net_driverlist_destroy (temp); return net_driverlist_test (inited, 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)); } }
int init_client(int argc, char *argv[]){ net_init (); /*net_loadconfig (NULL);*/ net_detectdrivers (net_drivers_all); net_initdrivers (net_drivers_all); /* Set up Proc Mask + SININT hook */ init_SIGCHLD_hook(); /* Parse the input */ if ( b_parser(argc,argv) == ERROR ){ printf("# Bad parameters! \n"); return ERROR; }/*if*/ return OK; }
int main (void) { NET_DRIVERNAME *drivers; char buffer[NET_MAX_ADDRESS_LENGTH], buffer2[NET_MAX_ADDRESS_LENGTH]; char *ch; int not_ok, x, choice; NET_DRIVERLIST avail; net_init(); net_loadconfig (NULL); printf ("Detecting available drivers...\n"); avail = net_detectdrivers (net_drivers_all); printf ("Getting detected driver names...\n"); drivers = net_getdrivernames (avail); do { list_drivers (drivers, "Available drivers"); printf ("Please choose a driver from the above list.\n"); fgets (buffer, 10, stdin); choice = atoi (buffer); } while (!in_list (drivers, choice)); free (drivers); avail = net_driverlist_create(); net_driverlist_add (avail, choice); if (!net_initdrivers (avail)) { printf("Error initialising driver.\n"); exit (1); } do { printf ("Enter address to prepare:\n"); fgets (buffer, sizeof buffer, stdin); if (feof (stdin)) break; ch = strchr (buffer, '\n'); if (!ch) { printf ("Too long for this lame program...\n"); while (1) { char ch = getchar(); if (ch == EOF || ch == '\n') break; } } else { NET_PREPADDR_DATA *data; *ch = '\0'; printf ("Converting...\n"); data = net_prepareaddress (choice, buffer, buffer2); if (!data) { printf ("Failed to initiate\n"); } else { int x; printf ("Waiting..."); do { printf ("."); fflush(stdout); sleep (1); x = net_poll_prepareaddress (data); } while (!x); printf ("\n"); if (x < 0) { printf ("Failed to convert address\n"); } else { printf ("%s => %s\n", buffer, buffer2); } } } } while (!feof (stdin)); printf ("Quitting...\n"); return 0; }
int main (int argc, char **argv) { NET_CONN *listen, *conn = NULL; NET_CHANNEL *chan; char remote[NET_MAX_ADDRESS_LENGTH], buf[NET_MAX_ADDRESS_LENGTH]; char *p, c; int server = -1; if (argc > 1) { if (!strcmp (argv[1], "server")) server = 1; else if (!strcmp (argv[1], "client")) server = 0; } if (server == -1) { puts ("Pass `server' or `client' on the command line."); return 1; } net_init(); net_detectdrivers(net_drivers_all); net_initdrivers(net_drivers_all); if (server) { listen = net_openconn(DRIVER, ""); net_listen(listen); while (!conn) conn = net_poll_listen(listen); } else { conn = net_openconn(DRIVER, NULL); if (net_connect_wait_time(conn, ADDRESS, 5) != 0) { printf("Error connecting\n"); return 1; } } chan = net_openchannel(DRIVER, NULL); p = net_getlocaladdress(chan); net_send_rdm(conn, p, strlen(p) + 1); while (!net_query_rdm(conn)) ; net_receive_rdm(conn, remote, sizeof remote); printf ("Address before fixing: %s\n", remote); if (net_fixupaddress_conn(conn, remote, buf) != 0) { printf("Didn't work\n"); return 1; } printf ("Address after fixing: %s\n", buf); printf("assigning target: %s\n", buf); net_assigntarget(chan, buf); do { c = fgetc(stdin); if (c == '1') net_send(chan, "** Channel", 11); else if (c == '2') net_send_rdm(conn, "** Conn", 8); while (net_query(chan)) { net_receive(chan, buf, sizeof buf, NULL); printf("%s\n", buf); } while (net_query_rdm(conn)) { net_receive_rdm(conn, buf, sizeof buf); printf("%s\n", buf); } } while (c != 'q'); return 0; }