Cleanup...
This commit is contained in:
parent
b98c794591
commit
13a38cd92e
1 changed files with 0 additions and 28 deletions
28
netcalc.c
28
netcalc.c
|
@ -21,26 +21,6 @@ void cleanup(int signum)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void printaddr(struct addrinfo *ainfo)
|
|
||||||
{
|
|
||||||
char ipstr[INET6_ADDRSTRLEN]; // will hold the IP adress, humanreadable
|
|
||||||
void *addr;
|
|
||||||
char *ipver;
|
|
||||||
for (struct addrinfo *p = ainfo; p->ai_next != NULL; p = p->ai_next) {
|
|
||||||
if (p->ai_family == AF_INET) { // IPv4
|
|
||||||
struct sockaddr_in *ipv4 = (struct sockaddr_in *) p->ai_addr;
|
|
||||||
addr = &(ipv4->sin_addr);
|
|
||||||
ipver = "IPv4";
|
|
||||||
} else { // IPv6
|
|
||||||
struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *) p->ai_addr;
|
|
||||||
addr = &(ipv6->sin6_addr);
|
|
||||||
ipver = "IPv6";
|
|
||||||
}
|
|
||||||
inet_ntop(p->ai_family, addr, ipstr, sizeof ipstr);
|
|
||||||
printf("Listening on %s: %s\n", ipver, ipstr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int prepaddr(char *host, char *port, struct addrinfo **ainfo)
|
int prepaddr(char *host, char *port, struct addrinfo **ainfo)
|
||||||
{
|
{
|
||||||
struct addrinfo hints; // hints to what we want
|
struct addrinfo hints; // hints to what we want
|
||||||
|
@ -55,8 +35,6 @@ int prepaddr(char *host, char *port, struct addrinfo **ainfo)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
printaddr(*ainfo);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,12 +53,6 @@ int prepsocket(struct addrinfo *ainfo)
|
||||||
cleanup(0);
|
cleanup(0);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
// yes means no!
|
|
||||||
//if (setsockopt(sockfd, IPPROTO_IPV6, IPV6_V6ONLY, &yes, sizeof yes) == -1) {
|
|
||||||
// perror("setsockopt");
|
|
||||||
// cleanup(0);
|
|
||||||
// return -1;
|
|
||||||
//}
|
|
||||||
|
|
||||||
if (bind(sockfd, ainfo->ai_addr, ainfo->ai_addrlen) != 0) {
|
if (bind(sockfd, ainfo->ai_addr, ainfo->ai_addrlen) != 0) {
|
||||||
perror("bind");
|
perror("bind");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue