Index: uspace/srv/net/dhcp/dhcp.c
===================================================================
--- uspace/srv/net/dhcp/dhcp.c	(revision 947e2ef52b4d89628cb7e4dc1fec8ca166910b10)
+++ uspace/srv/net/dhcp/dhcp.c	(revision bd88bee745abe1948dac683975e4b015ecdfaf39)
@@ -39,4 +39,5 @@
 #include <inet/dnsr.h>
 #include <inet/inetcfg.h>
+#include <io/log.h>
 #include <loc.h>
 #include <net/in.h>
@@ -46,4 +47,5 @@
 #include <stdlib.h>
 
+#include "dhcp.h"
 #include "dhcp_std.h"
 
@@ -113,5 +115,5 @@
 	    (struct sockaddr *)&addr, sizeof(addr));
 	if (rc != EOK) {
-		printf("Sending failed\n");
+		log_msg(LOG_DEFAULT, LVL_ERROR, "Sending failed");
 		return rc;
 	}
@@ -154,5 +156,5 @@
 	    (struct sockaddr *)&src_addr, &src_addr_size);
 	if (rc < 0) {
-		printf("recvfrom failed (%d)\n", rc);
+		log_msg(LOG_DEFAULT, LVL_ERROR, "recvfrom failed (%d)", rc);
 		return rc;
 	}
@@ -222,5 +224,5 @@
 	size_t i;
 
-	printf("Receive reply\n");
+	log_msg(LOG_DEFAULT, LVL_DEBUG, "Receive reply");
 	memset(offer, 0, sizeof(*offer));
 
@@ -231,5 +233,5 @@
 		return rc;
 
-	printf("Your IP address: %s\n", saddr);
+	log_msg(LOG_DEFAULT, LVL_DEBUG, "Your IP address: %s", saddr);
 	free(saddr);
 
@@ -240,5 +242,5 @@
 		return rc;
 
-	printf("Next server IP address: %s\n", saddr);
+	log_msg(LOG_DEFAULT, LVL_DEBUG, "Next server IP address: %s", saddr);
 	free(saddr);
 
@@ -249,5 +251,5 @@
 		return rc;
 
-	printf("Relay agent IP address: %s\n", saddr);
+	log_msg(LOG_DEFAULT, LVL_DEBUG, "Relay agent IP address: %s", saddr);
 	free(saddr);
 
@@ -320,10 +322,10 @@
 
 	if (!have_server_id) {
-		printf("Missing server ID option.\n");
+		log_msg(LOG_DEFAULT, LVL_ERROR, "Missing server ID option.");
 		return rc;
 	}
 
 	if (!have_subnet_mask) {
-		printf("Missing subnet mask option.\n");
+		log_msg(LOG_DEFAULT, LVL_ERROR, "Missing subnet mask option.");
 		return rc;
 	}
@@ -333,5 +335,5 @@
 		return rc;
 
-	printf("Offered network address: %s\n", saddr);
+	log_msg(LOG_DEFAULT, LVL_DEBUG, "Offered network address: %s", saddr);
 	free(saddr);
 
@@ -341,5 +343,5 @@
 			return rc;
 
-		printf("Router address: %s\n", saddr);
+		log_msg(LOG_DEFAULT, LVL_DEBUG, "Router address: %s", saddr);
 		free(saddr);
 	}
@@ -350,5 +352,5 @@
 			return rc;
 
-		printf("DNS server: %s\n", saddr);
+		log_msg(LOG_DEFAULT, LVL_DEBUG, "DNS server: %s", saddr);
 		free(saddr);
 	}
@@ -367,5 +369,6 @@
 	    &addr_id);
 	if (rc != EOK) {
-		printf("Error creating IP address %s (%d)\n", "dhcp4a", rc);
+		log_msg(LOG_DEFAULT, LVL_ERROR,
+		    "Error creating IP address %s (%d)", "dhcp4a", rc);
 		return rc;
 	}
@@ -378,6 +381,6 @@
 		rc = inetcfg_sroute_create("dhcpdef", &defr, &offer->router, &sroute_id);
 		if (rc != EOK) {
-			printf("Error creating default route %s (%d).\n", "dhcpdef",
-			    rc);
+			log_msg(LOG_DEFAULT, LVL_ERROR, "Error creating "
+			    "default route %s (%d).", "dhcpdef", rc);
 			return rc;
 		}
