20#define HOSTBUF_SIZE 1024
28struct addrinfo *rc_getaddrinfo (
char const *host,
unsigned flags)
30 struct addrinfo hints, *res;
32 const char *service = NULL;
34 memset(&hints, 0,
sizeof(hints));
35 hints.ai_socktype = SOCK_DGRAM;
36 if (flags & PW_AI_PASSIVE)
37 hints.ai_flags = AI_PASSIVE;
39 if (flags & PW_AI_AUTH)
41 else if (flags & PW_AI_ACCT)
42 service =
"radius-acct";
44 err = getaddrinfo(host, service, &hints, &res);
46 rc_log(LOG_ERR,
"rc_getaddrinfo: %s: %s", host ? host :
"(null)", gai_strerror(err));
68 if ((svp = getservbyname ((type==
AUTH)?
"radius" :
"radacct",
"udp")) == NULL)
70 return (type==
AUTH) ? PW_AUTH_UDP_PORT : PW_ACCT_UDP_PORT;
72 return ntohs ((
unsigned short) svp->s_port);
88#if defined(HAVE_UNAME)
91 rc_log(LOG_ERR,
"rc_own_hostname: couldn't get own hostname");
94 strlcpy(hostname, uts.nodename, len);
95#elif defined(HAVE_GETHOSTNAME)
96 if (gethostname(hostname, len) < 0)
98 rc_log(LOG_ERR,
"rc_own_hostname: couldn't get own hostname");
101#elif defined(HAVE_SYSINFO)
102 if (sysinfo(SI_HOSTNAME, hostname, len) < 0)
104 rc_log(LOG_ERR,
"rc_own_hostname: couldn't get own hostname");
130 temp_sock = socket(ria->sa_family, SOCK_DGRAM, 0);
131 if (temp_sock == -1) {
132 rc_log(LOG_ERR,
"rc_get_srcaddr: socket: %s", strerror(errno));
136 if (connect(temp_sock, ria, SA_LEN(ria)) != 0) {
137 int rc = errno == ENETUNREACH ? NETUNREACH_RC : ERROR_RC;
138 rc_log(LOG_ERR,
"rc_get_srcaddr: connect: %s",
144 namelen = SA_LEN(ria);
145 if (getsockname(temp_sock, lia, &namelen) != 0) {
146 rc_log(LOG_ERR,
"rc_get_srcaddr: getsockname: %s",
166void rc_own_bind_addr(rc_handle *rh,
struct sockaddr_storage *lia)
169 struct addrinfo *info;
171 if (rh->own_bind_addr_set) {
172 memcpy(lia, &rh->own_bind_addr, SS_LEN(&rh->own_bind_addr));
176 memset(lia, 0,
sizeof(*lia));
177 if (txtaddr == NULL || txtaddr[0] ==
'*') {
178 ((
struct sockaddr_in*)lia)->sin_family = AF_INET;
179 ((
struct sockaddr_in*)lia)->sin_addr.s_addr = INADDR_ANY;
181 info = rc_getaddrinfo (txtaddr, PW_AI_PASSIVE);
183 rc_log(LOG_ERR,
"rc_own_ipaddress: couldn't get IP address from bindaddr");
184 ((
struct sockaddr_in*)lia)->sin_family = AF_INET;
185 ((
struct sockaddr_in*)lia)->sin_addr.s_addr = INADDR_ANY;
189 memcpy(lia, info->ai_addr, info->ai_addrlen);
unsigned short rc_getport(int type)
Get the port number for the supplied request type.
int rc_get_srcaddr(struct sockaddr *lia, const struct sockaddr *ria)
Find outbound interface address for a given destination.
int rc_own_hostname(char *hostname, int len)
Get the hostname of this machine.
char * rc_conf_str(rc_handle const *rh, char const *optname)
Get the value of a config option.
@ AUTH
Request for authentication server.
Public API of the radcli library.