Syntax
#include <snmp_dpi.h> unsigned long lookup_host( /* find IP address in network */ char *hostname_p); /* byte order for this host */
Parameters
hostname_p
Return Values
If successful, the IP address is returned in network byte order, so it is ready to be used in a sockaddr_in structure.
If failure, a value of 0 is returned.
Description
The lookup_host() function is used to obtain the IP address in network byte order of a host or IP address in dot notation.
The DPI subagent programmer only needs to use this function to code the connection setup and send or await the packet. The programmer then obtains the DPI port number, finds the IP address of the agent with the lookup_host() function and then sets up a socket for communication.
This function is implicitly executed by the DPIconnect_to_agent_TCP() function, which is the function that the DPI subagent programmer would normally use. So the lookup_host() function is normally not used by the DPI subagent programmer.
Examples
#include <snmp_dpi.h>#include /* other include files for BSD sockets and such */
int handle;
unsigned char *pack_p;
long int dpi_port;
int fd;
struct sockaddr_in s,t; /* source and target */
dpi_port = query_DPI_port("localhost", /* get DPI port number */
"public", /* for TCP, local host */
dpiPortForTCP);
if (dpi_port < 0) exit(1); /* error if negative */
host_addr = lookup_host("localhost"); /* find target IP addr */
if (host_addr == 0) exit(1); /* unknown, that's it */
fd = socket(AF_INET,SOCK_STREAM,0); /* create a TCP socket */
if (fd < 0) exit(1); /* failure to do so */
memset(&s,0,sizeof(s));
s.sin_family = AF_INET; /* set AF_INET family */
s.sin_port = 0; /* give us any port, */
s.sin_addr.s_addr = htonl(INADDR_ANY); /* any local IPaddress */
rc = bind(fd,(struct sockaddr *)s, /* bind our socket(fd) */
sizeof(s_sock)); /* defined in s socket */
if (rc < 0) exit(1); /* failure, so exit */
memset(&d,0,sizeof(d));
d.sin_family = AF_INET; /* set AF_INET family */
d.sin_port = htons(dpi_port); /* set requested port */
d.sin_addr.s_addr = host_addr; /* destination IP addr */
/* network byte order */
rc = connect(fd,(struct sockaddr *)d, /* connect to target */
sizeof(d)); /* based on d sock */
if (rc < 0) exit(1); /* failed, exit */
/* now we have a socket on which to send/receive DPI packets */
Related Information