- Timestamp:
- May 3, 2021, 10:56:05 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/FlairCore/src/FrameworkManager_impl.cpp
r414 r424 35 35 #include <signal.h> 36 36 #include <fcntl.h> 37 #include <utmp.h> 37 38 #ifdef __XENO__ 38 39 #include <native/task.h> … … 222 223 } 223 224 if(address=="autodetect") { 224 Printf(" autodetecting gcs ip address based on ssh connection\n");225 Printf("Autodetecting gcs ip address based on ssh connection\n"); 225 226 address=AutoDetectGCS(); 226 227 } … … 253 254 254 255 string FrameworkManager_impl::AutoDetectGCS(void) { 255 FILE *fp; 256 char result[15]; 257 258 //get only first result and remove line feed 259 fp = popen("who | awk '{ print $7; }' | head -n 1 | tr -d '\n'", "r"); 260 if (fp == NULL) { 261 Err("Failed to run autodetect command\n" ); 262 } 263 264 fgets(result, sizeof(result), fp); 265 pclose(fp); 266 267 return result; 256 int logsize = 10;//should be sufficient 257 int file; 258 struct utmp log[logsize]; 259 260 file = open("/var/run/utmp", O_RDONLY); 261 262 //return only first matching occurence 263 //TODO: check also log->ut_addr_v6[0] 264 if (file) { 265 int read_size=read(file, &log, sizeof(log)); 266 int nb=read_size/sizeof(struct utmp); 267 268 for(int i = 0; i < nb; i++) { 269 //printf("\n ut_user: %s host: %s %x\n ut_type: %ld line %s\n", log[i].ut_user,log[i].ut_host,log[i].ut_addr_v6[0], log[i].ut_type,log[i].ut_line); 270 if(log[i].ut_type==USER_PROCESS) { 271 close(file); 272 return log[i].ut_host; 273 } 274 275 } 276 277 close(file); 278 } 279 280 Err("Failed to run autodetect command\n" ); 281 return ""; 268 282 } 269 283
Note:
See TracChangeset
for help on using the changeset viewer.