Jump to content

Plugin help


Cap0
 Share

Recommended Posts

This C code:

AU3_PLUGIN_DEFINE(Socket_Connect)
{
                                 char del[] = ".";
                                 AU3_PLUGIN_VAR *a_sock;
                                 SOCKADDR_IN Sock;
                                 char szIP;
                                 char tok1;
                                 //char tok2;
                                 int szPORT;
                                 int IsCon;
                                 int cur_socket;
                                 int a1,a2,a3,a4;
cur_socket = AU3_GetInt32(&p_AU3_Params[0]);
szIP = AU3_GetString(&p_AU3_Params[1]);
szPORT = AU3_GetInt32(&p_AU3_Params[2]);
a1 = strtok(szIP,".");
a2 = strtok(NULL,".");
a3 = strtok(NULL,".");
a4 = strtok(NULL,".");
            Sock.sin_addr.S_un.S_un_b.s_b1 = a1;
            Sock.sin_addr.S_un.S_un_b.s_b2 = a2;
            Sock.sin_addr.S_un.S_un_b.s_b3 = a3;
            Sock.sin_addr.S_un.S_un_b.s_b4 = a4;
            Sock.sin_port = szPORT;
            Sock.sin_family = AF_INET;
            IsCon = connect(cur_socket,(SOCKADDR *)(&Sock),sizeof(Sock));
AU3_FreeString(szIP);
a_sock = AU3_AllocVar();
AU3_SetInt32(a_sock,IsCon);
*p_AU3_Result = a_sock;
*n_AU3_ErrorCode = 0;
*n_AU3_ExtCode = 0;
return AU3_PLUGIN_OK;
}

This part:

a1 = strtok(szIP,".");
a2 = strtok(NULL,".");
a3 = strtok(NULL,".");
a4 = strtok(NULL,".");
            Sock.sin_addr.S_un.S_un_b.s_b1 = a1;
            Sock.sin_addr.S_un.S_un_b.s_b2 = a2;
            Sock.sin_addr.S_un.S_un_b.s_b3 = a3;
            Sock.sin_addr.S_un.S_un_b.s_b4 = a4;

makes autoit crash when using Socket_Connect()..

i'm doing something wrong here... any help?

Link to comment
Share on other sites

Hi,

when i comment out those functions, it doesn't crash.

i used this:

$in = InitWSA();another part of the plugin...
$f = CreateSocket();another part of the plugin...
$c = Socket_Connect($f,"127.0.0.1",1000) 
msgbox(0,'',"InitWSA: " & $in & @CRLF & "CreateSocket: " & $f & @CRLF & "Socket_Connect: " & $c)

Here's an exmple code of strtok:

/*****************************************************************
 *
 * Purpose: Program to demonstrate the 'strtok' function.
 * Author:  M J Leslie
 * Date:    23-Apr-94
 *
 ****************************************************************/

#include <stdio.h>
#include <string.h>

main()
{
                /* Copy the constant into the memory
                 * pinted to by 'test_string'       */
  char test_string[50]="string to split up";

    /* if 'test_string' is declared as below and the program will give a 
     * 'Segmentation fault' This is because test_string' is pointing
     * to a constant i.e. somethin that cant be changed.    

       char *test_string="string to split up";      */
            
  char *sub_string;

                    /* Extract first string */
  printf("%s\n", strtok(test_string, " "));

                    /* Extract remaining 
                     * strings      */
  while ( (sub_string=strtok(NULL, " ")) != NULL)
  {
    printf("%s\n", sub_string);
  }
}
/*****************************************************************
 *
 * Program O/P will look like this...
 *
 *   string
 *   to
 *   split
 *   up
 *
 *****************************************************************/

from: strtok.c

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...