Exemplo n.º 1
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;
}
Exemplo n.º 2
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);
}
Exemplo n.º 3
0
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;
}
Exemplo n.º 4
0
void get_driver() {
	char buffer[20];
	int choice;
	NET_DRIVERNAME *drivers;
	NET_DRIVERLIST avail;

	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);

	netdriver = choice;
}
Exemplo n.º 5
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;
}
Exemplo n.º 6
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;
}