Commit 5702c53b authored by Gero Hülsbusch's avatar Gero Hülsbusch
Browse files

Update get_addresses.c

parent ae9e095a
//
// Created by user on 27.11.21.
//
/**
Schreiben Sie ein Programm getaddresses, das einen Hostnamen als Argument akzeptiert und alle zugeho ̈rigen IP-Adressen (IPv4 und IPv6) ausgibt. Benutzen Sie dabei getaddrinfo() und getnameinfo().
Was ist der Unterschied von inet ntop() und getnameinfo() bei link- lokalen IPv6 Adressen?
int_ntop
This function converts the network address structure src in the
af address family into a character string. The resulting string
is copied to the buffer pointed to by dst, which must be a non-
null pointer. The caller specifies the number of bytes available
in this buffer in the argument size.
inet_ntop() extends the inet_ntoa(3) function to support multiple
address families, inet_ntoa(3) is now considered to be deprecated
in favor of inet_ntop(). The following address families are
currently supported:
AF_INET
src points to a struct in_addr (in network byte order)
which is converted to an IPv4 network address in the
dotted-decimal format, "ddd.ddd.ddd.ddd". The buffer dst
must be at least INET_ADDRSTRLEN bytes long.
AF_INET6
src points to a struct in6_addr (in network byte order)
which is converted to a representation of this address in
the most appropriate IPv6 network address format for this
address. The buffer dst must be at least INET6_ADDRSTRLEN
bytes long.
getnameinfo
The getnameinfo() function is the inverse of getaddrinfo(3): it
converts a socket address to a corresponding host and service, in
a protocol-independent manner. It combines the functionality of
gethostbyaddr(3) and getservbyport(3), but unlike those
functions, getnameinfo() is reentrant and allows programs to
eliminate IPv4-versus-IPv6 dependencies.
The addr argument is a pointer to a generic socket address
structure (of type sockaddr_in or sockaddr_in6) of size addrlen
that holds the input IP address and port number. The arguments
host and serv are pointers to caller-allocated buffers (of size
hostlen and servlen respectively) into which getnameinfo() places
null-terminated strings containing the host and service names
respectively.
The caller can specify that no hostname (or no service name) is
required by providing a NULL host (or serv) argument or a zero
hostlen (or servlen) argument. However, at least one of hostname
or service name must be requested.
The flags argument modifies the behavior of getnameinfo() as
follows:
*/
#include "Socket.h"
......@@ -14,7 +70,9 @@ int main(int argc, char* argv[]) {
}
int ret;
//The getnameinfo() function is the inverse of getaddrinfo(3): it
//converts a socket address to a corresponding host and service, in
//a protocol-independent manner.
if ((ret = getaddrinfo(argv[1], NULL, NULL, &result))) {
fprintf(stderr, "Getaddrinfo: %s\n", gai_strerror(ret));
return 2;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment