17#include <radcli/radcli.h>
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)
44 err = getaddrinfo(host, service, &hints, &res);
67 if ((svp = getservbyname ((type==
AUTH)?
"radius" :
"radacct",
"udp")) == NULL)
69 return (type==
AUTH) ? PW_AUTH_UDP_PORT : PW_ACCT_UDP_PORT;
71 return ntohs ((
unsigned short) svp->s_port);
87#if defined(HAVE_UNAME)
90 rc_log(LOG_ERR,
"rc_own_hostname: couldn't get own hostname");
93 strlcpy(hostname, uts.nodename, len);
94#elif defined(HAVE_GETHOSTNAME)
95 if (gethostname(hostname, len) < 0)
97 rc_log(LOG_ERR,
"rc_own_hostname: couldn't get own hostname");
100#elif defined(HAVE_SYSINFO)
101 if (sysinfo(SI_HOSTNAME, hostname, len) < 0)
103 rc_log(LOG_ERR,
"rc_own_hostname: couldn't get own hostname");
129 temp_sock = socket(ria->sa_family, SOCK_DGRAM, 0);
130 if (temp_sock == -1) {
131 rc_log(LOG_ERR,
"rc_get_srcaddr: socket: %s", strerror(errno));
135 if (connect(temp_sock, ria, SA_LEN(ria)) != 0) {
136 int rc = errno == ENETUNREACH ? NETUNREACH_RC : ERROR_RC;
137 rc_log(LOG_ERR,
"rc_get_srcaddr: connect: %s",
143 namelen = SA_LEN(ria);
144 if (getsockname(temp_sock, lia, &namelen) != 0) {
145 rc_log(LOG_ERR,
"rc_get_srcaddr: getsockname: %s",
167 struct addrinfo *info;
169 if (rh->own_bind_addr_set) {
170 memcpy(lia, &rh->own_bind_addr, SS_LEN(&rh->own_bind_addr));
174 memset(lia, 0,
sizeof(*lia));
175 if (txtaddr == NULL || txtaddr[0] ==
'*') {
176 ((
struct sockaddr_in*)lia)->sin_family = AF_INET;
177 ((
struct sockaddr_in*)lia)->sin_addr.s_addr = INADDR_ANY;
179 info = rc_getaddrinfo (txtaddr, PW_AI_PASSIVE);
181 rc_log(LOG_ERR,
"rc_own_ipaddress: couldn't get IP address from bindaddr");
182 ((
struct sockaddr_in*)lia)->sin_family = AF_INET;
183 ((
struct sockaddr_in*)lia)->sin_addr.s_addr = INADDR_ANY;
187 memcpy(lia, info->ai_addr, info->ai_addrlen);
unsigned short rc_getport(int type)
int rc_get_srcaddr(struct sockaddr *lia, const struct sockaddr *ria)
int rc_own_hostname(char *hostname, int len)
void rc_own_bind_addr(rc_handle *rh, struct sockaddr_storage *lia)
char * rc_conf_str(rc_handle const *rh, char const *optname)
@ AUTH
Request for authentication server.