LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-12-2018, 08:22 AM   #1
srinietrx
Member
 
Registered: May 2013
Posts: 98

Rep: Reputation: Disabled
Server socket with SSL Issue in ioctl function


I am facing problem when I implement SSL encryption in my socket.

Basically I am using SELECT function in socket so that multiple client can be connected.

So, Socket with SELECT(without SSL) is working fine as expected.

Link is https://pastebin.com/eaMS2E4a


Code:
else 
{
       ioctl(fd, FIONREAD, &nread);
       printf("nread = %d\n", nread);
 
 
       if(nread == 0) {
          close(fd);
          FD_CLR(fd, &readfds);
          printf("removing client on fd %d\n", fd);
        }
 
       else {
       read(fd, &ch, 1);
       sleep(5);
       printf("serving client on fd %d\n", fd);
       ch++;
       write(fd, &ch, 1);
       }
}
But when added SSL_server code it is showing error in ioctl system call. It is still reading bytes from fd.

https://pastebin.com/nYqBhjGg

The extra thing I added. I am linking file descriptor(fd) with SSL object.

Code:
 SSL_set_fd(ssl, fd);
apart from ssl_related code.


Also sending link for Client code with SSL

https://pastebin.com/0dgAuUrs
 
Old 03-12-2018, 10:47 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 3,557

Rep: Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092
Hi, what exactly the error message is?
 
Old 03-12-2018, 12:09 PM   #3
srinietrx
Member
 
Registered: May 2013
Posts: 98

Original Poster
Rep: Reputation: Disabled
Yes, Logs are shown below in link
for both

1. Server Select Socket with SSL (For testing client program is shown in previous post link)
2. Server Select Socket without SSL( For testing Used standard client program)

https://pastebin.com/En4Yi6wH


From my observation

Select Socket server does three operation
1. Adding Client
2. Serving client
3. Removing client.

But third operation is not happening because
ioctl(fd, FIONREAD, &nread);
nread is not equal to 0.Showing as 31.
 
Old 03-12-2018, 01:40 PM   #4
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 9,078
Blog Entries: 4

Rep: Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170
This StackOverflow posting contains a very good explanation, with examples and links, of how to implement SSL in a C program.
 
Old 03-12-2018, 03:24 PM   #5
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 3,557

Rep: Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092
@OP: So actually there is no error in ioctl? (Return value==-1 means error, errno is the error-code.)

Last edited by NevemTeve; 03-12-2018 at 03:27 PM.
 
Old 03-13-2018, 03:16 AM   #6
srinietrx
Member
 
Registered: May 2013
Posts: 98

Original Poster
Rep: Reputation: Disabled
Hi,
yes ioctl there is no issue.

fd which we are passing in ioctl should be reading zero bytes as in example without ssl.

If Select socket is added in SSL code it is reading 31 bytes in third operation. So I am not able to remove the client after serving.

The Select socket code I am using is same for both.
 
Old 03-13-2018, 03:25 AM   #7
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 3,557

Rep: Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092
Actually, ioctl(FIONREAD) should never be called. You should set your sockets into non-blocking mode, and when select(2) returns 'readable' attempt to read/SSL_read.

Last edited by NevemTeve; 03-13-2018 at 03:26 AM.
 
Old 03-13-2018, 07:36 AM   #8
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 9,078
Blog Entries: 4

Rep: Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170
The SSL protocol sends more stuff up-and-down the wire than just your data. The library handles all of that handshaking for you. You need to follow the examples very closely.
 
  


Reply

Tags
sockets


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Do ioctl and fcntl affect pending data on a socket? Millenniumman Programming 2 07-03-2007 03:28 PM
is the function ioctl ok for I_SENDFD wangjinyi Fedora 0 11-29-2005 03:02 AM
ioctl function maldini1010 Linux - Software 0 01-02-2005 06:28 PM
how to mute the mic by ioctl function derekzxcv Programming 0 07-12-2004 06:26 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:42 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration