コード例 #1
0
ファイル: ip.cpp プロジェクト: Bonfi96/godot
Array IP::_get_local_addresses() const {

	Array addresses;
	List<IP_Address> ip_addresses;
	get_local_addresses(&ip_addresses);
	for (List<IP_Address>::Element *E = ip_addresses.front(); E; E = E->next()) {
		addresses.push_back(E->get());
	}

	return addresses;
}
コード例 #2
0
ファイル: plaunch.c プロジェクト: jhorey/SpotHadoop
/**
 * Main function. 
 */
int main (int argc, char *argv[])
{
  char name[50];
  char* ips[15];
  char* labels[15];
  int num;
  int rank,nprocs,nid;
  MPI_Status status;
  cargs_t *arg;

  // Parse all the arguments. 
  cargs_t* *cargs = parse_args(argc, argv);

  // Initialize the MPI libs. 
  MPI_Init(&argc, &argv);
  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  MPI_Comm_size(MPI_COMM_WORLD, &nprocs);

  // Does the user need help? 
  if( (arg = contains_arg(cargs, "help") ) != NULL ) {
    print_help();
  }

  // Do we need to generate local information?
  if( (arg = contains_arg(cargs, "local") ) != NULL ) {
    // Get local information.
    get_local_name(name, sizeof(name));
    export_host(name);
    num = get_local_addresses(rank, ips, labels);

    // Output local information. 
    export_local_addresses(ips, labels, num);

    // Where to put the information? 
    char *dir = "/tmp/network";
    if(arg->value != NULL) {
      dir = strtok(arg->value, " ");
    }

    output_local_hosts(name, ips, labels, num, dir);
  }

  arg = NULL;
  if( (arg = contains_arg(cargs, "global") ) != NULL ) {
    // Do we need to generate global information? 
    char* hosts = collect_global_hosts(nprocs);

    // Where to put the information? 
    char *dir = "/tmp/hosts.txt";
    if(arg->value != NULL) {      
      dir = strtok(arg->value, " ");
    }

    output_global_hosts(rank, nprocs,
			hosts, dir);
  }

  // Do we need to export some special variables?
  // (Used to indicate leaders, etc.)
  arg = NULL;
  if( (arg = contains_arg(cargs, "export") ) != NULL ) {
    char *label;
    char *to_rank;

    // Fetch the directory where we store the environment vars. 
    cargs_t *dir_arg = NULL;
    char *export_dir = NULL;
    if( (dir_arg = contains_arg(cargs, "dir") ) != NULL ) {
      export_dir = strtok(dir_arg->value, " ");
    }
    else {
      export_dir = "/tmp/environment";
    }

    // First value is the label to export.
    // Second value is the rank of the node.  
    label = strtok(arg->value, " ");
    to_rank = strtok(NULL, " ");

    // Output the value. 
    output_env(label, to_rank, export_dir);
  }

  // Is there a command? 
  arg = NULL;
  if( (arg = contains_arg(cargs, "cmd") ) != NULL ) {
    launch(arg->value);
  }

  // Finish MPI
  MPI_Finalize();

  return 0;
}
コード例 #3
0
ファイル: message_parse.c プロジェクト: ayttm/ayttm
void eb_parse_incoming_message(eb_local_account *account,
	eb_account *remote, char *message)
{
	char *ptr;
	char *buff = strdup(message);

	ptr = strtok(buff, " ");

	/* Do we want to keep this? */
	if (ptr && !strcmp(ptr, "EB_COMMAND") && !xfer_in_progress) {
		eb_debug(DBG_CORE, "EB_COMMAND received\n");
		ptr = strtok(NULL, " ");
		if (ptr && !strcmp(ptr, "SEND_FILE")) {
			char buff2[1024];
			char myname[1024];
			int s;
			struct sockaddr_in sa;
			struct hostent *hp;

			memset(&sa, 0, sizeof(struct sockaddr_in));	/* clear our address */
			gethostname(myname, 1023);	/* who are we? */
			hp = gethostbyname(myname);	/* get our address info */
			if (hp == NULL) {	/* we don't exist !? */
				eb_debug(DBG_CORE, "gethostbyname failed: %s\n",
					strerror(errno));
				free(buff);
				return;
			}
			sa.sin_family = hp->h_addrtype;	/* this is our host address */
			sa.sin_port = htons(45678);	/* this is our port number */
			if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) {	/* create socket */
				eb_debug(DBG_CORE, "socket failed: %s\n",
					strerror(errno));
				free(buff);
				return;
			}
			if (bind(s, (struct sockaddr *)&sa,
					sizeof(struct sockaddr_in)) < 0) {
				eb_debug(DBG_CORE, "bind failed: %s\n",
					strerror(errno));
				close(s);
				free(buff);
				return;	/* bind address to socket */
			}
			listen(s, 1);	/* max # of queued connects */
			snprintf(buff2, 1024, "EB_COMMAND ACCEPT %s",
				get_local_addresses());
			RUN_SERVICE(remote)->send_im(account, remote, buff2);
			get_file(s);
		}
		if (ptr && !strcmp(ptr, "ACCEPT")) {
			int sockfd;
			struct sockaddr_in dest_addr;

			ptr = strtok(NULL, " ");
			if (!ptr) {
				free(buff);
				return;
			}

			sockfd = socket(AF_INET, SOCK_STREAM, 0);

			dest_addr.sin_family = AF_INET;
			dest_addr.sin_port = htons(45678);
			dest_addr.sin_addr.s_addr = inet_addr(ptr);
			memset(&(dest_addr.sin_zero), 0, 8);

			connect(sockfd, (struct sockaddr *)&dest_addr,
				sizeof(struct sockaddr));
			send_file(filename, sockfd);
		}
	} else {
		/* Ensure that the conversation comes up */
		ay_conversation_chat_with_account(remote);

		ay_conversation_got_message(remote->account_contact->conversation,
			remote->account_contact->nick, message);
	}

	free(buff);
}