| 
									
										
										
										
											2019-07-09 09:53:46 +02:00
										 |  |  | package main | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							| 
									
										
										
										
											2019-07-10 19:00:52 +02:00
										 |  |  | 	"math/big" | 
					
						
							|  |  |  | 	"net" | 
					
						
							| 
									
										
										
										
											2019-07-09 09:53:46 +02:00
										 |  |  | 	"sort" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	"github.com/pyke369/golang-support/uconfig" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // check if there is a member of "search" in "list". sort list to be more | 
					
						
							|  |  |  | // efficiant. adapt with sorting "search" too | 
					
						
							|  |  |  | func inArray(search, list []string) bool { | 
					
						
							|  |  |  | 	sort.Strings(list) | 
					
						
							|  |  |  | 	for _, g := range search { | 
					
						
							|  |  |  | 		i := sort.Search(len(list), func(i int) bool { return list[i] >= g }) | 
					
						
							|  |  |  | 		if i < len(list) && list[i] == g { | 
					
						
							|  |  |  | 			return true | 
					
						
							|  |  |  | 			break | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return false | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // parse a uconf array | 
					
						
							|  |  |  | func parseConfigArray(config *uconfig.UConfig, configpath string) []string { | 
					
						
							|  |  |  | 	result := []string{} | 
					
						
							|  |  |  | 	for _, i := range config.GetPaths(configpath) { | 
					
						
							|  |  |  | 		if s := config.GetString(i, ""); s == "" { | 
					
						
							|  |  |  | 			continue | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			result = append(result, s) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return result | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2019-07-10 19:00:52 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | func nextIP(ip net.IP) net.IP { | 
					
						
							|  |  |  | 	// Convert to big.Int and increment | 
					
						
							|  |  |  | 	ipb := big.NewInt(0).SetBytes([]byte(ip)) | 
					
						
							|  |  |  | 	ipb.Add(ipb, big.NewInt(1)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Add leading zeros | 
					
						
							|  |  |  | 	b := ipb.Bytes() | 
					
						
							|  |  |  | 	b = append(make([]byte, len(ip)-len(b)), b...) | 
					
						
							|  |  |  | 	return net.IP(b) | 
					
						
							|  |  |  | } |