groupsock/inet.c File Reference

#include "NetCommon.h"
#include <stdio.h>

Include dependency graph for inet.c:

Go to the source code of this file.

Defines

#define initializeWinsockIfNecessary()   1
#define NULL   0
#define TYPE_0   0
#define BREAK_0   8
#define DEG_0   0
#define SEP_0   0
#define TYPE_1   1
#define BREAK_1   32
#define DEG_1   7
#define SEP_1   3
#define TYPE_2   2
#define BREAK_2   64
#define DEG_2   15
#define SEP_2   1
#define TYPE_3   3
#define BREAK_3   128
#define DEG_3   31
#define SEP_3   3
#define TYPE_4   4
#define BREAK_4   256
#define DEG_4   63
#define SEP_4   1
#define MAX_TYPES   5

Functions

unsigned our_inet_addr (char const *cp)
long our_random (void)
void our_srandom (unsigned int x)
char * our_initstate (unsigned int seed, char *arg_state, int n)
char * our_setstate (char *arg_state)
u_int32_t our_random32 ()

Variables

static int const degrees [MAX_TYPES] = { DEG_0, DEG_1, DEG_2, DEG_3, DEG_4 }
static int const seps [MAX_TYPES] = { SEP_0, SEP_1, SEP_2, SEP_3, SEP_4 }
static long randtbl [DEG_3+1]
static long * fptr = &randtbl[SEP_3 + 1]
static long * rptr = &randtbl[1]
static long * state = &randtbl[1]
static int rand_type = TYPE_3
static int rand_deg = DEG_3
static int rand_sep = SEP_3
static long * end_ptr = &randtbl[DEG_3 + 1]


Define Documentation

#define BREAK_0   8

Definition at line 127 of file inet.c.

Referenced by our_initstate().

#define BREAK_1   32

Definition at line 132 of file inet.c.

Referenced by our_initstate().

#define BREAK_2   64

Definition at line 137 of file inet.c.

Referenced by our_initstate().

#define BREAK_3   128

Definition at line 142 of file inet.c.

Referenced by our_initstate().

#define BREAK_4   256

Definition at line 147 of file inet.c.

Referenced by our_initstate().

#define DEG_0   0

Definition at line 128 of file inet.c.

Referenced by our_initstate().

#define DEG_1   7

Definition at line 133 of file inet.c.

Referenced by our_initstate().

#define DEG_2   15

Definition at line 138 of file inet.c.

Referenced by our_initstate().

#define DEG_3   31

Definition at line 143 of file inet.c.

Referenced by our_initstate(), and our_random().

#define DEG_4   63

Definition at line 148 of file inet.c.

 
#define initializeWinsockIfNecessary (  )     1

Definition at line 51 of file inet.c.

#define MAX_TYPES   5

Definition at line 155 of file inet.c.

Referenced by our_initstate(), and our_setstate().

#define NULL   0

Definition at line 55 of file inet.c.

#define SEP_0   0

Definition at line 129 of file inet.c.

Referenced by our_initstate().

#define SEP_1   3

Definition at line 134 of file inet.c.

Referenced by our_initstate().

#define SEP_2   1

Definition at line 139 of file inet.c.

Referenced by our_initstate().

#define SEP_3   3

Definition at line 144 of file inet.c.

Referenced by our_initstate(), and our_random().

#define SEP_4   1

Definition at line 149 of file inet.c.

#define TYPE_0   0

Definition at line 126 of file inet.c.

Referenced by our_initstate(), our_random(), our_setstate(), and our_srandom().

#define TYPE_1   1

Definition at line 131 of file inet.c.

Referenced by our_initstate(), and our_setstate().

#define TYPE_2   2

Definition at line 136 of file inet.c.

Referenced by our_initstate(), and our_setstate().

#define TYPE_3   3

Definition at line 141 of file inet.c.

Referenced by our_initstate(), and our_setstate().

