Annotation of mstools/samples/nwlink/testlib/cmdline.c, revision 1.1

1.1     ! root        1: /****************************************************************************\
        !             2: *  cmdline.c -- sample program library demonstrating NWLink.
        !             3: *
        !             4: *       Microsoft Developer Support
        !             5: *       Copyright (c) 1992, 1993 Microsoft Corporation
        !             6: *
        !             7: *  Demonstrates basic sockets programming with the Windows Sockets API
        !             8: *  using the NWLink transport.
        !             9: * 
        !            10: ****************************************************************************/
        !            11: #include <stdio.h>
        !            12: #include <stdlib.h>
        !            13: #include <windows.h>
        !            14: #include <winsock.h>
        !            15: #include <string.h>
        !            16: #include <stdlib.h>
        !            17: #include <ctype.h>
        !            18: #include "externs.h"
        !            19: #include <wsipx.h>
        !            20: #include "testlib.h"
        !            21: 
        !            22: /*
        !            23: *   Global variables that can be set on the command line 
        !            24: */
        !            25: 
        !            26: int     verbose = 0;
        !            27: int     Socket_Type = SOCK_DGRAM;
        !            28: int     Protocol = NSPROTO_IPX;
        !            29: int     Backlog = 1;
        !            30: int     No_Broadcast = 0;
        !            31: int     No_Loop = 0;
        !            32: int     Sleep_Time = 250;
        !            33: int     Send_Length = 1024;
        !            34: int     Receive_Length = 1024;
        !            35: int     Local_Packet_Type = 0;
        !            36: int     Send_Packet_Type = 9;
        !            37: int     Filter_Packet_Type = 0;
        !            38: int     Local_Address_Family = AF_NS;
        !            39: int     Remote_Address_Family = AF_NS;
        !            40: char    Local_Network_Number[4]  = {0x00, 0x00, 0x00, 0x00};
        !            41: char    Local_Node_Number[6]     = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
        !            42: char    Local_Socket_Number[2]   = {0x00, 0x00};
        !            43: char    Remote_Network_Number[4] = {0x00, 0x00, 0x00, 0x00};
        !            44: char    Remote_Node_Number[6]    = "\xFF\xFF\xFF\xFF\xFF\xFF";
        !            45: char    Remote_Socket_Number[2]  = {0x12, 0x34};
        !            46: 
        !            47: /*
        !            48: *   Function prototypes for this file 
        !            49: */
        !            50: 
        !            51: void  usage(LPSTR);
        !            52: void  dump_defaults(LPSTR);
        !            53: void  get_hex_string(LPSTR, LPSTR, int);
        !            54: UCHAR get_hex_byte(char);
        !            55: 
        !            56: /****************************************************************************
        !            57: *
        !            58: *    FUNCTION:  parse_cmd_line( int argc, char **argv )
        !            59: *
        !            60: *    DESCRIPTION:  Routine used by all of the WinSock test programs for NWLink.
        !            61: *            Parses the command line and sets the respective global variables. 
        !            62: *
        !            63: *    ARGUMENTS:         char **     => array of command line arguments
        !            64: *                int         number of command line arguments
        !            65: *
        !            66: *       RETURNS:  nothing
        !            67: *
        !            68: *\***************************************************************************/
        !            69: void parse_cmd_line(int argc, char **argv)
        !            70: {
        !            71:     LPSTR p;
        !            72:     int num = 1;
        !            73: 
        !            74:     argc--;
        !            75: 
        !            76:     /*
        !            77:     *   Parse each command line parameter 
        !            78:     */
        !            79: 
        !            80:     while (num <= argc) {
        !            81:         /*
        !            82:         *   If option starts with '-' or '/', skip it 
        !            83:         */
        !            84: 
        !            85:         p = strupr(argv[num++]);
        !            86:         if (*p == '-' || *p == '/')
        !            87:             p++;
        !            88: 
        !            89:         /*
        !            90:         *   Help ? 
        !            91:         */
        !            92: 
        !            93:         printf("***> command: %s\n:",p);
        !            94:         if (*p == 'h' || *p == 'H' || *p == '?' || !stricmp(p, "help"))
        !            95:            usage(argv[0]);
        !            96: 
        !            97:         /*
        !            98:         *   Verbose option? 
        !            99:         */
        !           100: 
        !           101:         if (!stricmp(p, "v") || !stricmp(p, "verbose")) {
        !           102:             verbose++;
        !           103: 
        !           104:             printf("verbose is ON\n");
        !           105:             continue;
        !           106:         }
        !           107: 
        !           108:         /*
        !           109:         *   Display default values ? 
        !           110:         */
        !           111: 
        !           112:         if (!strnicmp(p, "default", 7)) {
        !           113:             p+= 7;
        !           114: 
        !           115:             dump_defaults(argv[0]);
        !           116:         }
        !           117: 
        !           118:         /*
        !           119:         *   Local address family ? 
        !           120:         */
        !           121: 
        !           122:         if (!strnicmp(p, "laf:", 4)) {
        !           123:             p+= 4;
        !           124: 
        !           125:             /*
        !           126:             *   Get the address family from the option 
        !           127:             */
        !           128: 
        !           129:             Local_Address_Family = atoi(p);
        !           130: 
        !           131:             if (verbose)
        !           132:                 printf("Local_Address_Family = %d\n", Local_Address_Family);
        !           133:             continue;
        !           134:         }
        !           135: 
        !           136:         /*
        !           137:         *   Remote address family ? 
        !           138:         */
        !           139: 
        !           140:         if (!strnicmp(p, "raf:", 4)) {
        !           141:             p+= 4;
        !           142: 
        !           143:             /*
        !           144:             *   Get the address family from the option 
        !           145:             */
        !           146: 
        !           147:             Remote_Address_Family = atoi(p);
        !           148: 
        !           149:             if (verbose)
        !           150:                 printf("Remote_Address_Family = %d\n", Remote_Address_Family);
        !           151:             continue;
        !           152:         }
        !           153: 
        !           154:         /*
        !           155:         *   Socket type ? 
        !           156:         */
        !           157: 
        !           158:         if (!strnicmp(p, "st:", 3)) {
        !           159:             p+= 3;
        !           160: 
        !           161:             /*
        !           162:             *   Get the socket type from the option 
        !           163:             */
        !           164: 
        !           165:             Socket_Type = atoi(p);
        !           166:             if (verbose)
        !           167:                printf("Socket_Type = %d\n", Socket_Type);
        !           168:             continue;
        !           169:         }
        !           170: #if(0)
        !           171:         /*
        !           172:         *   Socket family ? 
        !           173:         */
        !           174: 
        !           175:         if (!strnicmp(p, "sf:", 3)) {
        !           176:             p+= 3;
        !           177: 
        !           178:             /*
        !           179:             *   Get the socket family from the option 
        !           180:             */
        !           181: 
        !           182:             Socket_Family = get_socket_family(p);
        !           183:             continue;
        !           184:         }
        !           185: #endif
        !           186:         /*
        !           187:         *   Protocol ? 
        !           188:         */
        !           189: 
        !           190:         if (!strnicmp(p, "proto:", 6)) {
        !           191:             p+= 6;
        !           192: 
        !           193:             /*
        !           194:             *   Get the protocol from the option 
        !           195:             */
        !           196: 
        !           197:             Protocol = atoi(p);
        !           198: 
        !           199:             if (verbose)
        !           200:                printf("Protocol = %d\n", Protocol);
        !           201:             continue;
        !           202:         }
        !           203: 
        !           204:         /*
        !           205:         *   Local network number ? 
        !           206:         */
        !           207: 
        !           208:         if (!strnicmp(p, "lnet:", 5)) {
        !           209:             p+= 5;
        !           210: 
        !           211:             /*
        !           212:             *   Get the local network number from the option 
        !           213:             */
        !           214: 
        !           215:             memcpy(Local_Network_Number, get_network_number(p), 4);
        !           216:             if (verbose) {
        !           217:                 printf("Local_Network_Number = ");
        !           218:                 print_network_num(Local_Network_Number);
        !           219:                 printf("\n");
        !           220:             }
        !           221:             continue;
        !           222:         }
        !           223: 
        !           224: 
        !           225:         /*
        !           226:         *   Local node number ? 
        !           227:         */
        !           228: 
        !           229:         if (!strnicmp(p, "lnode:", 6)) {
        !           230:             p+= 6;
        !           231: 
        !           232:             /*
        !           233:             *   Get the local network number from the option 
        !           234:             */
        !           235: 
        !           236:             memcpy(Local_Node_Number, get_node_number(p), 6);
        !           237:             if (verbose) {
        !           238:                 printf("Local_Node_Number = ");
        !           239:                print_node_num(Local_Node_Number);
        !           240:                 printf("\n");
        !           241:             }
        !           242:             continue;
        !           243:         }
        !           244: 
        !           245:         /*
        !           246:         *   Remote network number ? 
        !           247:         */
        !           248: 
        !           249:         if (!strnicmp(p, "rnet:", 5)) {
        !           250:             p+= 5;
        !           251: 
        !           252:             /*
        !           253:             *   Get the remote network number from the option 
        !           254:             */
        !           255: 
        !           256:             memcpy(Remote_Network_Number, get_network_number(p), 4);
        !           257:             if (verbose) {
        !           258:                 printf("Remote_Network_Number = ");
        !           259:                 print_network_num(Remote_Network_Number);
        !           260:                 printf("\n");
        !           261:             }
        !           262:             continue;
        !           263:         }
        !           264: 
        !           265:         /*
        !           266:         *   Remote node number ? 
        !           267:         */
        !           268: 
        !           269:         if (!strnicmp(p, "rnode:", 6)) {
        !           270:             p+= 6;
        !           271: 
        !           272:             /*
        !           273:             *   Get the remote network number from the option 
        !           274:             */
        !           275: 
        !           276:             memcpy(Remote_Node_Number, get_node_number(p), 6);
        !           277:             if (verbose) {
        !           278:                 printf("Remote_Node_Number = ");
        !           279:                print_node_num(Remote_Node_Number);
        !           280:                 printf("\n");
        !           281:             }
        !           282:             continue;
        !           283:         }
        !           284: 
        !           285:         /*
        !           286:         *   Local socket number ? 
        !           287:         */
        !           288: 
        !           289:         if (!strnicmp(p, "lsock:", 6)) {
        !           290:             p+= 6;
        !           291: 
        !           292:             /*
        !           293:             *   Get the local socket number from the command line 
        !           294:             */
        !           295: 
        !           296:             memcpy(Local_Socket_Number, get_socket_number(p), 2);
        !           297: 
        !           298:            if (verbose) {
        !           299:                 printf("Local_Socket_Number = ");
        !           300:                 print_socket_num(Local_Socket_Number);
        !           301:                 printf("\n");
        !           302:             }
        !           303:             continue;
        !           304:         }
        !           305: 
        !           306:         /*
        !           307:         *   Remote socket number ? 
        !           308:         */
        !           309: 
        !           310:         if (!strnicmp(p, "rsock:", 6)) {
        !           311:             p+= 6;
        !           312: 
        !           313:             /*
        !           314:             *   Get the remote socket number from the command line 
        !           315:             */
        !           316: 
        !           317:             memcpy(Remote_Socket_Number, get_socket_number(p), 2);
        !           318: 
        !           319:            if (verbose) {
        !           320:                 printf("Remote_Socket_Number = ");
        !           321:                 print_socket_num(Remote_Socket_Number);
        !           322:                 printf("\n");
        !           323:             }
        !           324:             continue;
        !           325:         }
        !           326: 
        !           327: 
        !           328:         /*
        !           329:         *   Send length ? 
        !           330:         */
        !           331: 
        !           332:         if (!strnicmp(p, "sendlen:", 8)) {
        !           333:             p+= 8;
        !           334: 
        !           335:             /*
        !           336:             *   Get the amount of data to send from the command line 
        !           337:             */
        !           338: 
        !           339:             Send_Length = atoi(p);
        !           340:             if (verbose)
        !           341:                 printf("Send length = %d\n", Send_Length);
        !           342: 
        !           343:             continue;
        !           344:         }
        !           345: 
        !           346:         /*
        !           347:         *   Receive length ? 
        !           348:         */
        !           349: 
        !           350:         if (!strnicmp(p, "recvlen:", 8)) {
        !           351:             p+= 8;
        !           352: 
        !           353:             /*
        !           354:             *   Get the amount of data to send from the command line 
        !           355:             */
        !           356: 
        !           357:             Receive_Length = atoi(p);
        !           358:             if (verbose)
        !           359:                 printf("Receive length = %d\n", Receive_Length);
        !           360: 
        !           361:             continue;
        !           362:         }
        !           363: 
        !           364:         /*
        !           365:         *   Send packet type ? 
        !           366:         */
        !           367: 
        !           368:         if (!strnicmp(p, "sptype:", 7)) {
        !           369:            p+= 7;
        !           370: 
        !           371:             /*
        !           372:             *   Get the packet type from the command line 
        !           373:             */
        !           374: 
        !           375:             Send_Packet_Type = atoi(p);
        !           376: 
        !           377:            if (verbose)
        !           378:                printf("Send_Packet_Type = %d\n", Send_Packet_Type);
        !           379:             continue;
        !           380:         }
        !           381: 
        !           382:         /*
        !           383:         *   Local packet type ? 
        !           384:         */
        !           385: 
        !           386:         if (!strnicmp(p, "lptype:", 7)) {
        !           387:            p+= 7;
        !           388: 
        !           389:             /*
        !           390:             *   Get the packet type from the command line 
        !           391:             */
        !           392: 
        !           393:             Local_Packet_Type = atoi(p);
        !           394: 
        !           395:            if (verbose)
        !           396:                printf("Send_Packet_Type = %d\n", Send_Packet_Type);
        !           397:             continue;
        !           398:         }
        !           399: 
        !           400:         /*
        !           401:         *   Filter packet type ? 
        !           402:         */
        !           403: 
        !           404:         if (!strnicmp(p, "fptype:", 7)) {
        !           405:            p+= 7;
        !           406: 
        !           407:             /*
        !           408:             *   Get the packet type from the command line 
        !           409:             */
        !           410: 
        !           411:             Filter_Packet_Type = atoi(p);
        !           412: 
        !           413:            if (verbose)
        !           414:                printf("Filter_Packet_Type = %d\n", Send_Packet_Type);
        !           415:             continue;
        !           416:         }
        !           417: 
        !           418:         /*
        !           419:         *   Backlog size ? 
        !           420:         */
        !           421: 
        !           422:         if (!strnicmp(p, "backlog:", 8)) {
        !           423:            p+= 8;
        !           424: 
        !           425:             Backlog = atoi(p);
        !           426: 
        !           427:             if (verbose)
        !           428:                 printf("Backlog = %d\n", Backlog);
        !           429:             continue;
        !           430:         }
        !           431: 
        !           432:         /*
        !           433:         *   No broadcast flag ? 
        !           434:         */
        !           435: 
        !           436:         if (!strnicmp(p, "nobcast", 7)) {
        !           437:             p+= 7;
        !           438: 
        !           439:             No_Broadcast++;
        !           440: 
        !           441:             if (verbose)
        !           442:                 printf("No broadcast flag is set\n");
        !           443: 
        !           444:             continue;
        !           445:         }
        !           446: 
        !           447:         /*
        !           448:         *   No loop flag ? 
        !           449:         */
        !           450: 
        !           451:         if (!strnicmp(p, "noloop", 6)) {
        !           452:             p+= 6;
        !           453: 
        !           454:             No_Loop++;
        !           455: 
        !           456:             if (verbose)
        !           457:                 printf("No loop flag is set\n");
        !           458: 
        !           459:             continue;
        !           460:         }
        !           461: 
        !           462:         /*
        !           463:         *   Sleep time ? 
        !           464:         */
        !           465: 
        !           466:         if (!strnicmp(p, "sleep:", 6)) {
        !           467:             p+= 6;
        !           468: 
        !           469:             Sleep_Time = atoi(p);
        !           470: 
        !           471:             if (verbose)
        !           472:                 printf("Sleep time = %d\n", Sleep_Time);
        !           473: 
        !           474:             continue;
        !           475:         }
        !           476: 
        !           477: 
        !           478:         if (*p)
        !           479:             printf("Unknown command line parameter: %s\n", p);
        !           480: 
        !           481:     } /* while */
        !           482: 
        !           483:     if (verbose)
        !           484:         printf("\n\n");
        !           485: }
        !           486: 
        !           487: /****************************************************************************
        !           488: *
        !           489: *    FUNCTION:  usage( LPSTR progname )
        !           490: *
        !           491: *    PURPOSE:   Displays all allowable command line parameters.  (All may not be used
        !           492: *                  by the program linking to this library, however).
        !           493: *
        !           494: *    ARGUMENTS:        LPSTR   => program name
        !           495: *
        !           496: *       RETURNS:   exits with errorlevel 0
        !           497: *
        !           498: *\***************************************************************************/
        !           499: void usage(LPSTR progname)
        !           500: {
        !           501:     printf("\n\nUsage: %s [options]\n", progname);
        !           502:     printf("\n");
        !           503:     printf("Valid options are:\n");
        !           504:     printf("-v               Toggles verbose mode ON\n");
        !           505:     printf("-laf:x           Sets local address family to x\n");
        !           506:     printf("-raf:x           Sets remote address family to x\n");
        !           507:     printf("-st:x            Sets socket type to x\n");
        !           508:     printf("-proto:x         Sets protocol to x\n");
        !           509:     printf("-sleep:x         Sets sleep time between sends to x milliseconds\n");
        !           510:     printf("-backlog:x       Sets listen backlog size to x indications\n");
        !           511:     printf("-nobcast         Sets flag so program won't set sockopt to broadcast\n");
        !           512:     printf("-noloop          Sets flag so program won't loop\n");
        !           513:     printf("-sptype:x        Sets send packet type to x\n");
        !           514:     printf("-lptype:x        Sets local packet type to x\n");
        !           515:     printf("-fptype:x        Sets filter for incoming packet type x\n");
        !           516:     printf("-sendlen:x       Sets amount of data to send to x bytes\n");
        !           517:     printf("-recvlen:x       Sets amount of data to receive to x bytes\n");
        !           518:     printf("-lnet:xxxx       Sets local network number to xxxx (1)\n");
        !           519:     printf("-lnode:xxxxxx    Sets local node number to xxxxxx (1)\n");
        !           520:     printf("-rnet:xxxx       Sets remote network number to xxxx (1)\n");
        !           521:     printf("-rnode:xxxxxx    Sets remote node number to xxxxxx (1)\n");
        !           522:     printf("-rsock:xx        Sets remote socket number to xx (1)\n");
        !           523:     printf("-default         Displays programs default values\n");
        !           524:     printf("-?, -help, or -h Displays this screen\n");
        !           525:     printf("\n");
        !           526:     printf("Notes:  (1) Network numbers (network, node, and socket) must\n");
        !           527:     printf("            be specified as a series of hexadecimal numbers,\n");
        !           528:     printf("            for example: -lnet:04003BFF. \n");
        !           529:     printf("\n");
        !           530:     printf("        All values must come immediately after the ':'\n");
        !           531:     printf("        -default and/or -v should be first\n");
        !           532:     printf("        Not all programs make use of all the above parameters\n");
        !           533: 
        !           534:     exit(0);
        !           535: }
        !           536: 
        !           537: /****************************************************************************
        !           538: *
        !           539: *    FUNCTION:  dump_defaults( LPSTR progname )
        !           540: *
        !           541: *    PURPOSE:   Prints out the current values of the command line options
        !           542: *                  
        !           543: *
        !           544: *    ARGUMENTS:        LPSTR   => program name
        !           545: *
        !           546: *       RETURNS:   nothing
        !           547: *
        !           548: *\***************************************************************************/
        !           549: void dump_defaults(LPSTR progname)
        !           550: {
        !           551:     printf("Default option values for %s:\n\n", progname);
        !           552: 
        !           553:     printf("verbose =                %d\n", verbose);
        !           554:     printf("socket type =            %d\n", Socket_Type);
        !           555:     printf("protocol =               %d\n", Protocol);
        !           556:     printf("sleep time =             %d\n", Sleep_Time);
        !           557:     printf("backlog =                %d\n", Backlog);
        !           558:     printf("nobcast =                %d\n", No_Broadcast);
        !           559:     printf("noloop =                 %d\n", No_Loop);
        !           560:     printf("send length =            %d\n", Send_Length);
        !           561:     printf("receive length =         %d\n", Receive_Length);
        !           562:     printf("send packet type =       %d\n", Send_Packet_Type);
        !           563:     printf("local packet type =      %d\n", Local_Packet_Type);
        !           564:     printf("filter packet type =     %d\n", Filter_Packet_Type);
        !           565:     printf("local address family =   %d\n", Local_Address_Family);
        !           566:     printf("remote address family =  %d\n", Remote_Address_Family);
        !           567:     printf("local network number =   ");
        !           568:     print_network_num(Local_Network_Number);
        !           569:     printf("\nlocal node number =      ");
        !           570:     print_node_num(Local_Node_Number);
        !           571:     printf("\nlocal socket number =    ");
        !           572:     print_socket_num(Local_Socket_Number);
        !           573:     printf("\nremote network number =  ");
        !           574:     print_network_num(Remote_Network_Number);
        !           575:     printf("\nremote node number =     ");
        !           576:     print_node_num(Remote_Node_Number);
        !           577:     printf("\nremote socket number =   ");
        !           578:     print_socket_num(Remote_Socket_Number);
        !           579:     printf("\n\n");
        !           580: }
        !           581: 
        !           582: 
        !           583: /****************************************************************************
        !           584: *
        !           585: *    FUNCTION:  get_network_number( LPSTR cmd )
        !           586: *
        !           587: *    PURPOSE:   Reads a network number from the given string
        !           588: *
        !           589: *
        !           590: *    ARGUMENTS:        LPSTR  => string to read from
        !           591: *
        !           592: *       RETURNS:   LPSTR  => hex network number
        !           593: *
        !           594: *\***************************************************************************/
        !           595: LPSTR get_network_number(LPSTR cmd)
        !           596: {
        !           597:     static char hex_num[4];
        !           598: 
        !           599:     memset(hex_num, 0, 4);
        !           600: 
        !           601:     if (strlen(cmd) != 8) {
        !           602:         printf("Incorrect format for network number.\n");
        !           603:         exit(1);
        !           604:     }
        !           605: 
        !           606:     get_hex_string(cmd, hex_num, 4);
        !           607: 
        !           608:     return hex_num;
        !           609: }
        !           610: 
        !           611: /****************************************************************************
        !           612: *
        !           613: *    FUNCTION:  get_node_number( LPSTR cmd )
        !           614: *
        !           615: *    PURPOSE:   Reads a node number from the given string
        !           616: *
        !           617: *
        !           618: *    ARGUMENTS:        LPSTR  => string to read from
        !           619: *
        !           620: *       RETURNS:   LPSTR  => hex network number
        !           621: *
        !           622: *\***************************************************************************/
        !           623: LPSTR get_node_number(LPSTR cmd)
        !           624: {
        !           625:     static char hex_num[6];
        !           626: 
        !           627:     memset(hex_num, 0, 6);
        !           628: 
        !           629:     if (strlen(cmd) != 12) {
        !           630:         printf("Incorrect format for node number.\n");
        !           631:         exit(1);
        !           632:     }
        !           633: 
        !           634:     get_hex_string(cmd, hex_num, 6);
        !           635: 
        !           636:     return hex_num;
        !           637: }
        !           638: 
        !           639: /****************************************************************************
        !           640: *
        !           641: *    FUNCTION:  get_socket_number( LPSTR cmd )
        !           642: *
        !           643: *    PURPOSE:   Reads a socket number from the given string
        !           644: *
        !           645: *
        !           646: *    ARGUMENTS:        LPSTR  => string to read from
        !           647: *
        !           648: *       RETURNS:   LPSTR  => hex network number
        !           649: *
        !           650: *\***************************************************************************/
        !           651: LPSTR get_socket_number(LPSTR cmd)
        !           652: {
        !           653:     static char hex_num[2];
        !           654: 
        !           655:     memset(hex_num, 0, 2);
        !           656: 
        !           657:     if (strlen(cmd) != 4) {
        !           658:         printf("Incorrect format for socket number.\n");
        !           659:         exit(1);
        !           660:     }
        !           661: 
        !           662:     get_hex_string(cmd, hex_num, 2);
        !           663: 
        !           664:     return hex_num;
        !           665: }
        !           666: 
        !           667: /****************************************************************************
        !           668: *
        !           669: *    FUNCTION:  get_hex_string( LPSTR src, LPSTR dest, int num )
        !           670: *
        !           671: *    PURPOSE:   Reads in a character string containing hex digits and converts
        !           672: *                              it to a hexadecimal number.
        !           673: *
        !           674: *    ARGUMENTS:        LPSTR  => source string
        !           675: *                              LPSTR  => destination for hex number
        !           676: *                              int    number of bytes to convert       
        !           677: *
        !           678: *       RETURNS:   nothing
        !           679: *
        !           680: *\***************************************************************************/
        !           681: void get_hex_string(LPSTR src, LPSTR dest, int num)
        !           682: {
        !           683:     LPSTR q = src;
        !           684: 
        !           685:     while (num--)
        !           686:         *dest++ = (get_hex_byte(*q++) << 4) + get_hex_byte(*q++);
        !           687: 
        !           688: }
        !           689: 
        !           690: /****************************************************************************
        !           691: *
        !           692: *    FUNCTION:  get_hex_byte( char ch )
        !           693: *
        !           694: *    PURPOSE:   Converts the character passed in to a hexadecimal nibble.
        !           695: *
        !           696: *    ARGUMENTS:        char    character to convert
        !           697: *
        !           698: *       RETURNS:   UCHAR   hex nibble
        !           699: *
        !           700: *\***************************************************************************/
        !           701: UCHAR get_hex_byte(char ch)
        !           702: {
        !           703:     if (ch >= '0' && ch <= '9')
        !           704:         return (ch - '0');
        !           705: 
        !           706:     if (ch >= 'A' && ch <= 'F')
        !           707:         return ((ch - 'A') + 0x0A);
        !           708: 
        !           709:     printf("Illegal character %c in hex string\n", ch);
        !           710:     exit(1);
        !           711: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.