zuluCrypt  5.7.1
About: zuluCrypt is a simple but feature rich solution for hard drives encryption. It can manage PLAIN dm-crypt, LUKS, TrueCrypt and VeraCrypt encrypted volumes.
  Fossies Dox: zuluCrypt-5.7.1.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

socket.c
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2012-2015
4  * name : Francis Banyikwa
5  * email: mhogomchungu@gmail.com
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include "socket.h"
21 
22 #ifndef _GNU_SOURCE
23 #define _GNU_SOURCE
24 #endif
25 
26 #include <sys/socket.h>
27 #include <unistd.h>
28 #include <stdio.h>
29 #include <string.h>
30 #include <stdlib.h>
31 #include <sys/un.h>
32 #include <netinet/in.h>
33 #include <arpa/inet.h>
34 #include <sys/select.h>
35 #include <netdb.h>
36 #include <sys/time.h>
37 #include <fcntl.h>
38 #include <errno.h>
39 #include <sys/socket.h>
40 #include <netdb.h>
41 
43 {
45  int type ;
46  int protocol ;
47  int cmax ;
48  int domain ;
49  socklen_t size ;
50  int fd ;
51  void * socket ;
52  char * inetAddress ;
53 };
54 
55 static void ( *_fcn_ )( void ) = NULL ;
56 
57 void SocketExitOnMemoryExaustion( void ( *f )( void ) )
58 {
59  _fcn_ = f ;
60 }
61 
62 static socket_t _SocketError( void )
63 {
64  if( _fcn_ != NULL ){
65  _fcn_() ;
66  }
67  return SocketVoid ;
68 }
69 
70 static inline socket_t _SocketLocal( void )
71 {
72  socket_t s = malloc( sizeof( struct SocketType_t ) ) ;
73  struct sockaddr_un * e ;
74 
75  if( s == NULL ){
76  return SocketVoid ;
77  }else{
78  memset( s,'\0',sizeof( struct SocketType_t ) ) ;
79 
80  s->socket = malloc( sizeof( struct sockaddr_un ) ) ;
81 
82  if( s->socket == NULL ){
83  free( s ) ;
84  return _SocketError() ;
85  }else{
86  s->size = sizeof( struct sockaddr_un ) ;
87  memset( s->socket,'\0',s->size ) ;
88  e = s->socket ;
89  e->sun_family = AF_UNIX ;
90  return s ;
91  }
92  }
93 }
94 
95 static inline socket_t _SocketNet( void )
96 {
97  socket_t s = malloc( sizeof( struct SocketType_t ) ) ;
98  struct sockaddr_in * e ;
99 
100  if( s == NULL ){
101  return SocketVoid ;
102  }else{
103  memset( s,'\0',sizeof( struct SocketType_t ) ) ;
104 
105  s->socket = malloc( sizeof( struct sockaddr_in ) ) ;
106 
107  if( s->socket == NULL ){
108  free( s ) ;
109  return _SocketError() ;
110  }else{
111  s->inetAddress = NULL ;
112  s->size = sizeof( struct sockaddr_in ) ;
113  memset( s->socket,'\0',s->size ) ;
114  e = s->socket ;
115  e->sin_family = AF_INET ;
116  return s ;
117  }
118  }
119 }
120 
121 static inline socket_t _SocketNet6( void )
122 {
123  socket_t s = malloc( sizeof( struct SocketType_t ) ) ;
124  struct sockaddr_in6 * e ;
125 
126  if( s == NULL ){
127  return SocketVoid ;
128  }else{
129  memset( s,'\0',sizeof( struct SocketType_t ) ) ;
130 
131  s->socket = malloc( sizeof( struct sockaddr_in6 ) ) ;
132 
133  if( s->socket == NULL ){
134  free( s ) ;
135  return _SocketError() ;
136  }else{
137  s->inetAddress = NULL ;
138  s->size = sizeof( struct sockaddr_in6 ) ;
139  memset( s->socket,'\0',s->size ) ;
140  e = s->socket ;
141  e->sin6_family = AF_INET6 ;
142  return s ;
143  }
144  }
145 }
146 
147 socket_t Socket( int domain,int type,int protocol )
148 {
149  socket_t s = SocketVoid ;
150  int fd ;
151 
152  if( domain != AF_UNIX && domain != AF_INET && domain != AF_INET6 ){
153  return SocketVoid ;
154  }
155 
156  fd = socket( domain,type,protocol ) ;
157 
158  if( fd == -1 ){
159  return SocketVoid ;
160  }
161 
162  fcntl( fd,F_SETFD,FD_CLOEXEC ) ;
163 
164  switch( domain ){
165  case AF_UNIX : s = _SocketLocal() ; break ;
166  case AF_INET : s = _SocketNet() ; break ;
167  case AF_INET6: s = _SocketNet6() ; break ;
168  }
169 
170  if( s == SocketVoid ){
171  close( fd ) ;
172  return SocketVoid ;
173  }else{
174  s->domain = domain ;
175  s->type = type ;
176  s->protocol = protocol ;
177  s->cmax = 1 ;
178  s->socket_server = 0 ;
179  s->fd = fd ;
180  return s ;
181  }
182 }
183 
185 {
186  if( s == SocketVoid ){
187  return -1 ;
188  }else{
189  return s->fd ;
190  }
191 }
192 
193 socket_t SocketLocalWithOptions( const char * address,int type,int protocol )
194 {
195  socket_t s = Socket( AF_UNIX,type,protocol ) ;
196  struct sockaddr_un * e ;
197  size_t l = sizeof( e->sun_path ) ;
198  if( s != SocketVoid ){
199  e = s->socket ;
200  strncpy( e->sun_path,address,l ) ;
201  }
202  return s ;
203 }
204 
205 socket_t SocketLocal( const char * address )
206 {
207  return SocketLocalWithOptions( address,SOCK_STREAM,0 ) ;
208 }
209 
210 socket_t SocketNetWithOptions( const char * address,int port,int type,int protocol )
211 {
212  socket_t s = SocketVoid ;
213 
214  struct addrinfo * info ;
215  struct addrinfo hint ;
216  struct sockaddr_in * e ;
217 
218  memset( &hint,'\0',sizeof( hint ) ) ;
219 
220  hint.ai_family = AF_INET ;
221  hint.ai_socktype = type ;
222  hint.ai_protocol = protocol ;
223 
224  if( getaddrinfo( address,NULL,&hint,&info) == 0 ){
225  s = Socket( AF_INET,type,protocol ) ;
226  if( s != SocketVoid ){
227  e = s->socket ;
228  memcpy( e,info->ai_addr,info->ai_addrlen ) ;
229  e->sin_port = htons( (uint16_t)port ) ;
230  }
231 
232  freeaddrinfo( info ) ;
233  }
234 
235  return s ;
236 }
237 
238 socket_t SocketNet( const char * address,int port )
239 {
240  return SocketNetWithOptions( address,port,SOCK_STREAM,0 ) ;
241 }
242 
243 socket_t SocketNetWithOptions6( const char * address,int port,int type,int protocol )
244 {
245  socket_t s = SocketVoid ;
246 
247  struct addrinfo hint ;
248  struct addrinfo * info ;
249  struct sockaddr_in6 * e ;
250 
251  memset( &hint,'\0',sizeof( struct addrinfo ) ) ;
252 
253  hint.ai_family = AF_INET6 ;
254  hint.ai_socktype = type ;
255  hint.ai_protocol = protocol ;
256 
257  if( getaddrinfo( address,NULL,&hint,&info ) == 0 ){
258  s = Socket( AF_INET6,type,protocol ) ;
259  if( s != SocketVoid ){
260  e = s->socket ;
261  memcpy( e,info->ai_addr,info->ai_addrlen ) ;
262  e->sin6_port = htons( (uint16_t) port ) ;
263  }
264 
265  freeaddrinfo( info ) ;
266  }
267 
268  return s ;
269 }
270 
271 socket_t SocketNet6( const char * address,int port )
272 {
273  return SocketNetWithOptions6( address,port,SOCK_STREAM,0 ) ;
274 }
275 
276 static inline const char * _SocketNetAddress( socket_t s )
277 {
278  const char * c ;
279  struct sockaddr_in * e = s->socket ;
280 
281  if( s->inetAddress == NULL ){
282  s->inetAddress = malloc( sizeof( char ) * INET_ADDRSTRLEN ) ;
283  if( s->inetAddress == NULL ){
284  _SocketError() ;
285  return NULL ;
286  }
287 
288  c = inet_ntop( AF_INET,&e->sin_addr,s->inetAddress,INET_ADDRSTRLEN ) ;
289 
290  if( c == NULL ){
291  free( s->inetAddress ) ;
292  s->inetAddress = NULL ;
293  return NULL ;
294  }
295  }
296 
297  return s->inetAddress ;
298 }
299 
300 static inline const char * _SocketNetAddress6( socket_t s )
301 {
302  const char * c ;
303  struct sockaddr_in6 * e = s->socket ;
304 
305  if( s->inetAddress == NULL ){
306  s->inetAddress = malloc( sizeof( char ) * INET6_ADDRSTRLEN ) ;
307  if( s->inetAddress == NULL ){
308  _SocketError() ;
309  return NULL ;
310  }
311 
312  c = inet_ntop( AF_INET6,&e->sin6_addr,s->inetAddress,INET6_ADDRSTRLEN ) ;
313 
314  if( c == NULL ){
315  free( s->inetAddress ) ;
316  s->inetAddress = NULL ;
317  return NULL ;
318  }
319  }
320 
321  return s->inetAddress ;
322 }
323 
324 static inline const char * _SocketLocalAddress( socket_t s )
325 {
326  struct sockaddr_un * e = s->socket ;
327  return e->sun_path ;
328 }
329 
330 const char * SocketAddress( socket_t s )
331 {
332  if( s == SocketVoid ){
333  return NULL ;
334  }else{
335  switch( s->domain ){
336  case AF_UNIX : return _SocketLocalAddress( s ) ;
337  case AF_INET : return _SocketNetAddress( s ) ;
338  case AF_INET6: return _SocketNetAddress6( s ) ;
339  default : return NULL ;
340  }
341  }
342 }
343 
345 {
346  struct sockaddr * e ;
347  struct sockaddr_un * f ;
348 
349  size_t m ;
350 
351  char buffer[ sizeof( f->sun_path ) + 1 ] ;
352 
353  if( s == SocketVoid ){
354  return 0 ;
355  }
356 
357  e = s->socket ;
358 
359  if( s->domain == AF_UNIX ){
360  m = sizeof( f->sun_path ) ;
361  s->socket_server = 1 ;
362  f = s->socket ;
363  strncpy( buffer,f->sun_path,m ) ;
364  *( buffer + sizeof( f->sun_path ) ) = '\0' ;
365  unlink( buffer ) ;
366  return bind( s->fd,e,s->size ) == 0 ;
367  }else if( s->domain == AF_INET ){
368  return bind( s->fd,e,s->size ) == 0 ;
369  }else if (s->domain == AF_INET6 ){
370  return bind( s->fd,e,s->size ) == 0 ;
371  }else{
372  return 0 ;
373  }
374 }
375 
377 {
378  struct sockaddr_un * e ;
379  struct sockaddr_un * z ;
380 
381  struct sockaddr * f ;
382 
383  size_t size = sizeof( struct sockaddr_un ) ;
384  socket_t x = malloc( sizeof( struct SocketType_t ) ) ;
385 
386  size_t m ;
387 
388  if( x == NULL ){
389  return _SocketError() ;
390  }else{
391  memset( x,'\0',sizeof( struct SocketType_t ) ) ;
392 
393  x->socket = malloc( size ) ;
394 
395  if( x->socket == NULL ){
396  free( x ) ;
397  x = _SocketError() ;
398  }else{
399  x->size = (unsigned int)size ;
400  memset( x->socket,'\0',size ) ;
401  f = x->socket ;
402  x->fd = accept( s->fd,f,&x->size ) ;
403  if( x->fd == -1 ){
404  free( x->socket ) ;
405  free( x ) ;
406  x = SocketVoid ;
407  }else{
408  m = sizeof( z->sun_path ) ;
409  e = s->socket ;
410  z = x->socket ;
411  strncpy( z->sun_path,e->sun_path,m ) ;
412  x->inetAddress = NULL ;
413  x->domain = s->domain ;
414  x->type = s->type ;
415  x->protocol = s->protocol ;
416  x->cmax = 1 ;
417  x->socket_server = 0 ;
418  }
419  }
420  return x ;
421  }
422 }
423 
425 {
426  struct sockaddr * f ;
427 
428  size_t size = sizeof( struct sockaddr_in ) ;
429  socket_t x = ( socket_t ) malloc( sizeof( struct SocketType_t ) ) ;
430 
431  if( x == NULL ){
432  return _SocketError() ;
433  }else{
434  memset( x,'\0',sizeof( struct SocketType_t ) ) ;
435 
436  x->socket = malloc( size ) ;
437  if( x->socket == NULL ){
438  free( x ) ;
439  x = _SocketError() ;
440  }else{
441  x->size = (unsigned int)size ;
442  memset( x->socket,'\0',size ) ;
443  f = x->socket ;
444  x->fd = accept( s->fd,f,&x->size ) ;
445  if( x->fd == -1 ){
446  free( x->socket ) ;
447  free( x ) ;
448  x = SocketVoid ;
449  }else{
450  x->inetAddress = NULL ;
451  x->domain = s->domain ;
452  x->type = s->type ;
453  x->protocol = s->protocol ;
454  x->cmax = 1 ;
455  x->socket_server = 0 ;
456  }
457  }
458  return x ;
459  }
460 }
461 
463 {
464  struct sockaddr * f ;
465 
466  size_t size = sizeof( struct sockaddr_in6 ) ;
467  socket_t x = malloc( sizeof( struct SocketType_t ) ) ;
468 
469  if( x == NULL ){
470  return _SocketError() ;
471  }else{
472  memset( x,'\0',sizeof( struct SocketType_t ) ) ;
473 
474  x->socket = malloc( size ) ;
475  if( x->socket == NULL ){
476  free( x ) ;
477  x = _SocketError() ;
478  }else{
479  x->size = (unsigned int)size ;
480  memset( x->socket,'\0',size ) ;
481  f = x->socket ;
482  x->fd = accept( s->fd,f,&x->size ) ;
483  if( x->fd == -1 ){
484  free( x->socket ) ;
485  free( x ) ;
486  x = SocketVoid ;
487  }else{
488  x->inetAddress = NULL ;
489  x->domain = s->domain ;
490  x->type = s->type ;
491  x->protocol = s->protocol ;
492  x->cmax = 1 ;
493  x->socket_server = 0 ;
494  }
495  }
496  return x ;
497  }
498 }
499 
501 {
502  switch( s->domain ){
503  case AF_UNIX : return _SocketAcceptLocal( s ) ;
504  case AF_INET : return _SocketAcceptNet( s ) ;
505  case AF_INET6: return _SocketAcceptNet6( s ) ;
506  default : return SocketVoid ;
507  }
508 }
509 
511 {
512  int flags ;
513 
514  if( s == SocketVoid ){
515  return -1 ;
516  }else{
517  flags = fcntl( s->fd,F_GETFL,0 ) ;
518  return flags != ( flags | O_NONBLOCK ) ;
519  }
520 }
521 
522 #define READ 1
523 #define WRITE 0
524 
525 static inline int _SocketNotTimedOut( socket_t s,time_t time,int mode )
526 {
527  int fd = s->fd ;
528  fd_set fdset ;
529 
530  struct timeval interval ;
531 
532  memset( &interval,'\0',sizeof( struct timeval ) ) ;
533 
534  interval.tv_sec = time ;
535  interval.tv_usec = 0 ;
536 
537  FD_ZERO( &fdset ) ;
538  FD_SET( fd,&fdset ) ;
539 
540  if( mode == READ ){
541  select( fd + 1,&fdset,NULL,NULL,&interval ) ;
542  return FD_ISSET( fd,&fdset ) ;
543  }else{
544  select( fd + 1,NULL,&fdset,NULL,&interval ) ;
545  return FD_ISSET( fd,&fdset ) ;
546  }
547 }
548 
550 {
551  if( _SocketNotTimedOut( s,time,READ ) ){
552  return SocketAccept( s ) ;
553  }else{
554  return SocketVoid ;
555  }
556 }
557 
558 static inline void _SocketClose( socket_t * p )
559 {
560  socket_t s = *p ;
561  int fd = s->fd ;
562  struct sockaddr_un * e ;
563 
564  *p = SocketVoid ;
565 
566  shutdown( fd,SHUT_RDWR ) ;
567  close( fd ) ;
568 
569  if( s->domain == AF_UNIX ) {
570  if( s->socket_server ){
571  e = s->socket ;
572  unlink( e->sun_path ) ;
573  }
574  }
575 
576  free( s->socket ) ;
577 
578  free( s->inetAddress ) ;
579 
580  free( s ) ;
581 }
582 
584 {
585  if( p != NULL && *p != SocketVoid ){
586  _SocketClose( p ) ;
587  }
588 }
589 
591 {
592  if( s != NULL ){
593  shutdown( s->fd,SHUT_WR ) ;
594  }
595 }
596 
598 {
599  if( s != NULL ){
600  shutdown( s->fd,SHUT_RD ) ;
601  }
602 }
603 
604 static inline int _SocketConnect( socket_t s )
605 {
606  return connect( s->fd,s->socket,s->size ) == 0 ;
607 }
608 
610 {
611  if( s == NULL || *s == SocketVoid ){
612  return 0 ;
613  }
614  if( _SocketConnect( *s ) ){
615  return 1 ;
616  }else{
617  _SocketClose( s ) ;
618  return 0 ;
619  }
620 }
621 
623 {
624  if( s != SocketVoid ){
625  s->cmax = m ;
626  }
627 }
628 
630 {
631  int flags ;
632  if( s == SocketVoid ){
633  return -1 ;
634  }else{
635  flags = fcntl( s->fd,F_GETFL,0 );
636  if( flags == -1 ){
637  return -1 ;
638  }else{
639  return fcntl( s->fd,F_SETFL,flags | O_NONBLOCK ) ;
640  }
641  }
642 }
643 
645 {
646  int flags ;
647  if( s == SocketVoid ){
648  return -1 ;
649  }else{
650  flags = fcntl( s->fd,F_GETFL,0 );
651  if( flags == -1 ){
652  return -1 ;
653  }else{
654  return fcntl( s->fd,F_SETFL,flags & ~O_NONBLOCK ) ;
655  }
656  }
657 }
658 
660 {
661  if( s == SocketVoid ){
662  return 0 ;
663  }else{
664  return listen( s->fd,s->cmax ) == 0 ;
665  }
666 }
667 
668 ssize_t SocketGetData_2( socket_t s,char * buffer,size_t len )
669 {
670  ssize_t e ;
671  if( s == SocketVoid ){
672  return -1 ;
673  }else{
674  len = len - 1 ;
675  e = read( s->fd,buffer,len ) ;
676  if( e >= 0 ){
677  buffer[ e ] = '\0' ;
678  }
679  return e ;
680  }
681 }
682 
683 ssize_t SocketGetData_3( socket_t s,char * buffer,size_t len,int timeout )
684 {
685  if( _SocketNotTimedOut( s,( time_t )timeout,READ ) ){
686  return SocketGetData_2( s,buffer,len ) ;
687  }else{
688  return -1 ;
689  }
690 }
691 
692 #define BUFFSIZE 32
693 #define BUFFERINIT 64
694 #define FACTOR 2
695 
696 static inline char * __expandBuffer( char * buffer,size_t new_size,size_t * buff_size )
697 {
698  char * e ;
699  if( new_size >= *buff_size ){
700  *buff_size = *buff_size * FACTOR ;
701  e = realloc( buffer,*buff_size ) ;
702  if( e == NULL ){
703  free( buffer ) ;
704  _SocketError() ;
705  return NULL ;
706  }else{
707  return e ;
708  }
709  }else{
710  return buffer ;
711  }
712 }
713 
714 ssize_t SocketGetData( socket_t s,char ** e )
715 {
716  int fd ;
717  ssize_t result ;
718  size_t total = 0 ;
719  size_t buff_size = BUFFERINIT ;
720 
721  char buffer[ BUFFSIZE ] ;
722  char * d ;
723  char * f ;
724 
725  if( s == SocketVoid ){
726  return -1 ;
727  }
728 
729  f = malloc( sizeof( char ) * buff_size ) ;
730 
731  if( f == NULL ){
732  _SocketError() ;
733  return -1 ;
734  }else{
735  fd = s->fd ;
736 
737  while( 1 ){
738  result = read( fd,buffer,BUFFSIZE ) ;
739 
740  if( result <= 0 ){
741  if( total ){
742  break ;
743  }else{
744  free( f ) ;
745  if( result < 0 ){
746  return -1 ;
747  }else{
748  return 0 ;
749  }
750  }
751  }else{
752  d = __expandBuffer( f,total + (size_t)result,&buff_size ) ;
753 
754  if( d == NULL ){
755  free( f ) ;
756  _SocketError() ;
757  return -1 ;
758  }else{
759  f = d ;
760  memcpy( f + total,buffer,(size_t)result ) ;
761  total = total + (size_t)result ;
762  }
763  }
764  }
765 
766  if( total ){
767  d = ( char * ) realloc( f,total + 1 ) ;
768  if( d == NULL ){
769  free( f ) ;
770  _SocketError() ;
771  return -1 ;
772  }else{
773  d[ total ] = '\0' ;
774  *e = d ;
775  }
776  }else{
777  free( f ) ;
778  }
779 
780  return (ssize_t)total ;
781  }
782 }
783 
784 ssize_t SocketGetData_1( socket_t s,char ** e,size_t len )
785 {
786  int fd ;
787  ssize_t result ;
788  size_t total = 0 ;
789  size_t buff_size = BUFFERINIT ;
790 
791  char buffer[ BUFFSIZE ] ;
792  char * d ;
793  char * f ;
794 
795  if( s == SocketVoid ){
796  return -1 ;
797  }
798 
799  f = malloc( sizeof( char ) * buff_size ) ;
800 
801  if( f == NULL ){
802  _SocketError() ;
803  return -1 ;
804  }else{
805  fd = s->fd ;
806  while( 1 ){
807  result = read( fd,buffer,BUFFSIZE ) ;
808 
809  if( result <= 0 ){
810 
811  if( total ){
812  break ;
813  }else{
814  free( f ) ;
815  if( result < 0 ){
816  return -1 ;
817  }else{
818  return 0 ;
819  }
820  }
821  }else{
822  d = __expandBuffer( f,total + (size_t)result,&buff_size ) ;
823 
824  if( d == NULL ){
825  free( f ) ;
826  _SocketError() ;
827  return -1 ;
828  }else{
829  f = d ;
830 
831  memcpy( f + total,buffer,(size_t)result ) ;
832  total = total +(size_t)result ;
833 
834  if( total >= len ){
835  total = len ;
836  break ;
837  }
838  }
839  }
840  }
841 
842  if( total ){
843  d = realloc( f,total + 1 ) ;
844  if( d == NULL ){
845  free( f ) ;
846  _SocketError() ;
847  return 0 ;
848  }else{
849  d[ total ] = '\0' ;
850  *e = d ;
851  }
852  }else{
853  free( f ) ;
854  }
855 
856  return (ssize_t)total ;
857  }
858 }
859 
860 ssize_t SocketSendData( socket_t s,const char * buffer,size_t len )
861 {
862  if( s == SocketVoid || buffer == NULL || len == 0 ){
863  return -1 ;
864  }else{
865  return write( s->fd,buffer,len ) ;
866  }
867 }
__expandBuffer
static char * __expandBuffer(char *buffer, size_t new_size, size_t *buff_size)
Definition: socket.c:696
SocketExitOnMemoryExaustion
void SocketExitOnMemoryExaustion(void(*f)(void))
Definition: socket.c:57
SocketLocalWithOptions
socket_t SocketLocalWithOptions(const char *address, int type, int protocol)
Definition: socket.c:193
_fcn_
static void(* _fcn_)(void)
Definition: socket.c:55
SocketSetDoNotBlock
int SocketSetDoNotBlock(socket_t s)
Definition: socket.c:629
_SocketClose
static void _SocketClose(socket_t *p)
Definition: socket.c:558
SocketNet
socket_t SocketNet(const char *address, int port)
Definition: socket.c:238
SocketIsBlocking
int SocketIsBlocking(socket_t s)
Definition: socket.c:510
SocketFileDescriptor
int SocketFileDescriptor(socket_t s)
Definition: socket.c:184
_SocketNetAddress6
static const char * _SocketNetAddress6(socket_t s)
Definition: socket.c:300
_SocketAcceptLocal
static socket_t _SocketAcceptLocal(socket_t s)
Definition: socket.c:376
_SocketNotTimedOut
static int _SocketNotTimedOut(socket_t s, time_t time, int mode)
Definition: socket.c:525
BUFFSIZE
#define BUFFSIZE
Definition: socket.c:692
BUFFERINIT
#define BUFFERINIT
Definition: socket.c:693
SocketType_t::size
socklen_t size
Definition: socket.c:49
SocketSetBlock
int SocketSetBlock(socket_t s)
Definition: socket.c:644
READ
#define READ
Definition: socket.c:522
SocketNet6
socket_t SocketNet6(const char *address, int port)
Definition: socket.c:271
SocketGetData
ssize_t SocketGetData(socket_t s, char **e)
Definition: socket.c:714
SocketNetWithOptions6
socket_t SocketNetWithOptions6(const char *address, int port, int type, int protocol)
Definition: socket.c:243
FACTOR
#define FACTOR
Definition: socket.c:694
SocketType_t::fd
int fd
Definition: socket.c:50
SocketClose
void SocketClose(socket_t *p)
Definition: socket.c:583
SocketListen
int SocketListen(socket_t s)
Definition: socket.c:659
SocketVoid
#define SocketVoid
Definition: socket.h:32
SocketConnect
int SocketConnect(socket_t *s)
Definition: socket.c:609
SocketType_t::inetAddress
char * inetAddress
Definition: socket.c:52
SocketType_t::domain
int domain
Definition: socket.c:48
SocketGetData_2
ssize_t SocketGetData_2(socket_t s, char *buffer, size_t len)
Definition: socket.c:668
socket_t
struct SocketType_t * socket_t
Definition: socket.h:30
_SocketNet6
static socket_t _SocketNet6(void)
Definition: socket.c:121
SocketSendData
ssize_t SocketSendData(socket_t s, const char *buffer, size_t len)
Definition: socket.c:860
_SocketAcceptNet6
static socket_t _SocketAcceptNet6(socket_t s)
Definition: socket.c:462
SocketSetListenMaximum
void SocketSetListenMaximum(socket_t s, int m)
Definition: socket.c:622
_SocketConnect
static int _SocketConnect(socket_t s)
Definition: socket.c:604
SocketGetData_1
ssize_t SocketGetData_1(socket_t s, char **e, size_t len)
Definition: socket.c:784
_SocketError
static socket_t _SocketError(void)
Definition: socket.c:62
_SocketLocal
static socket_t _SocketLocal(void)
Definition: socket.c:70
SocketType_t
Definition: socket.c:42
SocketCloseWriteChannel
void SocketCloseWriteChannel(socket_t s)
Definition: socket.c:590
e
static QString e
Definition: about.cpp:31
SocketType_t::type
int type
Definition: socket.c:45
_SocketLocalAddress
static const char * _SocketLocalAddress(socket_t s)
Definition: socket.c:324
SocketGetData_3
ssize_t SocketGetData_3(socket_t s, char *buffer, size_t len, int timeout)
Definition: socket.c:683
SocketAcceptWithTimeOut
socket_t SocketAcceptWithTimeOut(socket_t s, time_t time)
Definition: socket.c:549
Socket
socket_t Socket(int domain, int type, int protocol)
Definition: socket.c:147
socket.h
SocketLocal
socket_t SocketLocal(const char *address)
Definition: socket.c:205
SocketType_t::cmax
int cmax
Definition: socket.c:47
_SocketNetAddress
static const char * _SocketNetAddress(socket_t s)
Definition: socket.c:276
SocketCloseReadChannel
void SocketCloseReadChannel(socket_t s)
Definition: socket.c:597
SocketAddress
const char * SocketAddress(socket_t s)
Definition: socket.c:330
SocketType_t::protocol
int protocol
Definition: socket.c:46
SocketAccept
socket_t SocketAccept(socket_t s)
Definition: socket.c:500
SocketType_t::socket
void * socket
Definition: socket.c:51
_SocketNet
static socket_t _SocketNet(void)
Definition: socket.c:95
_SocketAcceptNet
static socket_t _SocketAcceptNet(socket_t s)
Definition: socket.c:424
SocketNetWithOptions
socket_t SocketNetWithOptions(const char *address, int port, int type, int protocol)
Definition: socket.c:210
SocketBind
int SocketBind(socket_t s)
Definition: socket.c:344
SocketType_t::socket_server
int socket_server
Definition: socket.c:44