#define TYPE_4   4

Definition at line 146 of file inet.c.

Referenced by our_initstate(), and our_setstate().


Function Documentation

unsigned our_inet_addr ( char const*  cp  ) 

Definition at line 15 of file inet.c.

Referenced by MPEG2TransportUDPServerMediaSubsession::createNewStreamSource(), RTSPServer::RTSPClientSession::handleCmd_SETUP(), main(), NetAddressList::NetAddressList(), ourIPAddress(), and startReplicaUDPSink().

00017 {
00018         return inet_addr(cp);
00019 }

char* our_initstate ( unsigned int  seed,
char *  arg_state,
int  n 
)

Definition at line 268 of file inet.c.

References BREAK_0, BREAK_1, BREAK_2, BREAK_3, BREAK_4, DEG_0, DEG_1, DEG_2, DEG_3, MAX_TYPES, our_srandom(), SEP_0, SEP_1, SEP_2, SEP_3, TYPE_0, TYPE_1, TYPE_2, TYPE_3, and TYPE_4.

00272 {
00273         register char *ostate = (char *)(&state[-1]);
00274 
00275         if (rand_type == TYPE_0)
00276                 state[-1] = rand_type;
00277         else
00278                 state[-1] = MAX_TYPES * (rptr - state) + rand_type;
00279         if (n < BREAK_0) {
00280 #ifdef DEBUG
00281                 (void)fprintf(stderr,
00282                     "random: not enough state (%d bytes); ignored.\n", n);
00283 #endif
00284                 return(0);
00285         }
00286         if (n < BREAK_1) {
00287                 rand_type = TYPE_0;
00288                 rand_deg = DEG_0;
00289                 rand_sep = SEP_0;
00290         } else if (n < BREAK_2) {
00291                 rand_type = TYPE_1;
00292                 rand_deg = DEG_1;
00293                 rand_sep = SEP_1;
00294         } else if (n < BREAK_3) {
00295                 rand_type = TYPE_2;
00296                 rand_deg = DEG_2;
00297                 rand_sep = SEP_2;
00298         } else if (n < BREAK_4) {
00299                 rand_type = TYPE_3;
00300                 rand_deg = DEG_3;
00301                 rand_sep = SEP_3;
00302         } else {
00303                 rand_type = TYPE_4;
00304                 rand_deg = DEG_4;
00305                 rand_sep = SEP_4;
00306         }
00307         state = &(((long *)arg_state)[1]);      /* first location */
00308         end_ptr = &state[rand_deg];     /* must set end_ptr before srandom */
00309         our_srandom(seed);
00310         if (rand_type == TYPE_0)
00311                 state[-1] = rand_type;
00312         else
00313                 state[-1] = MAX_TYPES*(rptr - state) + rand_type;
00314         return(ostate);
00315 }

long our_random ( void   ) 

u_int32_t our_random32 (  ) 

Definition at line 423 of file inet.c.

References our_random().

Referenced by RTSPServer::incomingConnectionHandler(), SIPClient::invite(), and DarwinInjector::setDestination().

00423                          {
00424   /* Return a 32-bit random number.
00425      Because "our_random()" returns a 31-bit random number, we call it a second
00426      time, to generate the high bit.
00427      (Actually, to increase the likelhood of randomness, we take the middle 16 bits of two successive calls to "our_random()")
00428   */
00429   long random_1 = our_random();
00430   u_int32_t random16_1 = (u_int32_t)(random_1&0x00FFFF00);
00431 
00432   long random_2 = our_random();
00433   u_int32_t random16_2 = (u_int32_t)(random_2&0x00FFFF00);
00434 
00435   return (random16_1<<8) | (random16_2>>8);
00436 }

char* our_setstate ( char *  arg_state  ) 

Definition at line 333 of file inet.c.

References MAX_TYPES, TYPE_0, TYPE_1, TYPE_2, TYPE_3, and TYPE_4.

