blob: f7b5ecb2c385838b693ce144c5c69dcc8710afc5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <unistd.h>
#include "macros.h"
#include "network.h"
const char *addr_to_str(struct sockaddr *sa, socklen_t len) {
const int family = sa->sa_family;
static char ip[INET6_ADDRSTRLEN];
char *str = ip;
switch (family) {
case AF_INET6 : inet_ntop(family, &((struct sockaddr_in6 *)sa)->sin6_addr, ip, len); break;
case AF_INET : inet_ntop(family, &((struct sockaddr_in *)sa)->sin_addr, ip, len); break;
case AF_UNIX : str = ((struct sockaddr_un *)sa)->sun_path; break;
}
return str;
}
|