inc/internet.h File Reference

#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>

Include dependency graph for internet.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

bits32 internetHostIp (char *hostName)
boolean internetFillInAddress (char *hostName, int port, struct sockaddr_in *address)
boolean internetIpToDottedQuad (bits32 ip, char dottedQuad[17])
boolean internetDottedQuadToIp (char *dottedQuad, bits32 *retIp)
boolean internetIsDottedQuad (char *s)
void internetParseDottedQuad (char *dottedQuad, unsigned char quad[4])
void internetUnpackIp (bits32 packed, unsigned char unpacked[4])
boolean internetIpInSubnet (unsigned char unpackedIp[4], unsigned char subnet[4])


Function Documentation

boolean internetDottedQuadToIp ( char *  dottedQuad,
bits32 *  retIp 
)

Definition at line 89 of file internet.c.

References errno, FALSE, TRUE, and warn().

Referenced by internetHostIp().

00093 {
00094 #ifndef __CYGWIN32__
00095 struct in_addr ia;
00096 if (inet_pton(AF_INET, dottedQuad, &ia) < 0)
00097     {
00098     warn("internetDottedQuadToIp problem on %s: %s", dottedQuad, strerror(errno));
00099     return FALSE;
00100     }
00101 *retIp = ntohl(ia.s_addr);
00102 return TRUE;
00103 #else
00104 warn("Sorry, internetDottedQuadToIp not supported in Windows.");
00105 return FALSE;
00106 #endif
00107 }

Here is the call graph for this function:

Here is the caller graph for this function:

boolean internetFillInAddress ( char *  hostName,
int  port,
struct sockaddr_in *  address 
)

Definition at line 50 of file internet.c.

References FALSE, internetHostIp(), TRUE, and ZeroVar.

Referenced by netAcceptingSocketFrom(), and netConnect().

00052 {
00053 ZeroVar(address);
00054 address->sin_family = AF_INET;
00055 address->sin_port = htons(port);
00056 if (hostName == NULL)
00057     address->sin_addr.s_addr = INADDR_ANY;
00058 else
00059     {
00060     if ((address->sin_addr.s_addr = htonl(internetHostIp(hostName))) == 0)
00061         return FALSE;
00062     }
00063 return TRUE;
00064 }

Here is the call graph for this function:

Here is the caller graph for this function:

bits32 internetHostIp ( char *  hostName  ) 

Definition at line 26 of file internet.c.

References bits32, internetDottedQuadToIp(), internetIsDottedQuad(), and warn().

Referenced by internetFillInAddress().

00029 {
00030 struct hostent *hostent;
00031 bits32 ret;
00032 if (internetIsDottedQuad(hostName))
00033    {
00034    internetDottedQuadToIp(hostName, &ret);
00035    }
00036 else
00037     {
00038     hostent = gethostbyname(hostName);
00039     if (hostent == NULL)
00040         {
00041         warn("Couldn't find host %s. h_errno %d", hostName, h_errno);
00042         return 0;
00043         }
00044     memcpy(&ret, hostent->h_addr_list[0], sizeof(ret));
00045     ret = ntohl(ret);
00046     }
00047 return ret;
00048 }

Here is the call graph for this function:

Here is the caller graph for this function:

boolean internetIpInSubnet ( unsigned char  unpackedIp[4],
unsigned char  subnet[4] 
)

Definition at line 135 of file internet.c.

References FALSE, and TRUE.

Referenced by netAcceptFrom().

00137 {
00138 int i;
00139 for (i=0; i<4; ++i)
00140     {
00141     unsigned char c = subnet[i];
00142     if (c == 255)
00143         return TRUE;
00144     if (c != unpackedIp[i])
00145         return FALSE;
00146     }
00147 return TRUE;
00148 }

Here is the caller graph for this function:

boolean internetIpToDottedQuad ( bits32  ip,
char  dottedQuad[17] 
)

Definition at line 66 of file internet.c.

References errno, FALSE, TRUE, warn(), zeroBytes(), and ZeroVar.

00070 {
00071 #ifndef __CYGWIN32__
00072 struct in_addr ia;
00073 zeroBytes(dottedQuad, 17);
00074 ZeroVar(&ia);
00075 ia.s_addr = htonl(ip);
00076 if (inet_ntop(AF_INET, &ia, dottedQuad, 16) == NULL)
00077     {
00078     warn("conversion problem on 0x%x in internetIpToDottedQuad: %s", 
00079         ip, strerror(errno));
00080     return FALSE;
00081     }
00082 return TRUE;
00083 #else
00084 warn("Sorry, internetIpToDottedQuad not supported in Windows.");
00085 return FALSE;
00086 #endif
00087 }

Here is the call graph for this function:

boolean internetIsDottedQuad ( char *  s  ) 

Definition at line 8 of file internet.c.

References FALSE, and TRUE.

Referenced by internetHostIp(), and internetParseDottedQuad().

00010 {
00011 int i;
00012 if (!isdigit(s[0]))
00013     return FALSE;
00014 for (i=0; i<3; ++i)
00015     {
00016     s = strchr(s, '.');
00017     if (s == NULL)
00018         return FALSE;
00019     s += 1;
00020     if (!isdigit(s[0]))
00021         return FALSE;
00022     }
00023 return TRUE;
00024 }

Here is the caller graph for this function:

void internetParseDottedQuad ( char *  dottedQuad,
unsigned char  quad[4] 
)

Definition at line 109 of file internet.c.

References errAbort(), and internetIsDottedQuad().

00111 {
00112 char *s = dottedQuad;
00113 int i;
00114 if (!internetIsDottedQuad(s))
00115     errAbort("%s is not a dotted quad", s);
00116 for (i=0; i<4; ++i)
00117     {
00118     quad[i] = atoi(s);
00119     s = strchr(s, '.') + 1;
00120     }
00121 }

Here is the call graph for this function:

void internetUnpackIp ( bits32  packed,
unsigned char  unpacked[4] 
)

Definition at line 123 of file internet.c.

Referenced by netAcceptFrom().

00126 {
00127 int i;
00128 for (i=3; i>=0; --i)
00129     {
00130     unpacked[i] = (packed&0xff);
00131     packed >>= 8;
00132     }
00133 }

Here is the caller graph for this function:


Generated on Tue Dec 25 19:02:35 2007 for blat by  doxygen 1.5.2