Main Page | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

fakewap.c File Reference

#include <errno.h>
#include <ctype.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <sys/param.h>
#include <signal.h>
#include "gwlib/gwlib.h"

Include dependency graph for fakewap.c:

Include dependency graph

Go to the source code of this file.

Defines

#define MAX_SEND   (0)
#define GET_WTP_PDU_TYPE(hdr)   (hdr[0] >> 3)
#define WTP_PDU_INVOKE   1
#define WTP_PDU_RESULT   2
#define WTP_PDU_ACK   3
#define WTP_PDU_ABORT   4
#define SET_GTR(hdr)   hdr[0] |= 0x04
#define SET_TID(hdr, tid)
#define GET_TID(hdr)   (((hdr[1] & 0x7f) << 8) + hdr[2])
#define CONSTRUCT_EXPECTED_REPLY_HDR(dest, template, tid)
#define min(a, b)   (a < b ? a : b)

Functions

int get_wtp_pdu_type (Octstr *hdr)
void set_tid (Octstr *hdr, int tid)
void set_tid_new (Octstr *hdr)
void print_msg (const char *trace, unsigned char *msg, int msg_len)
void print_data (const char *trace, unsigned char *msg, int msg_len)
char * choose_message (char **urls, int num_urls)
unsigned short next_tid (unsigned short old_tid)
int StoreVarInt (unsigned char *buf, unsigned long varInt)
int ReadVarIntLen (const unsigned char *buf)
int wap_msg_send (int fd, unsigned char *hdr, int hdr_len, unsigned short tid, int tid_new, unsigned char *data, int data_len)
int wap_msg_recv (int fd, const char *hdr, int hdr_len, unsigned short tid, unsigned char *data, int data_len, int timeout)
int get_next_transaction (void)
void client_session (void *arg)
void help (void)
int main (int argc, char **argv)

Variables

char usage []
char ** urls
int num_urls
Octstrhostname = NULL
Octstrgateway_addr = NULL
double interval = 1.0
unsigned short port = 9201
int max_send = 1
unsigned short tid_addition = 1
Mutexmutex
int threads = 1
int num_sent = 0
time_t start_time
time_t end_time
double totaltime = 0 besttime = 1000000L worsttime = 0
int verbose = 0
int nofailexit = 0
int writedata = 0
int test_separation = 0
unsigned char WSP_Connect []
unsigned char WSP_ConnectReply [] = {0x16, 0x80, 0x00, 0x02 }
unsigned char WTP_Ack [] = {0x18, 0x00, 0x00 }
unsigned char WTP_TidVe [] = {0x1C, 0x00, 0x00 }
unsigned char WTP_Abort [] = {0x20, 0x00, 0x00, 0x00 }
unsigned char WSP_Get [] = {0x0E, 0x00, 0x00, 0x02, 0x40 }
unsigned char WSP_Reply [] = {0x16, 0x80, 0x00, 0x04, 0x20 }
unsigned char WSP_Disconnect [] = {0x0E, 0x00, 0x00, 0x00, 0x05 }
unsigned char WSP_Concat [] = {0x00, 0x03, 0x18, 0x00, 0x00, 0x05, 0x0E, 0x00, 0x00, 0x00, 0x05 }


Define Documentation

#define CONSTRUCT_EXPECTED_REPLY_HDR dest,
template,
tid   ) 
 

Value:

if (sizeof(dest) < sizeof(template)) panic(0,"buffer overflow.");\
    memcpy( dest, template, sizeof(template));\
    SET_TID( dest, tid )

Definition at line 245 of file fakewap.c.

Referenced by client_session().

#define GET_TID hdr   )     (((hdr[1] & 0x7f) << 8) + hdr[2])
 

Definition at line 244 of file fakewap.c.

Referenced by wap_msg_recv().

#define GET_WTP_PDU_TYPE hdr   )     (hdr[0] >> 3)
 

Definition at line 179 of file fakewap.c.

Referenced by wap_msg_recv().

#define MAX_SEND   (0)
 

Definition at line 132 of file fakewap.c.

Referenced by client_session(), and get_next_transaction().

#define min a,
 )     (a < b ? a : b)
 

Definition at line 270 of file fakewap.c.

Referenced by wap_msg_recv().

#define SET_GTR hdr   )     hdr[0] |= 0x04
 

Definition at line 240 of file fakewap.c.

#define SET_TID hdr,
tid   ) 
 

Value:

hdr[1] |= (0x7f & ((tid) >> 8)); \
    hdr[2] = (char)(tid)

Definition at line 241 of file fakewap.c.

#define WTP_PDU_ABORT   4
 

Definition at line 187 of file fakewap.c.

#define WTP_PDU_ACK   3
 

Definition at line 186 of file fakewap.c.

Referenced by wap_msg_recv().

#define WTP_PDU_INVOKE   1
 

Definition at line 184 of file fakewap.c.

#define WTP_PDU_RESULT   2
 

Definition at line 185 of file fakewap.c.


Function Documentation

char* choose_message char **  urls,
int  num_urls
[static]
 

Definition at line 308 of file fakewap.c.

References gw_rand(), and urls.

Referenced by client_session(), and main().

00308                                                        {
00309     /* the following doesn't give an even distribution, but who cares */
00310     return urls[gw_rand() % num_urls];
00311 }

Here is the call graph for this function:

void client_session void *  arg  )  [static]
 

Definition at line 520 of file fakewap.c.

References choose_message(), CONSTRUCT_EXPECTED_REPLY_HDR, end_time, get_next_transaction(), info(), interval, MAX_SEND, max_send, mutex, mutex_lock, mutex_unlock, next_tid(), num_urls, panic, ReadVarIntLen(), StoreVarInt(), tid, totaltime, udp_client_socket(), urls, verbose, wap_msg_recv(), wap_msg_send(), WSP_Concat, WSP_Connect, WSP_ConnectReply, WSP_Disconnect, WSP_Get, WSP_Reply, WTP_Abort, and WTP_Ack.

Referenced by main().

