How to use openssl

Don Payette payettedon at gmail.com
Wed May 24 18:12:29 UTC 2023


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 <(479)%20216-6320>


On Wed, May 24, 2023 at 12:02 PM Michael Wojcik via openssl-users <
openssl-users at openssl.org> wrote:

> > 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mta.openssl.org/pipermail/openssl-users/attachments/20230524/6a42c1fe/attachment-0001.htm>


More information about the openssl-users mailing list