00335 {
00336         register long *new_state = (long *)arg_state;
00337         register int type = new_state[0] % MAX_TYPES;
00338         register int rear = new_state[0] / MAX_TYPES;
00339         char *ostate = (char *)(&state[-1]);
00340 
00341         if (rand_type == TYPE_0)
00342                 state[-1] = rand_type;
00343         else
00344                 state[-1] = MAX_TYPES * (rptr - state) + rand_type;
00345         switch(type) {
00346         case TYPE_0:
00347         case TYPE_1:
00348         case TYPE_2:
00349         case TYPE_3:
00350         case TYPE_4:
00351                 rand_type = type;
00352                 rand_deg = degrees[type];
00353                 rand_sep = seps[type];
00354                 break;
00355         default:
00356 #ifdef DEBUG
00357                 (void)fprintf(stderr,
00358                     "random: state info corrupted; not changed.\n");
00359 #endif
00360                 break;
00361         }
00362         state = &new_state[1];
00363         if (rand_type != TYPE_0) {
00364                 rptr = &state[rear];
00365                 fptr = &state[(rear + rand_sep) % rand_deg];
00366         }
00367         end_ptr = &state[rand_deg];             /* set end_ptr too */
00368         return(ostate);
00369 }

void our_srandom ( unsigned int  x  ) 

Definition at line 231 of file inet.c.

References our_random(), and TYPE_0.

00232 {
00233         register int i;
00234 
00235         if (rand_type == TYPE_0)
00236                 state[0] = x;
00237         else {
00238                 state[0] = x;
00239                 for (i = 1; i < rand_deg; i++)
00240                         state[i] = 1103515245 * state[i - 1] + 12345;
00241                 fptr = &state[rand_sep];
00242                 rptr = &state[0];
00243                 for (i = 0; i < 10 * rand_deg; i++)
00244                         (void)our_random();
00245         }
00246 }


Variable Documentation

int const degrees[MAX_TYPES] = { DEG_0, DEG_1, DEG_2, DEG_3, DEG_4 } [static]

Definition at line 157 of file inet.c.

long* end_ptr = &randtbl[DEG_3 + 1] [static]

Definition at line 215 of file inet.c.

long* fptr = &randtbl[SEP_3 + 1] [static]

Definition at line 198 of file inet.c.

int rand_deg = DEG_3 [static]

Definition at line 213 of file inet.c.

int rand_sep = SEP_3 [static]

Definition at line 214 of file inet.c.

int rand_type = TYPE_3 [static]

Definition at line 212 of file inet.c.

long randtbl[DEG_3+1] [static]

Initial value:

 {
        TYPE_3,
        0x9a319039, 0x32d9c024, 0x9b663182, 0x5da1f342, 0xde3b81e0, 0xdf0a6fb5,
        0xf103bc02, 0x48f340fb, 0x7449e56b, 0xbeb1dbb0, 0xab5c5918, 0x946554fd,
        0x8c2e680f, 0xeb3d799f, 0xb11ee0b7, 0x2d436b86, 0xda672e2a, 0x1588ca88,
        0xe369735d, 0x904f35f7, 0xd7158fd6, 0x6fa6f051, 0x616e6b96, 0xac94efdc,
        0x36413f93, 0xc622c298, 0xf5a42ab8, 0x8a88d77b, 0xf5ad9d0e, 0x8999220b,
        0x27fb47b9,
}

Definition at line 174 of file inet.c.

long* rptr = &randtbl[1] [static]

Definition at line 199 of file inet.c.

int const seps[MAX_TYPES] = { SEP_0, SEP_1, SEP_2, SEP_3, SEP_4 } [static]

Definition at line 158 of file inet.c.

long* state = &randtbl[1] [static]

Definition at line 211 of file inet.c.


Generated on Thu Feb 2 23:51:42 2012 for live by  doxygen 1.5.2