00521 {
00522     int fd;
00523     int ret;
00524     int url_len = 0, url_off = 0;
00525     double nowsec, lastsec, tmp, sleepTime;
00526     long    uSleepTime;
00527     struct timeval now;
00528     struct timezone tz;
00529     char * url;
00530     unsigned char  sid[20];
00531     int            sid_len = 0;
00532     unsigned char  buf[64*1024];
00533     unsigned char reply_hdr[32];
00534     long timeout = 10;  /* wap gw is broken if no input */
00535     unsigned short tid = 0;
00536     unsigned short old_tid;
00537     int tid_new = 0;
00538     int connection_retries = 0;
00539     int i_this;
00540 
00541     fd = udp_client_socket();
00542     if (fd == -1)
00543         panic(0, "Couldn't create socket.");
00544 
00545     /*
00546     **  Loop until all URLs have been requested
00547     */
00548     for (;;) {
00549         /*
00550          ** Get start time of this request
00551          */
00552         gettimeofday(&now, &tz);
00553         lastsec = (double) now.tv_sec + now.tv_usec / 1e6;
00554 
00555         /*
00556         **  Get next transaction number or exit if too many transactions
00557         */
00558         i_this = get_next_transaction();
00559         if (max_send != MAX_SEND  && i_this > max_send) break;
00560 
00561         /*
00562         **  Connect, save sid from reply and finally ack the reply
00563         */
00564     old_tid = tid;
00565         tid = next_tid(old_tid);
00566     tid_new = (tid < old_tid);  /* Did we wrap? */
00567         ret = wap_msg_send( fd, WSP_Connect, sizeof(WSP_Connect),
00568                             tid, tid_new, NULL, 0 );
00569 
00570         if (ret == -1) panic(0, "Send WSP_Connect failed");
00571 
00572         CONSTRUCT_EXPECTED_REPLY_HDR( reply_hdr, WSP_ConnectReply, tid );
00573         ret = wap_msg_recv( fd, reply_hdr, sizeof(WSP_ConnectReply),
00574                             tid, buf, sizeof(buf), timeout );
00575 
00576         if (ret == -1) panic(0, "Receive WSP_ConnectReply failed");
00577 
00578         if (ret > 2)
00579         {
00580             sid_len = ReadVarIntLen(buf);
00581             memcpy( sid, buf, sid_len);
00582         }
00583         /*
00584         **  Send abort and continue if we get an unexpected reply
00585         */
00586         if (ret == 0)  {
00587             if (connection_retries++ > 3) {
00588                 panic(0, "Cannot connect WAP GW!");
00589             }
00590             wap_msg_send( fd, WTP_Abort, sizeof(WTP_Abort), tid, tid_new,
00591                           NULL, 0 );
00592             continue;
00593         }
00594         else {
00595             connection_retries = 0;
00596         }
00597         ret = wap_msg_send( fd, WTP_Ack, sizeof(WTP_Ack), tid, tid_new,
00598                             NULL, 0 );
00599 
00600         if (ret == -1) panic(0, "Send WTP_Ack failed");
00601 
00602         /*
00603         **  Request WML page with the given URL
00604         */
00605     old_tid = tid;
00606         tid = next_tid(old_tid);
00607     tid_new = (tid < old_tid);  /* Did we wrap? */
00608         url = choose_message(urls, num_urls);
00609         url_len = strlen(url);
00610         url_off = StoreVarInt( buf, url_len );
00611         memcpy( buf+url_off, url, url_len );
00612         ret = wap_msg_send( fd, WSP_Get, sizeof(WSP_Get), tid, tid_new,
00613                 buf, url_len+url_off );
00614         if (ret == -1) break;
00615 
00616         CONSTRUCT_EXPECTED_REPLY_HDR( reply_hdr, WSP_Reply, tid );
00617         ret = wap_msg_recv( fd, reply_hdr, sizeof(WSP_Reply),
00618                             tid, buf, sizeof(buf), timeout );
00619         if (ret == -1) break;
00620         /*
00621     ** If we are testing separation, we concatenate WTP_Ack and 
00622         ** WSP_Disconnect messages.
00623         */
00624         if (test_separation){
00625            ret = wap_msg_send(fd, WSP_Concat, sizeof(WSP_Concat), tid, tid_new,
00626                  sid, sid_len);
00627            
00628            if (ret == -1) break;
00629         } else {
00630            ret = wap_msg_send( fd, WTP_Ack, sizeof(WTP_Ack), tid, tid_new,
00631                 NULL, 0 );
00632 
00633            if (ret == -1) break;
00634 
00635         /*
00636         **  Finally disconnect with the sid returned by connect reply
00637         */
00638            ret = wap_msg_send( fd, WSP_Disconnect, sizeof(WSP_Disconnect),
00639                     tid, tid_new, sid, sid_len );
00640 
00641            if (ret == -1) break;
00642         }
00643 
00644         /*
00645          ** Get end time of the request
00646          */
00647         gettimeofday(&now, &tz);
00648         nowsec = (double) now.tv_sec + now.tv_usec / 1e6;
00649         tmp = nowsec - lastsec; /* Duration of request */
00650         sleepTime = interval-tmp;   /* Amount of time left to sleep */
00651         uSleepTime = sleepTime * 1e6;
00652 
00653         mutex_lock( mutex );
00654         if (tmp < besttime) besttime = tmp;
00655         if (tmp > worsttime) worsttime = tmp;
00656         totaltime += tmp;
00657         mutex_unlock( mutex );
00658 
00659         if (verbose == 1)
00660         {
00661             info(0, "fakewap: finished session # %d", i_this);
00662         }
00663 
00664         /*
00665          ** If we've done all the requests, then don't bother to sleep
00666          */
00667         if (i_this >= max_send) break;
00668 
00669         if (tmp < (double)interval) {
00670             usleep( uSleepTime );
00671         }
00672     }
00673     close(fd);
00674 
00675     /* The last end_time stays */
00676     mutex_lock( mutex );
00677     time(&end_time);
00678     mutex_unlock( mutex );
00679 }

Here is the call graph for this function:

int get_next_transaction void   )  [static]
 

Definition at line 507 of file fakewap.c.

References MAX_SEND, max_send, mutex, mutex_lock, mutex_unlock, and num_sent.

Referenced by client_session().

00507                                       {
00508     int i_this;
00509     mutex_lock( mutex );
00510     i_this = num_sent + 1;
00511     if (max_send == MAX_SEND || num_sent < max_send) num_sent++;
00512     mutex_unlock( mutex );
00513     return i_this;
00514 }

int get_wtp_pdu_type Octstr hdr  )  [static]
 

