Example #1
0
char *tcp_clienthost ()
{
  if (!myClientHost) {
    size_t sadrlen;
    struct sockaddr *sadr = ip_newsockaddr (&sadrlen);
    if (getpeername (0,sadr,(void *) &sadrlen)) {
      char *s,*t,*v,tmp[MAILTMPLEN];
      if ((s = getenv (t = "SSH_CLIENT")) ||
	  (s = getenv (t = "KRB5REMOTEADDR")) ||
	  (s = getenv (t = "SSH2_CLIENT"))) {
	if (v = strchr (s,' ')) *v = '\0';
	sprintf (v = tmp,"%.80s=%.80s",t,s);
      }
      else v = "UNKNOWN";
      myClientHost = cpystr (v);
    }
    else {			/* get stdin's peer name */
      myClientHost = tcp_name (sadr,T);
      if (!myClientAddr) myClientAddr = cpystr (ip_sockaddrtostring (sadr));
      if (myClientPort < 0) myClientPort = ip_sockaddrtoport (sadr);
    }
    fs_give ((void **) &sadr);
  }
  return myClientHost;
}
Example #2
0
char *tcp_remotehost (TCPSTREAM *stream)
{
  if (!stream->remotehost) {
    size_t sadrlen;
    struct sockaddr *sadr = ip_newsockaddr (&sadrlen);
    stream->remotehost =	/* get socket's peer name */
      getpeername (stream->tcpsi,sadr,(void *) &sadrlen) ?
        cpystr (stream->host) : tcp_name (sadr,NIL);
    fs_give ((void **) &sadr);
  }
  return stream->remotehost;
}
Example #3
0
char *tcp_serveraddr ()
{
  if (!myServerAddr) {
    size_t sadrlen;
    struct sockaddr *sadr = ip_newsockaddr (&sadrlen);
    myServerAddr =		/* get stdin's peer name */
      ((getsockname (0,sadr,&sadrlen) == SOCKET_ERROR) || (sadrlen <= 0)) ?
      cpystr ("UNKNOWN") : cpystr (ip_sockaddrtostring (sadr));
    fs_give ((void **) &sadr);
  }
  return myServerAddr;
}
Example #4
0
char *tcp_clienthost ()
{
  if (!myClientHost) {
    size_t sadrlen;
    struct sockaddr *sadr = ip_newsockaddr (&sadrlen);
    myClientHost =		/* get stdin's peer name */
      ((getpeername (0,sadr,&sadrlen) == SOCKET_ERROR) || (sadrlen <= 0)) ?
      cpystr ("UNKNOWN") : tcp_name (sadr,T);
    fs_give ((void **) &sadr);
  }
  return myClientHost;
}
Example #5
0
char *tcp_localhost (TCPSTREAM *stream)
{
  if (!stream->localhost) {
    size_t sadrlen;
    struct sockaddr *sadr = ip_newsockaddr (&sadrlen);
    stream->localhost =		/* get socket's name */
      ((stream->port & 0xffff000) ||
       getsockname (stream->tcpsi,sadr,(void *) &sadrlen)) ?
      cpystr (mylocalhost ()) : tcp_name (sadr,NIL);
    fs_give ((void **) &sadr);
  }
  return stream->localhost;	/* return local host name */
}
Example #6
0
char *tcp_serveraddr ()
{
  if (!myServerAddr) {
    size_t sadrlen;
    struct sockaddr *sadr = ip_newsockaddr (&sadrlen);
    if (getsockname (0,sadr,(void *) &sadrlen))
      myServerAddr = cpystr ("UNKNOWN");
    else {			/* get stdin's name */
      myServerAddr = cpystr (ip_sockaddrtostring (sadr));
      if (myServerPort < 0) myServerPort = ip_sockaddrtoport (sadr);
    }
    fs_give ((void **) &sadr);
  }
  return myServerAddr;
}
Example #7
0
char *tcp_clientaddr ()
{
  if (!myClientAddr) {
    char buf[NI_MAXHOST];
    size_t sadrlen;
    struct sockaddr *sadr = ip_newsockaddr (&sadrlen);
    if (getpeername (0,sadr,(void *) &sadrlen))
      myClientAddr = cpystr ("UNKNOWN");
    else {			/* get stdin's peer name */
      myClientAddr = cpystr (ip_sockaddrtostring (sadr,buf));
      if (myClientPort < 0) myClientPort = ip_sockaddrtoport (sadr);
    }
    fs_give ((void **) &sadr);
  }
  return myClientAddr;
}
Example #8
0
char *tcp_serverhost ()
{
  if (!myServerHost) {		/* once-only */
    size_t sadrlen;
    struct sockaddr *sadr = ip_newsockaddr (&sadrlen);
				/* get stdin's name */
    if (getsockname (0,sadr,(void *) &sadrlen))
      myServerHost = cpystr (mylocalhost ());
    else {			/* get stdin's name */
      myServerHost = tcp_name (sadr,NIL);
      if (!myServerAddr) myServerAddr = cpystr (ip_sockaddrtostring (sadr));
      if (myServerPort < 0) myServerPort = ip_sockaddrtoport (sadr);
    }
    fs_give ((void **) &sadr);
  }
  return myServerHost;
}
Example #9
0
struct sockaddr *ip_sockaddr (int family,void *adr,size_t adrlen,
                              unsigned short port,size_t *len)
{
    struct sockaddr *sadr = ip_newsockaddr (len);
    switch (family) {		/* build socket address based upon family */
    case AF_INET:			/* IPv4 */
        sadr->sa_family = PF_INET;
        /* copy host address */
        memcpy (&SADR4ADR (sadr),adr,adrlen);
        /* copy port number in network format */
        SADR4PORT (sadr) = htons (port);
        *len = SADR4LEN;
        break;
    default:			/* non-IP?? */
        sadr->sa_family = PF_UNSPEC;
        break;
    }
    return sadr;
}
Example #10
0
char *tcp_serverhost ()
{
  if (!myServerHost) {
    size_t sadrlen;
    struct sockaddr *sadr = ip_newsockaddr (&sadrlen);
    if (!wsa_initted++) {	/* init Windows Sockets */
      WSADATA wsock;
      if (WSAStartup (WINSOCK_VERSION,&wsock)) {
	wsa_initted = 0;
	return "random-pc";	/* try again later? */
      }
    }
				/* get stdin's name */
    myServerHost = ((getsockname (0,sadr,(void *) &sadrlen) == SOCKET_ERROR)||
		    (sadrlen <= 0) ||
                    ((myServerPort = ip_sockaddrtoport (sadr)) < 0)) ?
      cpystr (mylocalhost ()) : tcp_name (sadr,NIL);
    fs_give ((void **) &sadr);
  }
  return myServerHost;
}