Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * resolve.c
- *
- * Copyleft (C) 2015 Sun Dro (a.k.a. kala13x)
- *
- * Simple app to resolve addres.
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdint.h>
- #include <unistd.h>
- #include <netdb.h>
- #include <arpa/inet.h>
- uint32_t GetInetAddr(const char *pAddr)
- {
- struct hostent *pServer = gethostbyname(pAddr);
- if (pServer == NULL)
- {
- printf("Error: No such host: %s\n", pAddr);
- return 0;
- }
- const char *pIpAddr = inet_ntoa(*(struct in_addr *)pServer->h_addr);
- printf("Resoled IP Addr: %s\n", pIpAddr);
- return (uint32_t)inet_addr(pIpAddr);
- }
- int main(int argc, char *argv[])
- {
- if (argc < 2)
- {
- printf("Usage: %s <domain>\n", argv[0]);
- printf("Example: %s google.ge\n", argv[0]);
- return 1;
- }
- uint32_t nAddr = GetInetAddr(argv[1]);
- if (nAddr) printf("Inet Byte Addr: %llu\n", nAddr);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement