void slirp_init(int restricted, const char *special_ip) { #if DEBUG int slirp_logmask = 0; char slirp_logfile[512]; { const char* env = getenv( "ANDROID_SLIRP_LOGMASK" ); if (env != NULL) slirp_logmask = atoi(env); else if (VERBOSE_CHECK(slirp)) slirp_logmask = DEBUG_DEFAULT; } { char* p = slirp_logfile; char* end = p + sizeof(slirp_logfile); p = bufprint_temp_file( p, end, "slirp.log" ); if (p >= end) { dprint( "cannot create slirp log file in temporary directory" ); slirp_logmask = 0; } } if (slirp_logmask) { dprint( "sending slirp logs with mask %x to %s", slirp_logmask, slirp_logfile ); debug_init( slirp_logfile, slirp_logmask ); } #endif link_up = 1; slirp_restrict = restricted; if_init(); ip_init(); m_init(); inet_strtoip("127.0.0.1", &loopback_addr_ip); if (dns_addr_count == 0) { if (slirp_get_system_dns_servers() < 0) { dns_addr[0] = loopback_addr_ip; dns_addr_count = 1; fprintf (stderr, "Warning: No DNS servers found\n"); } } inet_strtoip(CTL_SPECIAL, &special_addr_ip); alias_addr_ip = special_addr_ip | CTL_ALIAS; getouraddr(); register_savevm("slirp", 0, 1, slirp_state_save, slirp_state_load, NULL); slirp_net_forward_init(); }
/* Create a new AUserConfig object from a given AvdInfo */ AUserConfig* auserConfig_new( AvdInfo* info ) { AUserConfig* uc; char inAndroidBuild = avdInfo_inAndroidBuild(info); char needUUID = 1; char temp[PATH_MAX], *p=temp, *end=p+sizeof(temp); char* parentPath; IniFile* ini = NULL; ANEW0(uc); /* If we are in the Android build system, store the configuration * in ~/.android/emulator-user.ini. otherwise, store it in the file * emulator-user.ini in the AVD's content directory. */ if (inAndroidBuild) { p = bufprint_config_file(temp, end, USER_CONFIG_FILE); } else { p = bufprint(temp, end, "%s/%s", avdInfo_getContentPath(info), USER_CONFIG_FILE); } /* handle the unexpected */ if (p >= end) { /* Hmmm, something is weird, let's use a temporary file instead */ p = bufprint_temp_file(temp, end, USER_CONFIG_FILE); if (p >= end) { derror("Weird: Cannot create temporary user-config file?"); exit(2); } dwarning("Weird: Content path too long, using temporary user-config."); } uc->iniPath = ASTRDUP(temp); DD("looking user-config in: %s", uc->iniPath); /* ensure that the parent directory exists */ parentPath = path_parent(uc->iniPath, 1); if (parentPath == NULL) { derror("Weird: Can't find parent of user-config file: %s", uc->iniPath); exit(2); } if (!path_exists(parentPath)) { if (!inAndroidBuild) { derror("Weird: No content path for this AVD: %s", parentPath); exit(2); } DD("creating missing directory: %s", parentPath); if (path_mkdir_if_needed(parentPath, 0755) < 0) { derror("Using empty user-config, can't create %s: %s", parentPath, strerror(errno)); exit(2); } } if (path_exists(uc->iniPath)) { DD("reading user-config file"); ini = iniFile_newFromFile(uc->iniPath); if (ini == NULL) { dwarning("Can't read user-config file: %s\nUsing default values", uc->iniPath); } } if (ini != NULL) { uc->windowX = iniFile_getInteger(ini, KEY_WINDOW_X, DEFAULT_X); DD(" found %s = %d", KEY_WINDOW_X, uc->windowX); uc->windowY = iniFile_getInteger(ini, KEY_WINDOW_Y, DEFAULT_Y); DD(" found %s = %d", KEY_WINDOW_Y, uc->windowY); if (iniFile_getValue(ini, KEY_UUID) != NULL) { uc->uuid = (uint64_t) iniFile_getInt64(ini, KEY_UUID, 0LL); needUUID = 0; DD(" found %s = %lld", KEY_UUID, uc->uuid); } iniFile_free(ini); } else { uc->windowX = DEFAULT_X; uc->windowY = DEFAULT_Y; uc->changed = 1; } /* Generate a 64-bit UUID if necessary. We simply take the * current time, which avoids any privacy-related value. */ if (needUUID) { struct timeval tm; gettimeofday( &tm, NULL ); uc->uuid = (uint64_t)tm.tv_sec*1000 + tm.tv_usec/1000; uc->changed = 1; DD(" Generated UUID = %lld", uc->uuid); } return uc; }