Example #1
0
static int detectdrivers_helper (int i, void *dat)
{
  NET_DRIVER *driver = __libnet_internal__get_driver (i);
  if (driver && (driver->detect())) {
    net_driverlist_add (detected_drivers, i);
    net_driverlist_add (temp_detected_list, i);
  }
  return 0;
}
Example #2
0
static int initdrivers_helper (int i, void *dat)
{
  NET_DRIVER *driver = __libnet_internal__get_driver (i);
  if (driver && (!driver->init()))
    net_driverlist_add (initialised_drivers, i);
  return 0;
}
Example #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");
}
Example #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);
}
Example #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));
	}
}
Example #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;
}
Example #7
0
static int add_helper (int driver, void *dat)
  { return !net_driverlist_add (dat, driver); }