How to use openssl

Michael Wojcik Michael.Wojcik at microfocus.com
Wed May 24 17:02:02 UTC 2023


> From: Don Payette <payettedon at gmail.com> 
> 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


More information about the openssl-users mailing list