----- Original Message ----- 
From: "RAHUL CHOUBE" <[EMAIL PROTECTED]>
To: "Palm Developer Forum" <[EMAIL PROTECTED]>
Sent: Saturday, January 31, 2004 3:05 PM
Subject: regarding gethostbyname () func


> i am getting an error of nellibgethostbyname even if i
> am not using it in the code , i am using
> gethostbyname... so any help regarding this topic will
> be greatly appreciated.

It's difficult to guess what's wrong when you did not tell what the problem
is.Anyway, the following is the code that use NetLibGetHostByName.
The logic is :
For a given server name, it may be either an ip address "x.y.z.t" or a dns
name like myhost.domain.net . Assume it is "x.y.z.t", try to convert it to
network-byte-order ipaddress by NetLibAddrAToIN. If it does not give any
error, then we have the expected ip address parsed into NetIPAddr. If it
gives some error, then it is not under the format "x.y.z.t", then it may be
a DNS name. In that case, GetHostByName will be called to use the dns
resolution to ger the ip.

---------------------------------

NetIPAddr ipaddr;
NetHostInfoBufPtr  phostinfobuf = NULL;
NetHostInfoPtr  phostinfo = NULL;
NetIPAddr *pipaddr = NULL;
Err err;

 ipaddr = NetLibAddrAToIN( gNetRefNum, p );
 if ( ipaddr != -1  ) return ipaddr;

 phostinfobuf = (NetHostInfoBufPtr) MemPtrNew( sizeof(NetHostInfoBufType));
 if ( phostinfobuf == NULL ) return -1;
 phostinfo = NetLibGetHostByName( gNetRefNum, p, phostinfobuf,
SysTicksPerSecond(), &err );
 if( err )
 {
  MemPtrFree( phostinfobuf );
  return err;
 }
 pipaddr =( NetIPAddr*) phostinfo->addrListP[0];
 ipaddr = NetNToHL( *pipaddr );
 MemPtrFree( phostinfobuf );
 return ipaddr;
----------------------------------------------

For more information, you can check with PalmOS Reference or the book PalmOS
Network Programming.

HTH,

Vu


-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to