Exemplo n.º 1
0
int cmd_ntp( int argc, char ** argv )
{ 
	unsigned long ip;
	char ipstr[ 20 ];

	struct TIME time;
	
	if ( argc == 2 )
	{
		ip = strtoip( argv[1] );

		if ( ip == 0 )
		{
			ip = DNS_ResolveName( argv[ 1 ] );
			if ( ip == DNS_NO_ANSWER )
			{
				printf_P( PSTR("Fehler\r\n"));
				return( 0 );
			}
		}
		
		printf_P( PSTR("Hole Zeit von %s\r\n"), argv[ 1 ] );
		
		if( checkConfigName_P( UTCZONE_P ) != -1 )
			readConfig_P ( UTCZONE_P, ipstr );
		else
			ipstr[0] = '\0';

		if ( NTP_GetTime( ip , 0 , atol( ipstr ) ) != NTP_ERROR )
		{
			CLOCK_GetTime( &time );
			printf_P( PSTR("Neue Zeit: %02d:%02d:%02d\r\n") , time.hh , time.mm , time.ss );
		}
		else
			printf_P( PSTR("Fehler\r\n"));			
	}
	else
		printf_P( PSTR("ntp <ntpserver>\r\n"));

	return( 0 );
}
Exemplo n.º 2
0
/**
 * DHCP: Obtains IP and configuration info from DHCP server
 *       (makes several attempts).
 *
 * @param  boot_device   a socket number used to send and receive packets
 * @param  fn_ip         contains the following configuration information:
 *                       client MAC, client IP, TFTP-server MAC, 
 *                       TFTP-server IP, Boot file name
 * @return               ZERO - IP and configuration info obtained;
 *                       NON ZERO - error condition occurs.
 */
int32_t
dhcp(char *ret_buffer, filename_ip_t * fn_ip, unsigned int retries) {
	int i = (int) retries+1;

	uint32_t dhcp_tftp_ip     = 0;
	strcpy((char *) dhcp_filename, "");
	strcpy((char *) dhcp_tftp_name, "");

	response_buffer = ret_buffer;

	printf("    ");

	do {
		printf("\b\b\b%03d", i-1);
		if (getchar() == 27) {
			printf("\nAborted\n");
			return -1;
		}
		if (!--i) {
			printf("\nGiving up after %d DHCP requests\n", retries);
			return -1;
		}
	} while (!dhcp_attempt());
	printf("\b\b\b\b");

	if (fn_ip->own_ip) {
		dhcp_own_ip = fn_ip->own_ip;
	}
	if (fn_ip->server_ip) {
		dhcp_siaddr_ip = fn_ip->server_ip;
	}
	if(fn_ip->filename[0] != 0) {
		strcpy((char *) dhcp_filename, (char *) fn_ip->filename);
	}

	// TFTP SERVER
	if (!strlen((char *) dhcp_tftp_name)) {
		if (!dhcp_siaddr_ip) {
			// ERROR: TFTP name is not presented
			return -3;
		}

		// take TFTP-ip from siaddr field
		dhcp_tftp_ip = dhcp_siaddr_ip;
	}
	else {
		// TFTP server defined by its name
		if (!strtoip(dhcp_tftp_name, &(dhcp_tftp_ip))) {
			if (!dns_get_ip(dhcp_tftp_name, &(dhcp_tftp_ip))) {
				// DNS error - can't obtain TFTP-server name  
				// Use TFTP-ip from siaddr field, if presented
				if (dhcp_siaddr_ip) {
					dhcp_tftp_ip = dhcp_siaddr_ip;
				}
				else {
					// ERROR: Can't obtain TFTP server IP
					return -4;
				}
			}
		}
	}

	// Store configuration info into filename_ip strucutre
	fn_ip -> own_ip = dhcp_own_ip;
	fn_ip -> server_ip = dhcp_tftp_ip;
	strcpy((char *) fn_ip -> filename, (char *) dhcp_filename);

	return 0;
}
Exemplo n.º 3
0
/**
 * print_element_names:
 * @a_node: the initial xml node to consider.
 *
 * Prints the names of the all the xml elements
 * that are siblings or children of a given xml node.
 */
gchar *
read_connection(struct connection *conn, xmlNode * a_node)
{
	static gchar err[512];
	bzero(conn, sizeof(*conn));
	xmlAttr *properties = a_node->properties;

	/* Set some defaults */
	conn->allocation_type = ALLOCATION_TYPE_DHCP;
	conn->connection_type = CONNECTION_TYPE_WLAN;
	conn->phy.wlan.auth_type = AUTH_TYPE_OPEN;
	conn->phy.wlan.encryption_type = ENCRYPTION_TYPE_NONE;
	conn->phy.wlan.key_type = KEY_TYPE_ASCII;

	for(properties = a_node->properties; properties; properties = properties->next) {
		char *name = (char *)properties->name;
		char *value = (char *)properties->children->content;

		if(!strcmp(name, "type")) {
			if(!strcmp(value, "wlan"))
				conn->connection_type = CONNECTION_TYPE_WLAN;
			else if(!strcmp(value, "lan"))
				conn->connection_type = CONNECTION_TYPE_LAN;
			else {
				conn->connection_type = CONNECTION_TYPE_UNKNOWN;
				g_snprintf(err, sizeof(err), "Unrecognized connection type: %s\n", value);
				return err;
			}
		}

		else if(!strcmp(name, "hwaddr"))
			strncpy(conn->phy.wlan.hwaddr, value, sizeof(conn->phy.wlan.hwaddr)-1);

		else if(!strcmp(name, "ssid")) {
			strncpy(conn->phy.wlan.ssid, value, sizeof(conn->phy.wlan.ssid)-1);
			conn->phy.wlan.ssid_len = xmlUTF8Size(properties->name);
		}

		else if(!strcmp(name, "auth")) {
			if(!strcmp(value, "OPEN"))
				conn->phy.wlan.auth_type = AUTH_TYPE_OPEN;
			else if(!strcmp(value, "WEPAUTO"))
				conn->phy.wlan.auth_type = AUTH_TYPE_WEPAUTO;
			else if(!strcmp(value, "WPAPSK"))
				conn->phy.wlan.auth_type = AUTH_TYPE_WPAPSK;
			else if(!strcmp(value, "WPA2PSK"))
				conn->phy.wlan.auth_type = AUTH_TYPE_WPA2PSK;
			else {
				conn->phy.wlan.auth_type = AUTH_TYPE_UNKNOWN;
				g_snprintf(err, sizeof(err), "Unrecognized auth: %s\n", value);
				return err;
			}
		}

		else if(!strcmp(name, "encryption")) {
			if(!strcmp(value, "NONE"))
				conn->phy.wlan.encryption_type = ENCRYPTION_TYPE_NONE;
			else if(!strcmp(value, "WEP"))
				conn->phy.wlan.encryption_type = ENCRYPTION_TYPE_WEP;
			else if(!strcmp(value, "TKIP"))
				conn->phy.wlan.encryption_type = ENCRYPTION_TYPE_TKIP;
			else if(!strcmp(value, "AES"))
				conn->phy.wlan.encryption_type = ENCRYPTION_TYPE_AES;
			else {
				conn->phy.wlan.encryption_type = ENCRYPTION_TYPE_UNKNOWN;
				g_snprintf(err, sizeof(err), "Unrecognized encryption: %s\n", value);
				return err;
			}
		}

		else if(!strcmp(name, "encoding")) {
			if(!strcmp(value, "ascii"))
				conn->phy.wlan.key_type = KEY_TYPE_ASCII;
			else if(!strcmp(value, "hex"))
				conn->phy.wlan.key_type = KEY_TYPE_HEX;
			else {
				conn->phy.wlan.key_type = KEY_TYPE_UNKNOWN;
				g_snprintf(err, sizeof(err), "Unrecognized encoding type: %s\n", value);
				return err;
			}
		}

		else if(!strcmp(name, "key"))
			strncpy(conn->phy.wlan.key, value, sizeof(conn->phy.wlan.key)-1);

		else if(!strcmp(name, "allocation")) {
			if(!strcmp(value, "static"))
				conn->allocation_type = ALLOCATION_TYPE_STATIC;
			else if(!strcmp(value, "dhcp"))
				conn->allocation_type = ALLOCATION_TYPE_DHCP;
			else {
				conn->allocation_type = ALLOCATION_TYPE_UNKNOWN;
				g_snprintf(err, sizeof(err), "Unrecognized allocation: %s\n", value);
				return err;
			}
		}

		else if(!strcmp(name, "ip"))
			strtoip(value, &conn->ip);
		else if(!strcmp(name, "netmask"))
			strtoip(value, &conn->netmask);
		else if(!strcmp(name, "gateway"))
			strtoip(value, &conn->gateway);
		else if(!strcmp(name, "nameserver1"))
			strtoip(value, &conn->nameserver1);
		else if(!strcmp(name, "nameserver2"))
			strtoip(value, &conn->nameserver2);
		else if(!strcmp(name, "username"))
			; // Ignore
		else {
			fprintf(stderr, "Unrecognized field: %s\n", name);
		}
	}

	return NULL;
}