compilation of c code from visualC++compiler 2008 and code is from linux os

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • priyanka23
    New Member
    • Sep 2010
    • 24

    compilation of c code from visualC++compiler 2008 and code is from linux os

    code has been taken frm linux platform and try to compile it on windows using vc++2008
    Code:
    #include <stdio.h>
    #include <sys/types.h> 
    //#include <sys/socket.h>
    #include <winsock.h> 
    #include<stdlib.h>
    #include<string.h>
    /*#include<cstring.h>*/
    #include "FunctionMapping.h"
    #include "getInventory.h"
    //#include "source.h"
    
    //#include <netinet/in.h>
    
    void error(char *msg)
    {
    	perror(msg);
    	exit(1);
    }
    struct licensedetails
    {
    	char lic_num[16];
        long int max_cc_calls;
        long int max_subs_limit;
        char expiry_date[10];
        char authorised_mac_addr[32];
    
    };
    
    
    
    int dummylicensedecrypter(char*  encryptedtext)
    { 
    	int decryptionresult=0;
    	 char badcharacter='*';
    	 if(strchr(encryptedtext,badcharacter))
         { decryptionresult=0;		
    	   printf ("\nFound badcharacter%c at %d\n",badcharacter,strchr(encryptedtext,badcharacter));
    	   
         }  
    	 else decryptionresult=1;
    	 
    	 
    	 printf("\nDecryptionResult: %d\n",decryptionresult);
    	 
       return decryptionresult;
       
    
    }
    
    // using jni
    
    /*JNIEXPORT jstring JNICALL Java_FunctionMapping_updatelicense__Ljava_lang_String_2(JNIEnv *env, jobject obj,jstring s1 )
    {
    char tosend[200];
    const jbyte *str;
    int presult;
    str = (*env)->GetStringUTFChars(env, s1, NULL);
    if (str == NULL) {
        return NULL; /* OutOfMemoryError already thrown 
    }
    char strng[20] ="updatelicense"; 
         presult=(char *)invokelicenseupdate(strng,str);
         printf(" processreply %s\n",tosend);
    
       if(presult==1)strcpy(tosend,"SUCCESS");
       else strcpy(tosend,"FAILURE");
        printf("processreply .. %s",tosend);
        (*env)->ReleaseStringUTFChars(env, s1, str);
       return (*env)->NewStringUTF(env, tosend);
    
    }*/
    
    JNIEXPORT jstring JNICALL Java_FunctionMapping_interchange (JNIEnv *env, jobject obj, jstring s,  jstring s2)
    {
    char reply[200];
    const jbyte *str;
    int rno;
    str = (*env)->GetStringUTFChars(env, s, NULL);
    if (str == NULL) {
        return NULL; /* OutOfMemoryError already thrown */
    }
    
    (*env)->ReleaseStringUTFChars(env, s, str);
    
    rno = rand()%(10);
    if (rno <7)
    {strcpy(reply,"SUCCESS");}
    else 
    {strcpy(reply,"FAILURE");}
    return (*env)->NewStringUTF(env, reply);
    }
    
    
    
    // ist function 
    JNIEXPORT jstring JNICALL Java_FunctionMapping_updatelicense__Ljava_lang_String_2Ljava_lang_String_2(JNIEnv *env, jobject obj, jstring s1, jstring s2)
    {
    char tosend[200];
    const jbyte *str, *str2;
    int presult;
    str = (*env)->GetStringUTFChars(env, s1, NULL);
    str2 = (*env)->GetStringUTFChars(env, s2, NULL);
    if (str == NULL) {
        return NULL; /* OutOfMemoryError already thrown */
    }
    if (str2 == NULL) {
        return NULL; /* OutOfMemoryError already thrown */
    }
    
    if(strcmp(str,"UPDATE_LICENSE")==0)
    	{
    		printf("Invoking commands for execution of .... %s\n with process parameters using jni %s\n",str,str2);
    	presult=(char *)invokelicenseupdate(str,str2);
    		printf(" processreply %s\n",tosend);
    	}
    	else
    	{
    
    	printf("Unrecognized process %s\n",str);
    	}
    
       if(presult==1)strcpy(tosend,"SUCCESS");
       else strcpy(tosend,"FAILURE");
        printf("processreply .. %s",tosend);
        (*env)->ReleaseStringUTFChars(env, s1, str);
        (*env)->ReleaseStringUTFChars(env, s2, str2);
    
        return (*env)->NewStringUTF(env, tosend);
    }
    
    int reloadngcpe(char processparameter[])
    {  int licenseupdateresult=0;
    	printf("\nreloading ngcpe....");
    	
    	printf("\ndecrypting license file....");
    	
    		//dummy decryption logic
            
    		licenseupdateresult=dummylicensedecrypter(processparameter);
    	
    	
    	if(licenseupdateresult==1)
    	{
    		//updating database
    		printf("\nwriting  to database");
    		char comm[500];
    		while(1)
    			{
    				printf("\n myPrompt>>>");
    				gets(comm);
    				if(!strcmp(comm,"exit"))
    				{
    					break;
    				}
    				system(comm);
    			}
     
    	}		
    
       return licenseupdateresult;
    }
    
    
    
    
    int invokelicenseupdate(char process[],char processparameter[])
    {
    	printf("\nTaking backup of current license file in cdot_license.bk . . .");
    	
    	printf("\nPlacing new license file  cdot_license.dat");
    	
    	
    	int licenseupdateresult=reloadngcpe(processparameter);
    	
    	
    	
    	printf("\nlicense update information logged in pdtrc.log file");
    
    	
      return licenseupdateresult;
    }
    int main(int argc, char *argv[])
    {
    	int sockfd, newsockfd, portno, clilen;
    	char buffer[1000];
    	struct sockaddr_in serv_addr, cli_addr;
    	int n;
    	char process[50];
    	int i,j=0;
    
    	char processparameter[100];
    	char processreply[100];
        int processresult;
    	if (argc < 2) {
    		fprintf(stderr,"ERROR, no port provided\n");
    		exit(1);
    	}
    	sockfd = socket(AF_INET, SOCK_STREAM, 0);
    	if (sockfd < 0)
    		error("ERROR opening socket");
    	
    	
    	bzero((char *) &serv_addr, sizeof(serv_addr));
    	portno = atoi(argv[1]);
    	serv_addr.sin_family = AF_INET;
    	serv_addr.sin_addr.s_addr = INADDR_ANY;
    	serv_addr.sin_port = htons(portno);
    	if (bind(sockfd, (struct sockaddr *) &serv_addr,sizeof(serv_addr)) < 0) 
    		error("ERROR on binding");
    	
    	listen(sockfd,5);
        printf("\nSS simulator ready...listening on port : %d",portno);
    	clilen = sizeof(cli_addr);
    	newsockfd = accept(sockfd, 
    			(struct sockaddr *) &cli_addr, 
    			&clilen);
    	if (newsockfd < 0) 
    		error("ERROR on accept");
    	bzero(buffer,1000);
    	n = read(newsockfd,buffer,1000);
    	if (n < 0) error("ERROR reading from socket");
    	printf("Here is the message: %s\n",buffer);
    
    
    	for(i=0;i<strlen(buffer);i++)
    	{
    		if(buffer[i]!=';')
    			process[i]=buffer[i];
    		else break;
    	}
    	i++;//for omitting delimiter
    	printf("i %d\n",i);
    	for(i,j;i<strlen(buffer);i++,j++)
    	{
    		processparameter[j]=buffer[i];
    
    	}
    
    	printf("Here is the process invoked: (%s)\n",process);
    	printf("Here is the process parameter: %s\n",processparameter);
    	
    	
    	if(strcmp(process,"UPDATE_LICENSE")==0)
    	{
    		printf("Invoking commands for execution of .... %s\n with process parameters %s\n",process,processparameter);
    		processresult=(char *)invokelicenseupdate(process,processparameter);
    		printf(" processreply %s\n",processreply);
    	}
    	else
    	{
    		
    	printf("Unrecognized process %s\n",process);
    	}
    	
       
       if(processresult==1)strcpy(processreply,"SUCCESS");
       else strcpy(processreply,"FAILURE");
       
       
        printf("processreply .. %s",processreply);
        
       
    	n = write(newsockfd,processreply,sizeof(processreply));
    	if (n < 0) error("\nERROR writing to socket");
    	return 0; 
    }
    
    //mysql -ungcpe -pngcpe agent;
    // update sip_license set lic_num='0001';
    //quit
    //exit
    errors are as following-
    licensejni.c(11 7)warning :c4047:"=":'int ' difers the level of indirection from 'char*'
    licensejni.c(15 0):error c2143:syntax error:missing'; 'before'type'
    licensejni.c(15 4):error c2065:'comm':un declared identifier
    licensejni.c(15 5):error c2065:'comm':un declared identifier
    licensejni.c(15 9):error c2065:'comm':un declared identifier
    licensejni.c(17 7):error c2143:syntax error:missing'; 'before'type'
    licensejni.c(18 4):error c2065:'licenseu pdateresult':un declered identifier
  • priyanka23
    New Member
    • Sep 2010
    • 24

    #2
    compilation of c code from visualC++compil er 2008 and code is from linux os

    code has been taken frm linux platform and try to compile it on windows using vc++2008
    Code:
    line numbers of error are according to VC++ editor..
    /* A simple server in the internet domain using
    TCP domain  The port number is passed as an argument */
    /*also implenet jni method to get input from java and send back argument to java after processing as we want*/
    #include <stdio.h>
    #include <sys/types.h> 
    //#include <sys/socket.h>
    #include <winsock.h> 
    #include<stdlib.h>
    #include<string.h>
    /*#include<cstring.h>*/
    #include "FunctionMapping.h"
    #include "getInventory.h"
    //#include "source.h"
    
    //#include <netinet/in.h>
    
    void error(char *msg)
    {
    	perror(msg);
    	exit(1);
    }
    struct licensedetails
    {
    	char lic_num[16];
        long int max_cc_calls;
        long int max_subs_limit;
        char expiry_date[10];
        char authorised_mac_addr[32];
    
    };
    
    
    
    int dummylicensedecrypter(char*  encryptedtext)
    { 
    	int decryptionresult=0;
    	 char badcharacter='*';
    	 if(strchr(encryptedtext,badcharacter))
         { decryptionresult=0;		
    	   printf ("\nFound badcharacter%c at %d\n",badcharacter,strchr(encryptedtext,badcharacter));
    	   
         }  
    	 else decryptionresult=1;
    	 
    	 
    	 printf("\nDecryptionResult: %d\n",decryptionresult);
    	 
       return decryptionresult;
       
    
    }
    
    // using jni
    
    /*JNIEXPORT jstring JNICALL Java_FunctionMapping_updatelicense__Ljava_lang_String_2(JNIEnv *env, jobject obj,jstring s1 )
    {
    char tosend[200];
    const jbyte *str;
    int presult;
    str = (*env)->GetStringUTFChars(env, s1, NULL);
    if (str == NULL) {
        return NULL; /* OutOfMemoryError already thrown 
    }
    char strng[20] ="updatelicense"; 
         presult=(char *)invokelicenseupdate(strng,str);
         printf(" processreply %s\n",tosend);
    
       if(presult==1)strcpy(tosend,"SUCCESS");
       else strcpy(tosend,"FAILURE");
        printf("processreply .. %s",tosend);
        (*env)->ReleaseStringUTFChars(env, s1, str);
       return (*env)->NewStringUTF(env, tosend);
    
    }*/
    
    JNIEXPORT jstring JNICALL Java_FunctionMapping_interchange (JNIEnv *env, jobject obj, jstring s,  jstring s2)
    {
    char reply[200];
    const jbyte *str;
    int rno;
    str = (*env)->GetStringUTFChars(env, s, NULL);
    if (str == NULL) {
        return NULL; /* OutOfMemoryError already thrown */
    }
    
    (*env)->ReleaseStringUTFChars(env, s, str);
    
    rno = rand()%(10);
    if (rno <7)
    {strcpy(reply,"SUCCESS");}
    else 
    {strcpy(reply,"FAILURE");}
    return (*env)->NewStringUTF(env, reply);
    }
    
    
    
    // ist function 
    JNIEXPORT jstring JNICALL Java_FunctionMapping_updatelicense__Ljava_lang_String_2Ljava_lang_String_2(JNIEnv *env, jobject obj, jstring s1, jstring s2)
    {
    char tosend[200];
    const jbyte *str, *str2;
    int presult;
    str = (*env)->GetStringUTFChars(env, s1, NULL);
    str2 = (*env)->GetStringUTFChars(env, s2, NULL);
    if (str == NULL) {
        return NULL; /* OutOfMemoryError already thrown */
    }
    if (str2 == NULL) {
        return NULL; /* OutOfMemoryError already thrown */
    }
    
    if(strcmp(str,"UPDATE_LICENSE")==0)
    	{
    		printf("Invoking commands for execution of .... %s\n with process parameters using jni %s\n",str,str2);
    	presult=(char *)invokelicenseupdate(str,str2);
    		printf(" processreply %s\n",tosend);
    	}
    	else
    	{
    
    	printf("Unrecognized process %s\n",str);
    	}
    
       if(presult==1)strcpy(tosend,"SUCCESS");
       else strcpy(tosend,"FAILURE");
        printf("processreply .. %s",tosend);
        (*env)->ReleaseStringUTFChars(env, s1, str);
        (*env)->ReleaseStringUTFChars(env, s2, str2);
    
        return (*env)->NewStringUTF(env, tosend);
    }
    
    int reloadngcpe(char processparameter[])
    {  int licenseupdateresult=0;
    	printf("\nreloading ngcpe....");
    	
    	printf("\ndecrypting license file....");
    	
    		//dummy decryption logic
            
    		licenseupdateresult=dummylicensedecrypter(processparameter);
    	
    	
    	if(licenseupdateresult==1)
    	{
    		//updating database
    		printf("\nwriting  to database");
    		char comm[500];
    		while(1)
    			{
    				printf("\n myPrompt>>>");
    				gets(comm);
    				if(!strcmp(comm,"exit"))
    				{
    					break;
    				}
    				system(comm);
    			}
     
    	}		
    
       return licenseupdateresult;
    }
    
    
    
    
    int invokelicenseupdate(char process[],char processparameter[])
    {
    	printf("\nTaking backup of current license file in cdot_license.bk . . .");
    	
    	printf("\nPlacing new license file  cdot_license.dat");
    	
    	
    	int licenseupdateresult=reloadngcpe(processparameter);
    	
    	
    	
    	printf("\nlicense update information logged in pdtrc.log file");
    
    	
      return licenseupdateresult;
    }
    int main(int argc, char *argv[])
    {
    	int sockfd, newsockfd, portno, clilen;
    	char buffer[1000];
    	struct sockaddr_in serv_addr, cli_addr;
    	int n;
    	char process[50];
    	int i,j=0;
    
    	char processparameter[100];
    	char processreply[100];
        int processresult;
    	if (argc < 2) {
    		fprintf(stderr,"ERROR, no port provided\n");
    		exit(1);
    	}
    	sockfd = socket(AF_INET, SOCK_STREAM, 0);
    	if (sockfd < 0)
    		error("ERROR opening socket");
    	
    	
    	bzero((char *) &serv_addr, sizeof(serv_addr));
    	portno = atoi(argv[1]);
    	serv_addr.sin_family = AF_INET;
    	serv_addr.sin_addr.s_addr = INADDR_ANY;
    	serv_addr.sin_port = htons(portno);
    	if (bind(sockfd, (struct sockaddr *) &serv_addr,sizeof(serv_addr)) < 0) 
    		error("ERROR on binding");
    	
    	listen(sockfd,5);
        printf("\nSS simulator ready...listening on port : %d",portno);
    	clilen = sizeof(cli_addr);
    	newsockfd = accept(sockfd, 
    			(struct sockaddr *) &cli_addr, 
    			&clilen);
    	if (newsockfd < 0) 
    		error("ERROR on accept");
    	bzero(buffer,1000);
    	n = read(newsockfd,buffer,1000);
    	if (n < 0) error("ERROR reading from socket");
    	printf("Here is the message: %s\n",buffer);
    
    
    	for(i=0;i<strlen(buffer);i++)
    	{
    		if(buffer[i]!=';')
    			process[i]=buffer[i];
    		else break;
    	}
    	i++;//for omitting delimiter
    	printf("i %d\n",i);
    	for(i,j;i<strlen(buffer);i++,j++)
    	{
    		processparameter[j]=buffer[i];
    
    	}
    
    	printf("Here is the process invoked: (%s)\n",process);
    	printf("Here is the process parameter: %s\n",processparameter);
    	
    	
    	if(strcmp(process,"UPDATE_LICENSE")==0)
    	{
    		printf("Invoking commands for execution of .... %s\n with process parameters %s\n",process,processparameter);
    		processresult=(char *)invokelicenseupdate(process,processparameter);
    		printf(" processreply %s\n",processreply);
    	}
    	else
    	{
    		
    	printf("Unrecognized process %s\n",process);
    	}
    	
       
       if(processresult==1)strcpy(processreply,"SUCCESS");
       else strcpy(processreply,"FAILURE");
       
       
        printf("processreply .. %s",processreply);
        
       
    	n = write(newsockfd,processreply,sizeof(processreply));
    	if (n < 0) error("\nERROR writing to socket");
    	return 0; 
    }
    
    //mysql -ungcpe -pngcpe agent;
    // update sip_license set lic_num='0001';
    //quit
    //exit
    errors are as following-
    licensejni.c(11 7)warning :c4047:"=":'int ' difers the level of indirection from 'char*'
    licensejni.c(15 0):error c2143:syntax error:missing'; 'before'type'
    licensejni.c(15 4):error c2065:'comm':un declared identifier
    licensejni.c(15 5):error c2065:'comm':un declared identifier
    licensejni.c(15 9):error c2065:'comm':un declared identifier
    licensejni.c(17 7):error c2143:syntax error:missing'; 'before'type'
    licensejni.c(18 4):error c2065:'licenseu pdateresult':un declered identifier

    Comment

    • Banfa
      Recognized Expert Expert
      • Feb 2006
      • 9067

      #3
      The code stangely and unnecessarily casts the value returned from calling invokelicenseup date to char * and then assigns to an int. Remove the cast.

      I guess on Linux it was compiling for C99, visual C supports C89 and at line 151 you can not declare a variable half way through the code block it needs to be declared at the start of the code block (before the printf).

      Comment

      • ashitpro
        Recognized Expert Contributor
        • Aug 2007
        • 542

        #4
        In function "invokelicenseu pdate",
        declare "licenseupdater esult" variable at the beginning of the function. i.e.

        Code:
        int licenseupdateresult= 0 ;
        ....
        ....
        //Then use it as:
        licenseupdateresult = reloadngcpe(processparameter);
        Similarly at line 150 char comm[500];
        At line 117:
        Code:
        presult=(char *)invokelicenseupdate(str,str2);
        Why are you type casting it to char* ? Cause, "presult" is of type integer and "invokelicenseu pdate" returns the same.

        Consider these just as a guidelines...Tr y to solve further errors accordingly..
        Google is your friend, use it !!
        Last edited by NeoPa; Sep 14 '10, 08:49 PM. Reason: Please use the [CODE] tags provided.

        Comment

        • priyanka23
          New Member
          • Sep 2010
          • 24

          #5
          Thanks alot.........bu t after compiling this we have got such type of errors
          creating library liblicense.lib and object liblicense.exp
          licensejni.obj: error LINK2019:unreso lved external symbol_write@12 referenced in function _main licensejni.obj: error LINK2019:unreso lved external symbol_read@12r eferenced in function _main licensejni.obj: error LINK2019:unreso lved external symbol_accept@1 2referenced in function _main licensejni.obj: error LINK2019:unreso lved external symbol_listen@8 referenced in function _main licensejni.obj: error LINK2019:unreso lved external symbol_bind@12r eferenced in function _main licensejni.obj: error LINK2019:unreso lved external symbol_htons@4r eferenced in function _main licensejni.obj: error LINK2019:unreso lved external symbol_bzero@8r eferenced in function _main licensejni.obj: error LINK2019:unreso lved external symbol_socket@1 2referenced in function _main liblicense.dll: fatal error LINK1120:8 unresolved externals

          Comment

          • Banfa
            Recognized Expert Expert
            • Feb 2006
            • 9067

            #6
            Looks like you have failed to include the socket library in you link command link. Try adding the winsock2 library (ws2_32.lib) to the link command.

            Additionally this simple port will not work once it has link because the windows socket library does not work without initialisation.

            You will have to add a call to WSAStartup in the code before any socket functions are called and you should add a all to WSACleanup once the program have finished unsing sockets.

            Comment

            • priyanka23
              New Member
              • Sep 2010
              • 24

              #7
              plz tell m how to add winsock2 library in command link.....please telle me...and also suggest me how to initialise windows socket library?? nd thanks u a lot.......

              Comment

              • Banfa
                Recognized Expert Expert
                • Feb 2006
                • 9067

                #8
                In the linker properties of your Visual Studio project there is a place to put additional libraries.

                I told you how to initialise it, call WSAStartup, you can look the function up on MSDN or using google.

                Comment

                • priyanka23
                  New Member
                  • Sep 2010
                  • 24

                  #9
                  plz tell me where i will have to call WSASTART UP in my code???
                  Thanx a lot..

                  Comment

                  • Banfa
                    Recognized Expert Expert
                    • Feb 2006
                    • 9067

                    #10
                    Before you call any socket functions.

                    You first socket call looks like a call to socket at line 199. But you will be able to tell because all the socket functions will return WSANOTINITIALIS ED if they are called before WSAStartup.

                    Comment

                    • priyanka23
                      New Member
                      • Sep 2010
                      • 24

                      #11
                      i am not able to understand your solution please describe the solution and tell me how to initialize WSAstartUP and where.....
                      Thanking you and sory for distrbing..you again and again

                      Comment

                      • Banfa
                        Recognized Expert Expert
                        • Feb 2006
                        • 9067

                        #12
                        WSAStartup must be called by your program before your program calls any other functions from the socket library.

                        Your first call looks like it is at line 199 in main, a call to socket so before then.


                        If you just run the program without putting in a call to WSAStartup or if you put it in the wrong place then any socket functions that you call before WSAStartup is called will return WSANOTINITIALIS ED

                        Comment

                        • priyanka23
                          New Member
                          • Sep 2010
                          • 24

                          #13
                          thanks you lots..i am not understanding that how to initialise WSAstartUP function in the code as i described you....

                          Comment

                          • Banfa
                            Recognized Expert Expert
                            • Feb 2006
                            • 9067

                            #14
                            You don't initialise WSAStartup, you call WSAStartup to initialise the socket library.

                            If, as I said in post #8, you type "WSAStartup " into Google (or another search engine) then the first returned link will be to WSAStartup Reference on MSDN which tells you all about the function and at the bottom of the page has an example of calling it.

                            Comment

                            • priyanka23
                              New Member
                              • Sep 2010
                              • 24

                              #15
                              Code:
                              /* A simple server in the internet domain using
                              TCP domain  The port number is passed as an argument */
                              /*also implenet jni method to get input from java and send back argument to java after processing as we want*/
                              #include <stdio.h>
                              #include <sys/types.h> 
                              //#include <sys/socket.h>
                              //#include<windows.h>
                              #include <winsock2.h> 
                              #include<stdlib.h>
                              #include<string.h>
                              //#include<cstring.h>
                              #include "FunctionMapping.h"
                              #include "getInventory.h"
                              //#include "source.h"
                              //#include <iostream.h>
                              //#include <netinet/in.h>
                              
                              void error(char *msg)
                              {
                              	perror(msg);
                              	exit(1);
                              }
                              struct licensedetails
                              {
                              	char lic_num[16];
                                  long int max_cc_calls;
                                  long int max_subs_limit;
                                  char expiry_date[10];
                                  char authorised_mac_addr[32];
                              
                              };
                              
                              
                              
                              int dummylicensedecrypter(char*  encryptedtext)
                              { 
                              	int decryptionresult=0;
                              	 char badcharacter='*';
                              	 if(strchr(encryptedtext,badcharacter))
                                   { decryptionresult=0;		
                              	   printf ("\nFound badcharacter%c at %d\n",badcharacter,strchr(encryptedtext,badcharacter));
                              	   
                                   }  
                              	 else decryptionresult=1;
                              	 
                              	 
                              	 printf("\nDecryptionResult: %d\n",decryptionresult);
                              	 
                                 return decryptionresult;
                                 
                              
                              }
                              
                              // using jni
                              
                              /*JNIEXPORT jstring JNICALL Java_FunctionMapping_updatelicense__Ljava_lang_String_2(JNIEnv *env, jobject obj,jstring s1 )
                              {
                              char tosend[200];
                              const jbyte *str;
                              int presult;
                              str = (*env)->GetStringUTFChars(env, s1, NULL);
                              if (str == NULL) {
                                  return NULL; /* OutOfMemoryError already thrown 
                              }
                              char strng[20] ="updatelicense"; 
                                   presult=(char *)invokelicenseupdate(strng,str);
                                   printf(" processreply %s\n",tosend);
                              
                                 if(presult==1)strcpy(tosend,"SUCCESS");
                                 else strcpy(tosend,"FAILURE");
                                  printf("processreply .. %s",tosend);
                                  (*env)->ReleaseStringUTFChars(env, s1, str);
                                 return (*env)->NewStringUTF(env, tosend);
                              
                              }*/
                              
                              JNIEXPORT jstring JNICALL Java_FunctionMapping_interchange (JNIEnv *env, jobject obj, jstring s,  jstring s2)
                              {
                              char reply[200];
                              const jbyte *str;
                              int rno;
                              str = (*env)->GetStringUTFChars(env, s, NULL);
                              if (str == NULL) {
                                  return NULL; /* OutOfMemoryError already thrown */
                              }
                              
                              (*env)->ReleaseStringUTFChars(env, s, str);
                              
                              rno = rand()%(10);
                              if (rno <7)
                              {strcpy(reply,"SUCCESS");}
                              else 
                              {strcpy(reply,"FAILURE");}
                              return (*env)->NewStringUTF(env, reply);
                              }
                              
                              
                              
                              // ist function 
                              JNIEXPORT jstring JNICALL Java_FunctionMapping_updatelicense__Ljava_lang_String_2Ljava_lang_String_2(JNIEnv *env, jobject obj, jstring s1, jstring s2)
                              {
                              char tosend[200];
                              const jbyte *str, *str2;
                              int presult;
                              str = (*env)->GetStringUTFChars(env, s1, NULL);
                              str2 = (*env)->GetStringUTFChars(env, s2, NULL);
                              if (str == NULL) {
                                  return NULL; /* OutOfMemoryError already thrown */
                              }
                              if (str2 == NULL) {
                                  return NULL; /* OutOfMemoryError already thrown */
                              }
                              
                              if(strcmp(str,"UPDATE_LICENSE")==0)
                              	{
                              		printf("Invoking commands for execution of .... %s\n with process parameters using jni %s\n",str,str2);
                              	presult=invokelicenseupdate(str,str2);
                              		printf(" processreply %s\n",tosend);
                              	}
                              	else
                              	{
                              
                              	printf("Unrecognized process %s\n",str);
                              	}
                              
                                 if(presult==1)strcpy(tosend,"SUCCESS");
                                 else strcpy(tosend,"FAILURE");
                                  printf("processreply .. %s",tosend);
                                  (*env)->ReleaseStringUTFChars(env, s1, str);
                                  (*env)->ReleaseStringUTFChars(env, s2, str2);
                              
                                  return (*env)->NewStringUTF(env, tosend);
                              }
                              
                              int reloadngcpe(char processparameter[])
                              {  int licenseupdateresult=0;
                                 char comm[500];
                              	printf("\nreloading ngcpe....");
                              	
                              	printf("\ndecrypting license file....");
                              	
                              		//dummy decryption logic
                                      
                              		licenseupdateresult=dummylicensedecrypter(processparameter);
                              	
                              	
                              	if(licenseupdateresult==1)
                              	{
                              		//updating database
                              		printf("\nwriting  to database");
                              		
                              		//for(i=0;i<499;i++)
                              		//comm[i]=0;
                              		while(1)
                              			{
                              				printf("\n myPrompt>>>");
                              				gets(comm);
                              				if(!strcmp(comm,"exit"))
                              				{
                              					break;
                              				}
                              				system(comm);
                              			}
                               
                              	}		
                              
                                 return licenseupdateresult;
                              }
                              
                              
                              
                              
                              int invokelicenseupdate(char process[],char processparameter[])
                              {   int licenseupdateresult=0;
                              	printf("\nTaking backup of current license file in cdot_license.bk . . .");
                              	
                              	printf("\nPlacing new license file  cdot_license.dat");
                              	
                              	
                                 licenseupdateresult=reloadngcpe(processparameter);
                              	
                              	
                              	
                              	printf("\nlicense update information logged in pdtrc.log file");
                              
                              	
                                return licenseupdateresult;
                              }
                              int main(int argc, char *argv[])
                              {   
                              	
                              	int sockfd, newsockfd, portno, clilen;
                              	char buffer[1000];
                              	struct sockaddr_in serv_addr, cli_addr;
                              	int n;
                              	char process[50];
                              	int i,j=0;
                              	char processparameter[100];
                              	char processreply[100];
                                  int processresult;
                              	WSADATA wsa;
                                  WSAStartup(MAKEWORD(2, 0), &wsa);
                              
                              	
                              	if (argc < 2) {
                              		fprintf(stderr,"ERROR, no port provided\n");
                              		exit(1);
                              	}
                              	sockfd = socket(AF_INET, SOCK_STREAM, 0);
                              	if (sockfd < 0)
                              		error("ERROR opening socket");
                              	
                              	
                              	bzero((char *) &serv_addr, sizeof(serv_addr));
                              	portno = atoi(argv[1]);
                              	serv_addr.sin_family = AF_INET;
                              	serv_addr.sin_addr.s_addr = INADDR_ANY;
                              	serv_addr.sin_port = htons(portno);
                              	if (bind(sockfd, (struct sockaddr *) &serv_addr,sizeof(serv_addr)) < 0) 
                              		error("ERROR on binding");
                              	
                              	listen(sockfd,5);
                                  printf("\nSS simulator ready...listening on port : %d",portno);
                              	clilen = sizeof(cli_addr);
                              	newsockfd = accept(sockfd, 
                              			(struct sockaddr *) &cli_addr, 
                              			&clilen);
                              	if (newsockfd < 0) 
                              		error("ERROR on accept");
                              	bzero(buffer,1000);
                              	n = read(newsockfd,buffer,1000);
                              	if (n < 0) error("ERROR reading from socket");
                              	printf("Here is the message: %s\n",buffer);
                              
                              
                              	for(i=0;i<strlen(buffer);i++)
                              	{
                              		if(buffer[i]!=';')
                              			process[i]=buffer[i];
                              		else break;
                              	}
                              	i++;//for omitting delimiter
                              	printf("i %d\n",i);
                              	for(i,j;i<strlen(buffer);i++,j++)
                              	{
                              		processparameter[j]=buffer[i];
                              
                              	}
                              
                              	printf("Here is the process invoked: (%s)\n",process);
                              	printf("Here is the process parameter: %s\n",processparameter);
                              	
                              	
                              	if(strcmp(process,"UPDATE_LICENSE")==0)
                              	{
                              		printf("Invoking commands for execution of .... %s\n with process parameters %s\n",process,processparameter);
                              		processresult=(char *)invokelicenseupdate(process,processparameter);
                              		printf(" processreply %s\n",processreply);
                              	}
                              	else
                              	{
                              		
                              	printf("Unrecognized process %s\n",process);
                              	}
                              	
                                 
                                 if(processresult==1)strcpy(processreply,"SUCCESS");
                                 else strcpy(processreply,"FAILURE");
                                 
                                 
                                  printf("processreply .. %s",processreply);
                                  
                                 
                              	n = write(newsockfd,processreply,sizeof(processreply));
                              	if (n < 0) error("\nERROR writing to socket");
                              	return 0; 
                              	WSACleanup();
                              }
                              
                              //mysql -ungcpe -pngcpe agent;
                              // update sip_license set lic_num='0001';
                              //quit
                              //exit

                              after changing this code according u I m getting similar errors..and also i have included WS2_32.lib as u suggested me.....plzz help me please......... .....

                              Tahniking u a lot...
                              Last edited by Frinavale; Sep 15 '10, 01:47 PM. Reason: In the future please post code in [code] ... [/code] tags. Added code tags.

                              Comment

                              Working...