Exemple #1
0
/* net_init:
 *  Initialises the libnet library.
 */
int net_init (void) {
  if (!initialised) {
    initialised = 1;
    
    if (!__libnet_internal__mutex_create)
        net_set_mutex_funcs (NULL, NULL, NULL, NULL);
    if (!__libnet_timer_func)
        net_set_timer_func (NULL);
    __libnet_timer_func();
    
    detected_drivers = net_driverlist_create();
    initialised_drivers = net_driverlist_create();
    temp_detected_list = net_driverlist_create();
    net_drivers_all = net_driverlist_create();

    __libnet_internal__classes_init();
    __libnet_internal__drivers_init();
    __libnet_internal__channels_init();
    __libnet_internal__conns_init();
    
    if (!done_atexit) {
      if (atexit(exitfunc)) {
	exitfunc();
	return 1;
      }
      done_atexit = 1;
    } 
  }
  return 0;
}
Exemple #2
0
/* net_initdrivers:
 *  Initialises the given drivers.  Returns the full list of
 *  successfully initialised drivers.
 */
list_t net_initdrivers (list_t which) {
  list_t temp1, temp2, temp3;
  temp1 = net_driverlist_create();
  temp2 = net_driverlist_create();
  temp3 = net_driverlist_create();

  /* Take a copy of our parameter, because the later call to 
   * `net_detectdrivers' could clobber it. */
  net_driverlist_add_list (temp3, which);
  which = temp3;
  
  /* Find undetected drivers */
  net_driverlist_add_list (temp2, which);
  net_driverlist_remove_list (temp2, detected_drivers);

  /* Try to detect them */
  net_detectdrivers (temp2);

  /* Mask out remaining undetected drivers */
  net_driverlist_add_list (temp2, which);
  net_driverlist_remove_list (temp2, detected_drivers);
  net_driverlist_add_list (temp1, which);
  net_driverlist_remove_list (temp1, temp2);
  
  /* Mask out already-initialised drivers */
  net_driverlist_remove_list (temp1, initialised_drivers);
  
  /* Do initialisation */
  net_driverlist_foreach (temp1, initdrivers_helper, NULL);
  
  net_driverlist_destroy (temp1);
  net_driverlist_destroy (temp2);
  net_driverlist_destroy (temp3);
  return initialised_drivers;
}
Exemple #3
0
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");
}
Exemple #4
0
/* 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);
}
Exemple #5
0
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));
	}
}
Exemple #6
0
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;
}