Re: How to use openssl

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The compiler is Visual C++. 

I'm trying to fix this C code to work in Windows since my app is a Windows service written in Visual C++. It would be be real nice if openSSL had a version
of the sample program that works in Microsoft Visual C++.

Anyway, I went to my existing C++ code and found where it creates a socket and the type needs to be SOCKET, not int.

Still got more to fix. Wish me luck.

Don Payette
(cell) 479-216-6320


On Wed, May 24, 2023 at 12:02 PM Michael Wojcik via openssl-users <openssl-users@xxxxxxxxxxx> wrote:
> From: Don Payette <payettedon@xxxxxxxxx>
> Sent: Wednesday, 24 May, 2023 10:42

> Right now I'm attempting to compile sslecho using Microsoft Visual C++.
> It's giving me an error which I can't figure out.
> I'm guessing that this is because it's C++ instead of C.

I'm not sure what you believe is C++. The code you posted here is C.

> int create_socket ()
> {
>    int s;
>    int optval = 1;
>
>    s = socket (AF_INET, SOCK_STREAM, 0);
>    if (s < 0) {
>        perror("Unable to create socket");
>        exit(EXIT_FAILURE);
>    }
>
>    return s;
> }

This isn't going to work on Windows, where the return type of the socket() function is HANDLE, not int. This code is written to work in a UNIX (SUS, POSIX) environment. As it is, it's not suitable for Windows, unless you're building under a POSIX or POSIX-like environment within Windows such as WSL, MinGW, or Cygwin.
  
...

>    client_skt = create_socket;
>
> Error (active) E0513 a value of type "int (*)()" cannot be assigned to an entity of type "int" OpenSSL-Demo  line 152

create_socket is a function. This line is not invoking the function; it's trying to assign it to a variable. You can only do that in C if the variable is of a function-pointer type.

What you want here is:

   client_skt = create_socket();

Note the parentheses.

However, as I pointed out above, this code is unsuitable for Windows anyway, unless you're working in a POSIXy environment.

--
Michael Wojcik

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux