netlib.c
int generic_addr(struct sockaddr_in *addr, struct vtun_addr *vaddr)
{
     struct hostent *hent;
     memset(addr, 0, sizeof(struct sockaddr_in));
  
     addr->sin_family = AF_INET;
  
     switch (vaddr->type) {
        case VTUN_ADDR_IFACE:
	 if (!(addr->sin_addr.s_addr =
	       getifaddr(vaddr->name))) {
	    vtun_syslog(LOG_ERR,
	                "Can't get address of interface %s",
	                vaddr->name);
	    return -1;
	 }
           break;
        case VTUN_ADDR_NAME:
	 if (!(hent = gethostbyname(vaddr->name))) {
	    vtun_syslog(LOG_ERR,
	                "Can't resolv local address %s",
	                vaddr->name);
	    return -1;
           }
	 addr->sin_addr.s_addr = *(unsigned long *) hent->h_addr;
           break;
        default:
           addr->sin_addr.s_addr = INADDR_ANY;
           break;
     }
  
     if (vaddr->port)
        addr->sin_port = htons(vaddr->port);

     return 0; 
}
/* Set address by interface name, ip address or hostname */
Set address by interface name, ip address or hostname
Set address by interface name ip address or hostname
int generic_addr(struct sockaddr_in *addr, struct vtun_addr *vaddr)
{
     struct hostent *hent;
     memset(addr, 0, sizeof(struct sockaddr_in));
     addr->sin_family = AF_INET;
     switch (vaddr->type) {
        case VTUN_ADDR_IFACE:
	 if (!(addr->sin_addr.s_addr =
	       getifaddr(vaddr->name))) {
	    vtun_syslog(LOG_ERR,
	                "Can't get address of interface %s",
	                vaddr->name);
	    return -1;
	 }
           break;
        case VTUN_ADDR_NAME:
	 if (!(hent = gethostbyname(vaddr->name))) {
	    vtun_syslog(LOG_ERR,
	                "Can't resolv local address %s",
	                vaddr->name);
	    return -1;
           }
	 addr->sin_addr.s_addr = *(unsigned long *) hent->h_addr;
           break;
        default:
           addr->sin_addr.s_addr = INADDR_ANY;
           break;
     }
     if (vaddr->port)
        addr->sin_port = htons(vaddr->port);
     return 0; 
}
int generic_addr ( struct sockaddr_in * addr , struct vtun_addr * vaddr ) { struct hostent * hent ; memset ( addr , 0 , sizeof ( struct sockaddr_in ) ) ; addr -> sin_family = AF_INET ; switch ( vaddr -> type ) { case VTUN_ADDR_IFACE : if ( ! ( addr -> sin_addr . s_addr = getifaddr ( vaddr -> name ) ) ) { vtun_syslog ( LOG_ERR , " " , vaddr -> name ) ; return -1 ; } break ; case VTUN_ADDR_NAME : if ( ! ( hent = gethostbyname ( vaddr -> name ) ) ) { vtun_syslog ( LOG_ERR , " " , vaddr -> name ) ; return -1 ; } addr -> sin_addr . s_addr = * ( unsigned long * ) hent -> h_addr ; break ; default : addr -> sin_addr . s_addr = INADDR_ANY ; break ; } if ( vaddr -> port ) addr -> sin_port = htons ( vaddr -> port ) ; return 0 ; }
Set address by interface name, ip address or hostname
Set address by interface name ip address or hostname