 	
 	configure_dhcp = (nn, nc, add_dhcp, modify_dhcp) ->
 		(callback) ->
+			return callback new Error "no ip specified for network #{nn}" if not nc.ip?
+			return callback new Error "no netmask specified for network #{nn}" if not nc.netmask?
+			return callback new Error "no dhcp lower_ip specified for network #{nn}" if not nc.dhcp.lower_ip?
+			return callback new Error "no dhcp upper_ip specified for network #{nn}" if not nc.dhcp.upper_ip?
+			
 			dhcp.list_servers (err, servers) ->
 				return callback err if err
 				
-				s = servers.reduce (previous, current) ->
-					return previous if previous and previous.NetworkName == nn or previous.NetworkName == "HostInterfaceNetworking-#{nn}"
-					return current if current and current.NetworkName == nn or previous.NetworkName == "HostInterfaceNetworking-#{nn}"
+				s = servers.narrow (previous, current) ->
+					return previous if previous and (previous.NetworkName == nn or previous.NetworkName == "HostInterfaceNetworking-#{nn}")
+					return current if current and (current.NetworkName == nn or current.NetworkName == "HostInterfaceNetworking-#{nn}")
 					
 				h = () ->
 					s.IP != nc.ip or

			when 'hostonly'
				actions.push do (vm, adaptor, index) ->
					(callback) ->
						network.set_hostonly vm, index, adaptor.network, callback
						
			when 'internal'
				actions.push do (vm, adaptor, index) ->
					(callback) ->
						network.set_internal vm, index, adaptor.network, callback
						
			when 'nat'

async = require 'async'
dhcp = require './dhcp.coffee'
proto = require './proto.coffee'
share = require './share.coffee'
network = require './network.coffee'