@@ -387,6 +390,6 @@
 		rc = dnsr_set_srvaddr(&offer->dns_server);
 		if (rc != EOK) {
-			printf("%s: Error setting nameserver address (%d))\n",
-			    NAME, rc);
+			log_msg(LOG_DEFAULT, LVL_ERROR, "%s: Error setting "
+			    "nameserver address (%d))", NAME, rc);
 			return rc;
 		}
@@ -396,36 +399,21 @@
 }
 
-int main(int argc, char *argv[])
+int dhcpsrv_link_add(service_id_t link_id)
 {
 	int fd;
 	struct sockaddr_in laddr;
 	void *msg;
-	service_id_t iplink;
 	size_t msg_size;
 	dhcp_offer_t offer;
 	int rc;
 
-	if (argc < 2) {
-		printf("syntax: %s <ip-link>\n", NAME);
-		return 1;
-	}
-
-	rc = inetcfg_init();
+	log_msg(LOG_DEFAULT, LVL_DEBUG, "dhcpsrv_link_add(%zu)", link_id);
+
+	/* Get link hardware address */
+	rc = inetcfg_link_get(link_id, &link_info);
 	if (rc != EOK) {
-		printf("Error contacting inet configuration service.\n");
-		return 1;
-	}
-
-	rc = loc_service_get_id(argv[1], &iplink, 0);
-	if (rc != EOK) {
-		printf("Error resolving service '%s'.\n", argv[1]);
-		return 1;
-	}
-
-	/* Get link hardware address */
-	rc = inetcfg_link_get(iplink, &link_info);
-	if (rc != EOK) {
-		printf("Error getting properties for link '%s'.\n", argv[1]);
-		return 1;
+		log_msg(LOG_DEFAULT, LVL_ERROR, "Error getting properties "
+		    "for link %zu.", link_id);
+		return EIO;
 	}
 
@@ -436,54 +424,60 @@
 	fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
 	if (fd < 0)
-		return 1;
-
-	printf("Bind socket.\n");
+		return EIO;
+
+	log_msg(LOG_DEFAULT, LVL_DEBUG, "Bind socket.");
 	rc = bind(fd, (struct sockaddr *)&laddr, sizeof(laddr));
 	if (rc != EOK)
-		return 1;
-
-	printf("Set socket options\n");
-	rc = setsockopt(fd, SOL_SOCKET, SO_IPLINK, &iplink, sizeof(iplink));
-	if (rc != EOK)
-		return 1;
+		return EIO;
+
+	log_msg(LOG_DEFAULT, LVL_DEBUG, "Set socket options");
+	rc = setsockopt(fd, SOL_SOCKET, SO_IPLINK, &link_id, sizeof(link_id));
+	if (rc != EOK)
+		return EIO;
 
 	transport_fd = fd;
 
-	printf("Send DHCPDISCOVER\n");
+	log_msg(LOG_DEFAULT, LVL_DEBUG, "Send DHCPDISCOVER");
 	rc = dhcp_send_discover();
 	if (rc != EOK)
-		return 1;
+		return EIO;
 
 	rc = dhcp_recv_msg(&msg, &msg_size);
 	if (rc != EOK)
-		return 1;
-
-	printf("Received %zu bytes\n", msg_size);
+		return EIO;
+
+	log_msg(LOG_DEFAULT, LVL_DEBUG, "Received %zu bytes", msg_size);
 
 	rc = dhcp_recv_reply(msg, msg_size, &offer);
 	if (rc != EOK)
-		return 1;
+		return EIO;
 
 	rc = dhcp_send_request(&offer);
 	if (rc != EOK)
-		return 1;
+		return EIO;
 
 	rc = dhcp_recv_msg(&msg, &msg_size);
 	if (rc != EOK)
-		return 1;
-
-	printf("Received %zu bytes\n", msg_size);
+		return EIO;
+
+	log_msg(LOG_DEFAULT, LVL_DEBUG, "Received %zu bytes", msg_size);
 
 	rc = dhcp_recv_reply(msg, msg_size, &offer);
 	if (rc != EOK)
-		return 1;
-
-	rc = dhcp_cfg_create(iplink, &offer);
-	if (rc != EOK)
-		return 1;
+		return EIO;
+
+	rc = dhcp_cfg_create(link_id, &offer);
+	if (rc != EOK)
+		return EIO;
 
 	closesocket(fd);
-	return 0;
-}
+	return EOK;
+}
+
+int dhcpsrv_link_remove(service_id_t link_id)
+{
+	return ENOTSUP;
+}
+
 
 /** @}
