Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How do I convert the IP address from Internet Host Address?

45 views
Skip to first unread message

Brendan Chung

unread,
Nov 18, 1999, 3:00:00 AM11/18/99
to
How do I convert the IP address(numbers-and-dots notation) from Internet
Host Address?

It is easy in Unix. But I don't know how to convert in VxWorks?

/* unix
* compile: cc -o addr_conv addr_conv.c -lsocket -lnsl
* test : addr www.kaist.ac.kr
*/
#include <netdb.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

int main(int argc, char *argv[]) {
struct hostent *ptr_he;
struct in_addr in;
char *hname;

if(argc != 2) {
printf("Usage : %s hostname \n", argv[0]);
return -1;
}
hname = argv[1];

if((ptr_he = gethostbyname(hname)))


memcpy(&in.s_addr,ptr_he->h_addr_list[0], sizeof(in.s_addr));
printf("%s\'s IP address : %s\n", hname, inet_ntoa(in));
} else {
printf("gethostbyname error.\n");
}
}


yann chambionnat

unread,
Nov 18, 1999, 3:00:00 AM11/18/99
to
In vxworks it's near the same thing as Unix :
you must use the fonction hostGetByName(char* Name); (inlcude hostLib.h)
see also hostLib

bye
yann

Brendan Chung a écrit :


>
> How do I convert the IP address(numbers-and-dots notation) from Internet
> Host Address?

--
=====/= yann.cha...@temex.fr
= /=== Tekelec Temex
=/===== tel : +33 1 698 220 00
T E M E X 29 avenue de la Baltique
TELECOM 91953 Les Ulis cedex - FRANCE

0 new messages