inet.h File Reference

#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "config.h"

Include dependency graph for inet.h:

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

Go to the source code of this file.

Defines

#define HTONL(d)   ((d) = htonl((d)))
#define HTONS(d)   ((d) = htons((d)))
#define INADDR_LOOPBACK   (u_int32_t)0x7F000001
#define NTOHL(d)   ((d) = ntohl((d)))
#define NTOHS(d)   ((d) = ntohs((d)))

Typedefs

typedef int socklen_t

Functions

u_short in_cksum (u_short *, int)
char * InetNtoa (u_int32_t addr)
const char * intoa (u_int32_t addr)
u_int32_t LookupHostAddr (const char *host)
char * LookupHostName (u_int32_t addr)
u_int32_t LookupLocalAddr (void)


Define Documentation

#define HTONL  )     ((d) = htonl((d)))
 

Definition at line 82 of file inet.h.

#define HTONS  )     ((d) = htons((d)))
 

Definition at line 83 of file inet.h.

#define INADDR_LOOPBACK   (u_int32_t)0x7F000001
 

Definition at line 95 of file inet.h.

#define NTOHL  )     ((d) = ntohl((d)))
 

Definition at line 80 of file inet.h.

Referenced by intoa().

#define NTOHS  )     ((d) = ntohs((d)))
 

Definition at line 81 of file inet.h.


Typedef Documentation

typedef int socklen_t
 

Definition at line 122 of file inet.h.


Function Documentation

u_short in_cksum u_short *  ,
int 
 

Definition at line 131 of file inet.c.

00134 {   
00135         register int nleft = len;       
00136         register u_short *w = addr;
00137         register int sum = 0;
00138         u_short answer = 0;
00139     
00140         /*                      
00141          * Our algorithm is simple, using a 32 bit accumulator (sum), we add
00142          * sequential 16 bit words to it, and at the end, fold back all the
00143          * carry bits from the top 16 bits into the lower 16 bits.
00144          */      
00145         while (nleft > 1)  {
00146                 sum += *w++;
00147                 nleft -= 2;
00148         }       
00149     
00150         /* mop up an odd byte, if necessary */
00151         if (nleft == 1) {
00152                 *(u_char *)(&answer) = *(u_char *)w ;
00153                 sum += answer;
00154         }
00155 
00156         /* add back carry outs from top 16 bits to low 16 bits */
00157         sum = (sum >> 16) + (sum & 0xffff);     /* add hi 16 to low 16 */
00158         sum += (sum >> 16);                     /* add carry */
00159         answer = ~sum;                          /* truncate to 16 bits */
00160         return(answer);
00161 }

char* InetNtoa u_int32_t  addr  ) 
 

Definition at line 99 of file inet.c.

References intoa().

Referenced by LookupHostName().

00100 {
00101     const char *s = intoa(addr);
00102     char *p = (char *)malloc(strlen(s) + 1);
00103     strcpy(p, s);
00104     return p;
00105 }

Here is the call graph for this function:

const char* intoa u_int32_t  addr  ) 
 

Definition at line 69 of file inet.c.

References NTOHL.

Referenced by InetNtoa().

00070 {
00071     register char *cp;
00072     register u_int byte;
00073     register int n;
00074     static char buf[sizeof(".xxx.xxx.xxx.xxx")];
00075 
00076     NTOHL(addr);
00077     cp = &buf[sizeof buf];
00078     *--cp = '\0';
00079 
00080     n = 4;
00081     do {
00082         byte = addr & 0xff;
00083         *--cp = byte % 10 + '0';
00084         byte /= 10;
00085         if (byte > 0) {
00086             *--cp = byte % 10 + '0';
00087             byte /= 10;
00088             if (byte > 0)
00089                 *--cp = byte + '0';
00090         }
00091         *--cp = '.';
00092         addr >>= 8;
00093     } while (--n > 0);
00094 
00095     return cp + 1;
00096 }

u_int32_t LookupHostAddr const char *  host  ) 
 

Definition at line 38 of file inet.c.

Referenced by UDPIPNetwork::command(), IPNetwork::command(), and LookupLocalAddr().

00039 {
00040     if (isdigit(*s))
00041         return (u_int32_t)inet_addr(s);
00042     else {
00043         struct hostent *hp = gethostbyname(s);
00044         if (hp == 0)
00045             /*XXX*/
00046             return (0);
00047         return *((u_int32_t **)hp->h_addr_list)[0];
00048     }
00049 }

char* LookupHostName u_int32_t  addr  ) 
 

Definition at line 108 of file inet.c.

References InetNtoa().

00109 {
00110     char *p;
00111     struct hostent* hp;
00112 
00113     /*XXX*/
00114     if (IN_MULTICAST(ntohl(addr)))
00115         return (InetNtoa(addr));
00116 
00117     hp = gethostbyaddr((char *)&addr, sizeof(addr), AF_INET);
00118     if (hp == 0) 
00119         return InetNtoa(addr);
00120     p = (char *)malloc(strlen(hp->h_name) + 1);
00121     strcpy(p, hp->h_name);
00122     return p;
00123 }

Here is the call graph for this function:

u_int32_t LookupLocalAddr void   ) 
 

Definition at line 52 of file inet.c.

References LookupHostAddr().

00053 {
00054     static u_int32_t local_addr;
00055     char name[MAXHOSTNAMELEN];
00056     
00057     if (local_addr == 0) {
00058         (void)gethostname(name, sizeof(name));
00059         local_addr = LookupHostAddr(name);
00060     }
00061     return (local_addr);
00062 }

Here is the call graph for this function:


Generated on Tue Mar 6 16:53:53 2007 for ns2 Network Simulator 2.29 by  doxygen 1.4.6