Added new function config_address2addrinfo
This function takes an "Address" config string, splits it into address and port, then calls str2addinfo() on it returning addrinfo. The aim is to refactor the code an allow simple translation of addresses listed in configuration or generated on demand in other places in the code.
This commit is contained in:
		
							parent
							
								
									deccb83a29
								
							
						
					
					
						commit
						299b223bba
					
				
					 2 changed files with 20 additions and 0 deletions
				
			
		
							
								
								
									
										19
									
								
								src/netutl.c
									
										
									
									
									
								
							
							
						
						
									
										19
									
								
								src/netutl.c
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -54,6 +54,25 @@ struct addrinfo *str2addrinfo(const char *address, const char *service, int sock
 | 
			
		|||
	return ai;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
  Turn a configuration Address string into addrinfo.
 | 
			
		||||
*/
 | 
			
		||||
struct addrinfo *config_address2addrinfo(char *address, int socktype) {
 | 
			
		||||
	struct addrinfo *ai;
 | 
			
		||||
	char *space, *port;
 | 
			
		||||
	space = strchr(address, ' ');
 | 
			
		||||
	if(space) {
 | 
			
		||||
		port = xstrdup(space + 1);
 | 
			
		||||
		*space = 0;
 | 
			
		||||
	} else
 | 
			
		||||
			port = xstrdup("655");
 | 
			
		||||
 | 
			
		||||
	ai = str2addrinfo(address, port, socktype);
 | 
			
		||||
	free(port);
 | 
			
		||||
 | 
			
		||||
	return ai;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
sockaddr_t str2sockaddr(const char *address, const char *port) {
 | 
			
		||||
	struct addrinfo *ai, hint;
 | 
			
		||||
	sockaddr_t result;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -26,6 +26,7 @@
 | 
			
		|||
extern bool hostnames;
 | 
			
		||||
 | 
			
		||||
extern struct addrinfo *str2addrinfo(const char *, const char *, int) __attribute__ ((__malloc__));
 | 
			
		||||
extern struct addrinfo *config_address2addrinfo(char *, int);
 | 
			
		||||
extern sockaddr_t str2sockaddr(const char *, const char *);
 | 
			
		||||
extern void sockaddr2str(const sockaddr_t *, char **, char **);
 | 
			
		||||
extern char *sockaddr2hostname(const sockaddr_t *) __attribute__ ((__malloc__));
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue