/**************************************************************************///code for framing the packet stream (both encapsulation and decapsulation) // encapsulation using "strcat"//decapsulation using "strtok"// using delimiter as '@' in between the fields/**************************************************************************/
#include <stdio.h>
#include <string.h>
#define DELIMITER "@"
void bingo (char *argp[]);
void bingo (char *argp[])
{
char
str_complete_packet[50] = "process_start@1st_index";
int i = 0;
while (argp[i] !=
NULL) {
printf("%s\n", argp[i]);
strcat(str_complete_packet, DELIMITER);
strcat(str_complete_packet, argp[i]);
i++;
}
printf("\n
complete packet : %s \n\n", str_complete_packet);
char *operation;
char *index;
#if 0
operation =
strtok(str_complete_packet, DELIMITER );
printf("Operation: %s \n", operation);
index =
strtok(NULL, DELIMITER );
printf("rule index: %s \n", index);
#endif
printf("\n Now print the arguments extracted from packet in order
\n");
char
*tokenPtr;
int j =0;
char
temp[10][20];
memset(temp, 0, sizeof(temp));
//
initialize the string tokenizer and receive pointer to first token
tokenPtr =
strtok(str_complete_packet, DELIMITER);
while(tokenPtr != NULL)
{
printf("%s\n",tokenPtr);
sprintf(temp[j],"%s",tokenPtr );
printf("%s\n",temp[j]);
tokenPtr = strtok(NULL, DELIMITER);
j++;
}
}
int main()
{
char *argp[] =
{"neel", "-p", "bambo", NULL};
bingo(argp);
return 0;
}