Initial CMake support.

Fix an off-by-one array initialization.
Clean up VERSION a bit.
This commit is contained in:
Nicholas J. Kain 2010-11-12 04:44:25 -05:00
parent 5bea46a071
commit c999fee9f5
4 changed files with 55 additions and 7 deletions

25
CMakeLists.txt Normal file
View File

@ -0,0 +1,25 @@
project (ifchd)
cmake_minimum_required (VERSION 2.6)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -s -std=gnu99 -pedantic -Wall -lcap -DHAVE_CLEARENV -DLINUX")
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -s -std=gnu99 -pedantic -Wall -lcap -DHAVE_CLEARENV -DLINUX")
#include_directories("${PROJECT_SOURCE_DIR}/ncmlib")
#add_subdirectory(ncmlib)
set(IFCHD_SRCS
ifchd.c
linux.c
strlist.c
signals.c
pidfile.c
chroot.c
nstrl.c
log.c
)
add_executable(ifchd ${IFCHD_SRCS})
#target_link_libraries(ifchd ncmlib)
add_subdirectory(ndhc)

21
ndhc/CMakeLists.txt Normal file
View File

@ -0,0 +1,21 @@
project (ndhc)
cmake_minimum_required (VERSION 2.6)
#include_directories("${PROJECT_SOURCE_DIR}/ncmlib")
#add_subdirectory(ncmlib)
set(NDHC_SRCS
nstrl.c
log.c
options.c
socket.c
packet.c
rootcap.c
script.c
clientpacket.c
dhcpc.c
)
add_executable(ndhc ${NDHC_SRCS})
#target_link_libraries(ndhc ncmlib)

View File

@ -69,8 +69,8 @@ static void init_packet(struct dhcpMessage *packet, char type)
struct vendor { struct vendor {
char vendor; char vendor;
char length; char length;
char str[sizeof("ndhc "VERSION)]; char str[sizeof("ndhc")];
} vendor_id = { DHCP_VENDOR, sizeof("ndhc "VERSION) - 1, "ndhc "VERSION}; } vendor_id = { DHCP_VENDOR, sizeof("ndhc") - 1, "ndhc"};
init_header(packet, type); init_header(packet, type);
memcpy(packet->chaddr, client_config.arp, 6); memcpy(packet->chaddr, client_config.arp, 6);

View File

@ -52,6 +52,8 @@
#include "rootcap.h" #include "rootcap.h"
#include "nstrl.h" #include "nstrl.h"
#define VERSION "1.0"
static unsigned long requested_ip, server_addr, timeout; static unsigned long requested_ip, server_addr, timeout;
static unsigned long lease, t1, t2, xid, start; static unsigned long lease, t1, t2, xid, start;
static int state, packet_num, fd, listen_mode; static int state, packet_num, fd, listen_mode;
@ -142,11 +144,11 @@ static void perform_renew(void)
/* perform a release */ /* perform a release */
static void perform_release(void) static void perform_release(void)
{ {
char buf[16]; char buf[32];
struct in_addr temp_addr; struct in_addr temp_addr;
buf[16] = '\0'; memset(buf, '\0', sizeof buf);
/* send release packet */ /* send release packet */
if (state == BOUND || state == RENEWING || state == REBINDING) { if (state == BOUND || state == RENEWING || state == REBINDING) {
temp_addr.s_addr = server_addr; temp_addr.s_addr = server_addr;
@ -543,7 +545,7 @@ int main(int argc, char **argv)
strlcpy(chroot_dir, optarg, len); strlcpy(chroot_dir, optarg, len);
break; break;
case 'v': case 'v':
printf("ndhc, version %s\n\n", VERSION); printf("ndhc, version " VERSION "\n\n");
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
break; break;
default: default:
@ -551,7 +553,7 @@ int main(int argc, char **argv)
} }
} }
log_line(LOG_INFO, "ndhc client (v%s) started.\n", VERSION); log_line(LOG_INFO, "ndhc client " VERSION " started.\n");
if (read_interface(client_config.interface, &client_config.ifindex, if (read_interface(client_config.interface, &client_config.ifindex,
NULL, client_config.arp) < 0) NULL, client_config.arp) < 0)