home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / CEREBRUM / WAT9609.ZIP / SRC / BSDNAME.C < prev    next >
Text File  |  1994-11-28  |  2KB  |  100 lines

  1. #include <copyright.h>
  2. #include <stdio.h>
  3. #include <wattcp.h>
  4. #include <stdlib.h>    /* itoa */
  5. #include <string.h>
  6. #include <elib.h>
  7.  
  8. int getpeername( sock_type *s, void *dest, int *len )
  9. {
  10.     struct sockaddr temp;
  11.     int ltemp;
  12.  
  13.     memset( &temp, 0, sizeof( struct sockaddr ));
  14.     temp.s_ip = s->tcp.hisaddr;
  15.     temp.s_port = s->tcp.hisport;
  16.  
  17.     if (!s->tcp.hisaddr || !s->tcp.hisport || ! _chk_socket( s )) {
  18.         if (len) *len = 0;
  19.         return( -1 );
  20.     }
  21.  
  22.     /* how much do we move */
  23.     ltemp = (len) ? *len : sizeof( struct sockaddr );
  24.     if (ltemp > sizeof( struct sockaddr)) ltemp = sizeof( struct sockaddr );
  25.     qmove( &temp, dest, ltemp );
  26.  
  27.     if (len) *len = ltemp;
  28.     return( 0 );
  29. }
  30.  
  31. int getsockname(  sock_type *s, void *dest, int *len )
  32. {
  33.     struct sockaddr temp;
  34.     int ltemp;
  35.  
  36.     memset( &temp, 0, sizeof( struct sockaddr ));
  37.     temp.s_ip = s->tcp.myaddr;
  38.     temp.s_port = s->tcp.myport;
  39.  
  40.     if (!s->tcp.hisaddr || !s->tcp.hisport || ! _chk_socket( s )) {
  41.         if (len) *len = 0;
  42.         return( -1 );
  43.     }
  44.  
  45.     /* how much do we move */
  46.     ltemp = (len) ? *len : sizeof( struct sockaddr );
  47.     if (ltemp > sizeof( struct sockaddr)) ltemp = sizeof( struct sockaddr );
  48.     qmove( &temp, dest, ltemp );
  49.  
  50.     if (len) *len = ltemp;
  51.     return( 0 );
  52. }
  53.  
  54. char *getdomainname( char *name, int length )
  55. {
  56.     if ( length ) {
  57.     if ( length < strlen( def_domain ))
  58.         *name = 0;
  59.     else
  60.         strcpy( name, def_domain );
  61.     return( name );
  62.     }
  63.     return( ( def_domain && *def_domain ) ? def_domain : NULL );
  64. }
  65.  
  66. char *setdomainname( char *string )
  67. {
  68.     return( def_domain = string );
  69. }
  70.  
  71. char *gethostname( char *name, int len )
  72. {
  73.     if ( len ) {
  74.     if (len < strlen( _hostname ))
  75.         *name = 0;
  76.     else
  77.         strcpy( name, _hostname );
  78.     return( name );
  79.     }
  80.     return( ( _hostname && *_hostname ) ?  _hostname  : NULL );
  81. }
  82.  
  83. char *sethostname( char *name )
  84. {
  85.     return( _hostname = name );
  86. }
  87.  
  88. void psocket( sock_type *s )
  89. {
  90.     char buffer[255];
  91.  
  92.     outch( '[' );
  93.     outs( inet_ntoa( buffer, s->tcp.hisaddr) );
  94.     outch( ':' );
  95.     itoa( s->tcp.hisport, buffer, 10 );
  96.     outs( buffer );
  97.     outch( ']' );
  98.  
  99. }
  100.