Definition at line 180 of file fakewap.c.

References octstr_get_char().

Referenced by wap_msg_send().

00180                                          {
00181     return octstr_get_char(hdr, 0) >> 3;
00182 }

Here is the call graph for this function:

void help void   )  [static]
 

Definition at line 682 of file fakewap.c.

References info(), and usage.

00682                        {
00683     info(0, "\n%s", usage);
00684 }

Here is the call graph for this function:

int main int  argc,
char **  argv
 

Definition at line 689 of file fakewap.c.

References client_session(), end_time, error(), gateway_addr, getopt(), GW_INFO, gwlib_init(), gwlib_shutdown(), gwthread_create, gwthread_join_every(), help(), hostname, info(), interval, log_set_output_level(), max_send, mutex, mutex_create, mutex_destroy(), nofailexit, num_sent, num_urls, octstr_create, octstr_destroy(), optarg, optind, panic, port, srand, start_time, tcl, test_separation, threads, tid_addition, totaltime, udp_create_address(), urls, usage, verbose, writedata, and WSP_Connect.

00690 {
00691     int i, opt;
00692     double delta;
00693     int proto_version, pdu_type, tcl, tid_new;
00694 #ifdef SunOS
00695     struct sigaction alrm;
00696 
00697     alrm.sa_handler = SIG_IGN;
00698 
00699     sigaction(SIGALRM,&alrm,NULL);
00700 #endif
00701     gwlib_init();
00702 
00703     proto_version = 0;
00704     pdu_type = 1;
00705     tcl = 2;
00706     tid_new = 0;
00707 
00708     hostname = octstr_create("localhost");
00709 
00710     while ((opt = getopt(argc, argv, "Fhvc:g:p:P:m:i:t:V:T:t:nsd:w")) != EOF) {
00711     switch (opt) {
00712     case 'g':
00713         octstr_destroy(hostname);
00714         hostname = octstr_create(optarg);
00715         break;
00716 
00717     case 'p':
00718         port = atoi(optarg);
00719         break;
00720 
00721     case 'm':
00722         max_send = atoi(optarg);
00723         break;
00724 
00725     case 'i':
00726         interval = atof(optarg);
00727         break;
00728 
00729     case 'c':
00730         threads = atoi(optarg);
00731         break;
00732 
00733     case 'V':
00734         proto_version = atoi(optarg);
00735         break;
00736 
00737     case 'T':
00738         pdu_type = atoi(optarg);
00739         break;
00740 
00741     case 't':
00742         tcl = atoi(optarg);
00743         break;
00744 
00745     case 'n':
00746         tid_new = 1;
00747         break;
00748 
00749         case 's':
00750         test_separation = 1;
00751             break;
00752 
00753     case 'd':
00754         tid_addition = atoi(optarg);
00755         break;
00756 
00757     case 'v':
00758         verbose = 1;
00759         break;
00760         
00761     case 'h':
00762         help();
00763         exit(0);
00764         break;
00765 
00766     case 'F':
00767         nofailexit=1;
00768         break;
00769 
00770         case 'w':
00771             writedata = 1;
00772             break;
00773 
00774     case '?':
00775     default:
00776         error(0, "Unknown option %c", opt);
00777         help();
00778         panic(0, "Stopping.");
00779     }
00780     }
00781 
00782     time(&start_time);
00783 
00784     if (optind >= argc)
00785         panic(0, "%s", usage);
00786 
00787     if (verbose != 1)
00788     {
00789         log_set_output_level (GW_INFO);
00790     }
00791     WSP_Connect[3] += (proto_version&3)<<6;
00792     WSP_Connect[0] += (pdu_type&15)<<3;
00793     WSP_Connect[3] += tcl&3;
00794     WSP_Connect[3] += (tid_new&1)<<5;
00795     
00796     gateway_addr = udp_create_address(hostname, port);
00797 
00798     urls = argv + optind;
00799     num_urls = argc - optind;
00800 
00801     srand((unsigned int) time(NULL));
00802 
00803     mutex = mutex_create();
00804 
00805     info(0, "fakewap starting");
00806 
00807     if (threads < 1) threads = 1;
00808 
00809     /*
00810     **  Start 'extra' client threads and finally execute the
00811     **  session of main thread
00812     */
00813     for (i = 1; i < threads; i++)
00814         gwthread_create(client_session, NULL);
00815     client_session(NULL);
00816 
00817     /* Wait for the other sessions to complete */
00818     gwthread_join_every(client_session);
00819 
00820     info(0, "fakewap complete.");
00821     info(0, "fakewap: %d client threads made total %d transactions.", 
00822         threads, num_sent);
00823     delta = difftime(end_time, start_time);
00824     info( 0, "fakewap: total running time %.1f seconds", delta);
00825     info( 0, "fakewap: %.1f messages/seconds on average", num_sent / delta);
00826     info( 0, "fakewap: time of best, worst and average transaction: "
00827              "%.1f s, %.1f s, %.1f s",
00828          besttime, worsttime, totaltime / num_sent );
00829 
00830     octstr_destroy(hostname);
00831     octstr_destroy(gateway_addr);
00832     mutex_destroy(mutex);
00833     gwlib_shutdown();
00834     return 0;
00835 }

Here is the call graph for this function:

unsigned short next_tid unsigned short  old_tid  )  [static]
 

Definition at line 316 of file fakewap.c.

Referenced by client_session().

00316                                                        { 
00317     return (old_tid + tid_addition) % (1 << 15);
00318 }

void print_data const char *  trace,
unsigned char *  msg,
int  msg_len
[static]
 

Definition at line 293 of file fakewap.c.

References mutex, mutex_lock, mutex_unlock, and verbose.

Referenced by wap_msg_recv().

00294                               {
00295     int i;
00296 
00297     if (verbose || writedata) {
00298         mutex_lock( mutex );
00299         printf( "%s (len %d): ", trace, msg_len );
00300         for (i = 0; i < msg_len && i < msg_len; i++)
00301              printf( "%c", isprint(msg[i]) ? msg[i] : '_');
00302         printf( "\n");
00303         mutex_unlock( mutex );
00304     }
00305 }

void print_msg const char *  trace,
unsigned char *  msg,
int  msg_len
[static]
 

Definition at line 278 of file fakewap.c.

References mutex, mutex_lock, and mutex_unlock.

00279                               {
00280     int i;
00281     if (verbose) {
00282         mutex_lock( mutex );
00283         printf( "%s (len %d): ", trace, msg_len );
00284         for (i = 0; i < msg_len && i < 16; i++) printf( "%02X ", msg[i] );
00285         printf( "\n");
00286         mutex_unlock( mutex );
00287     }
00288 }

int ReadVarIntLen const unsigned char *  buf  )  [static]
 

Definition at line 352 of file fakewap.c.

Referenced by client_session().

00353 {
00354     int    len = 1;
00355 
00356     while (buf[len-1] & 0x80) len++;
00357     return len;
00358 }

void set_tid Octstr hdr,
int  tid
[static]
 

Definition at line 250 of file fakewap.c.

References octstr_get_char(), octstr_set_char(), and tid.

Referenced by handle_connect_reply(), handle_get_reply(), send_invoke_connect(), send_invoke_disconnect(), send_invoke_get(), and wap_msg_send().

00250                                           {
00251     int c;
00252     
00253     c = octstr_get_char(hdr, 1);
00254     c |= 0x7f & (tid >> 8);
00255     octstr_set_char(hdr, 1, c);
00256     octstr_set_char(hdr, 2, (unsigned char) tid);
00257 }

Here is the call graph for this function:

void set_tid_new Octstr hdr  )  [static]
 

Definition at line 260 of file fakewap.c.

References octstr_get_char(), and octstr_set_char().

Referenced by wap_msg_send().

00260                                      {
00261     int c;
00262 
00263     c = octstr_get_char(hdr, 3);
00264     c |= 0x40;
00265     octstr_set_char(hdr, 3, c);
00266 }

Here is the call graph for this function:

int StoreVarInt unsigned char *  buf,
unsigned long  varInt
[static]
 

Definition at line 325 of file fakewap.c.

Referenced by client_session().

00326 {
00327     int i, len = 1, non_zero_bits = 7;
00328 
00329     /*
00330     **    Skip all zero high bits
00331     */
00332     while ((varInt >> non_zero_bits) != 0) {
00333         non_zero_bits += 7;
00334         len++;
00335     }
00336     /*
00337     **    Read the higest bits first.
00338     */
00339     for (i = 0; i < len; i++)
00340     {
00341         buf[i] = ((unsigned char)(varInt >> (non_zero_bits-7)) & 0x7f) | 0x80;
00342         non_zero_bits -= 7;
00343     }
00344     buf[len-1] &= 0x7f;
00345     return len;
00346 }

int wap_msg_recv int  fd,
const char *  hdr,
int  hdr_len,
unsigned short  tid,
unsigned char *  data,
int  data_len,
int  timeout
[static]
 

Definition at line 417 of file fakewap.c.

References data, error(), GET_TID, GET_WTP_PDU_TYPE, info(), min, octstr_destroy(), octstr_get_many_chars(), octstr_len(), print_data(), print_msg(), read_available(), tid, udp_recvfrom(), wap_msg_send(), WTP_PDU_ACK, and WTP_TidVe.

Referenced by client_session().

00420 {
00421     int ret;
00422     unsigned char msg[1024*64];
00423     int msg_len = 0;
00424     int    fResponderIsDead = 1;  /* assume this by default */
00425     Octstr *datagram, *dummy;
00426 
00427     /*
00428     **  Loop until we get the expected response or do timeout
00429     */
00430     for (;;)
00431     {
00432         if (timeout != 0)
00433         {
00434         ret = read_available(fd, timeout * 1000 * 1000);
00435         if (ret <= 0) {
00436                 info(0, "Timeout while receiving from socket.\n");
00437         if(nofailexit){
00438             continue;
00439         }else{
00440             return fResponderIsDead ? -1 : 0;
00441         }
00442         /* continue if we got ack? */
00443         }
00444         }
00445     
00446     ret = udp_recvfrom(fd, &datagram, &dummy);
00447     if (ret == 0) {
00448         octstr_get_many_chars(msg, datagram, 0, octstr_len(datagram));
00449         msg_len = octstr_len(datagram);
00450     }
00451     octstr_destroy(datagram);
00452     octstr_destroy(dummy);
00453 
00454         if (ret == -1) {
00455             error(0, "recv() from socket failed");
00456             return -1;
00457         }
00458 
00459         if (hdr != NULL) {
00460             /*
00461             **  Ignore extra header bits, WAP GWs return different values
00462             */
00463             if (msg_len >= hdr_len &&
00464                 GET_WTP_PDU_TYPE(msg) == GET_WTP_PDU_TYPE(hdr) &&
00465                 (hdr_len <= 3 || !memcmp( msg+3, hdr+3, hdr_len-3 ))) {
00466                 break;
00467             }
00468             /*
00469             **  Handle TID test, the answer is: Yes, we have an outstanding
00470             **  transaction with this tid. We must turn on TID_OK-flag, too.
00471             **  We have a separate tid verification PDU.
00472             */
00473             else if (GET_WTP_PDU_TYPE(msg) == WTP_PDU_ACK &&
00474                      GET_TID(msg) == tid) {
00475                 print_msg( "Received tid verification", msg, msg_len );
00476                 wap_msg_send( fd, WTP_TidVe, sizeof(WTP_TidVe), tid, 0,
00477                               NULL, 0 );
00478             }
00479             else if (GET_WTP_PDU_TYPE(msg) == WTP_PDU_ABORT) {
00480                 print_msg( "Received WTP Abort", msg, msg_len );
00481             }
00482             else if (GET_WTP_PDU_TYPE(msg) == WTP_PDU_RESULT) {
00483                break;
00484             }
00485             else {
00486                 print_msg( "Received unexpected message", msg, msg_len );
00487             }
00488             fResponderIsDead = 0;
00489         }
00490         else {
00491             hdr_len = 0;
00492             break;
00493         }
00494     }
00495     print_msg( "Received packet", msg, msg_len );
00496     print_data( "Received data", msg, msg_len );
00497 
00498     if (data != NULL && msg_len > hdr_len) {
00499         data_len = min( data_len, msg_len - hdr_len );
00500         memcpy( data, msg+hdr_len, data_len);
00501     }
00502     else  data_len = 0;
00503     return data_len;
00504 }

Here is the call graph for this function:

int wap_msg_send int  fd,
unsigned char *  hdr,
int  hdr_len,
unsigned short  tid,
int  tid_new,
unsigned char *  data,
int  data_len
[static]
 

Definition at line 365 of file fakewap.c.

References data, debug(), error(), gateway_addr, get_wtp_pdu_type(), octstr_append_data(), octstr_create, octstr_destroy(), octstr_dump, octstr_get_char(), octstr_set_char(), set_tid(), set_tid_new(), tid, and udp_sendto().

Referenced by client_session(), and wap_msg_recv().

00368 {
00369     int ret;
00370     Octstr *datagram;
00371 
00372     datagram = octstr_create("");
00373     if (hdr != NULL)
00374         octstr_append_data(datagram, hdr, hdr_len);
00375 
00376     set_tid(datagram, tid);
00377     if (get_wtp_pdu_type(datagram) == WTP_PDU_INVOKE) {
00378     /* request ack every time */
00379     int c;
00380     c = octstr_get_char(datagram, 3);
00381     octstr_set_char(datagram, 3, c | 0x10);
00382     if (tid_new)
00383         set_tid_new(datagram);
00384     }
00385 
00386     if (data != NULL)
00387     octstr_append_data(datagram, data, data_len);
00388     
00389 #if 0
00390     debug("fakewap", 0, "Sending WDP datagram:");
00391     octstr_dump(datagram, 0);
00392 #endif
00393     ret = udp_sendto(fd, datagram, gateway_addr);
00394 
00395     if (ret == -1) {
00396         error(0, "Sending to socket failed");
00397         return -1;
00398     }
00399 
00400     if (verbose) {
00401     debug("", 0, "Sent packet:");
00402     octstr_dump(datagram, 0);
00403     }
00404     octstr_destroy(datagram);
00405     return ret;
00406 }

Here is the call graph for this function:


Variable Documentation

time_t end_time
 

Definition at line 204 of file fakewap.c.

Referenced by at2_wait_line(), at2_wait_modem_command(), client_session(), and main().

Octstr* gateway_addr = NULL
 

Definition at line 196 of file fakewap.c.

Referenced by main(), and wap_msg_send().

Octstr* hostname = NULL
 

Definition at line 195 of file fakewap.c.

Referenced by cimd_open(), http_use_proxy(), main(), ois_open(), tcpip_connect_nb_to_server(), tcpip_connect_nb_to_server_with_port(), tcpip_connect_to_server(), and tcpip_connect_to_server_with_port().

double interval = 1.0
 

Definition at line 197 of file fakewap.c.

Referenced by client_session(), client_thread(), gen_data(), gwtimer_start(), main(), and main_loop().

int max_send = 1
 

Definition at line 199 of file fakewap.c.

Referenced by client_session(), get_next_transaction(), and main().

Mutex* mutex
 

Definition at line 201 of file fakewap.c.

Referenced by client_session(), get_next_transaction(), main(), mutex_create_real(), mutex_destroy(), mutex_init_static_real(), mutex_lock_real(), mutex_trylock_real(), mutex_unlock_real(), print_data(), and print_msg().

int nofailexit = 0
 

Definition at line 207 of file fakewap.c.

Referenced by main().

int num_sent = 0
 

Definition at line 203 of file fakewap.c.

Referenced by get_next_transaction(), and main().

int num_urls
 

Definition at line 193 of file fakewap.c.

Referenced by client_session(), main(), and start_request().

unsigned short port = 9201
 

Definition at line 198 of file fakewap.c.

Referenced by accept_thread(), add_service(), addr_tuple_change_cliport(), build_request(), client(), client_thread(), conn_open_ssl(), conn_open_ssl_nb(), conn_open_tcp(), conn_open_tcp_nb(), conn_open_tcp_nb_with_port(), conn_open_tcp_with_port(), conn_pool_get(), conn_pool_key(), conn_pool_put(), connect_to_bearerbox(), connect_to_bearerbox_real(), find_client(), get_connection(), handle_internal_event(), http_accept_request(), http_open_port(), http_open_port_if(), http_thread(), http_use_proxy(), main(), make_server_socket(), pack_server_address(), port_add(), port_get_request(), port_key(), port_remove(), run_connects(), server(), smsboxc_run(), smsc_open(), smsc_smpp_create(), start_http_thread(), tcpip_connect_nb_to_server(), tcpip_connect_nb_to_server_with_port(), tcpip_connect_to_server(), tcpip_connect_to_server_with_port(), udp_bind(), udp_create_address(), udpc_create(), usage(), wait_for_client(), and wapboxc_run().

time_t start_time
 

Definition at line 204 of file fakewap.c.

Referenced by main(), and main_loop().

int test_separation = 0
 

Definition at line 209 of file fakewap.c.

Referenced by main().

int threads = 1
 

Definition at line 202 of file fakewap.c.

Referenced by main().

unsigned short tid_addition = 1
 

Definition at line 200 of file fakewap.c.

Referenced by main().

double totaltime = 0 besttime = 1000000L worsttime = 0
 

Definition at line 205 of file fakewap.c.

Referenced by client_session(), and main().

char** urls
 

Definition at line 192 of file fakewap.c.

Referenced by choose_message(), client_session(), main(), and start_request().

char usage[] [static]
 

Initial value:

 "\
Usage: fakewap [options] url ...\n\
\n\
where options are:\n\
\n\
-h      help\n\
-v      verbose\n\
-g hostname hostname or IP number of gateway (default: localhost)\n\
-p port     port number of gateway (default: 9201)\n\
-m max      maximum number of requests fakewap will make (default: 1)\n\
-i interval interval between requests (default: 1.0 seconds)\n\
-c threads  number of concurrent clients simulated (default: 1)\n\
-V protoversion protocol version field, as an integer (default: 0)\n\
-T pdu-type PDU type, as an integer (default: 1)\n\
-t tcl      transaction class, as an integer (default: 2)\n\
-n      set tid_new flag in packets, forces gateway to flush cache\n\
                (default: off)\n\
-s              test separation, by concatenating ack and disconnect pdus\n\
                (default: off)\n\
-d difference   difference between successive tid numbers (default: 1)\n\
-F      Accept failure and continue rather than exiting\n\
-w      Write/print received data (experimental)\n\
\n\
The urls are fetched in random order.\n\
"

Definition at line 134 of file fakewap.c.

Referenced by help(), and main().

int verbose = 0
 

Definition at line 206 of file fakewap.c.

Referenced by client_session(), main(), and print_data().

int writedata = 0
 

Definition at line 208 of file fakewap.c.

Referenced by main().

unsigned char WSP_Concat[] = {0x00, 0x03, 0x18, 0x00, 0x00, 0x05, 0x0E, 0x00, 0x00, 0x00, 0x05 }
 

Definition at line 235 of file fakewap.c.

Referenced by client_session().

unsigned char WSP_Connect[]
 

Initial value:

 {0x06, 0x00, 0x00, 0x00, 
                
                0x01, 
                0x10, 
                0x00, 
                0x02, 
                
                
                0x80, 0x80 
                }

Definition at line 216 of file fakewap.c.

Referenced by client_session(), and main().

unsigned char WSP_ConnectReply[] = {0x16, 0x80, 0x00, 0x02 }
 

Definition at line 226 of file fakewap.c.

Referenced by client_session().

unsigned char WSP_Disconnect[] = {0x0E, 0x00, 0x00, 0x00, 0x05 }
 

Definition at line 234 of file fakewap.c.

Referenced by client_session().

unsigned char WSP_Get[] = {0x0E, 0x00, 0x00, 0x02, 0x40 }
 

Definition at line 230 of file fakewap.c.

Referenced by client_session().

unsigned char WSP_Reply[] = {0x16, 0x80, 0x00, 0x04, 0x20 }
 

Definition at line 233 of file fakewap.c.

Referenced by client_session().

unsigned char WTP_Abort[] = {0x20, 0x00, 0x00, 0x00 }
 

Definition at line 229 of file fakewap.c.

Referenced by client_session().

unsigned char WTP_Ack[] = {0x18, 0x00, 0x00 }
 

Definition at line 227 of file fakewap.c.

Referenced by client_session().

unsigned char WTP_TidVe[] = {0x1C, 0x00, 0x00 }
 

Definition at line 228 of file fakewap.c.

Referenced by wap_msg_recv().

See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.