Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <sys/socket.h>
- #include <netdb.h>
- static char name[32];
- int main(int argc, char **argv)
- {
- int error;
- char *ip = argv[1];
- struct sockaddr_in sa;
- if (argc <= 1) {
- fprintf(stderr, "usage: %s <ip address>\n", argv[0]);
- exit(EXIT_FAILURE);
- }
- memset(&sa, 0, sizeof(sa));
- sa.sin_family = AF_INET;
- error = inet_aton(ip, &sa.sin_addr);
- if (error == 0) {
- perror("inet_aton()");
- exit(EXIT_FAILURE);
- }
- error = getnameinfo((struct sockaddr *)&sa, sizeof(sa), name, sizeof(name), NULL, 0, NI_NAMEREQD);
- if (error) {
- perror("getnameinfo()");
- exit(EXIT_FAILURE);
- }
- puts(name);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment