Skip to content

Commit

Permalink
Merge pull request #20 from pemensik/master
Browse files Browse the repository at this point in the history
Compiler warnings fix
  • Loading branch information
saravana815 authored Mar 15, 2018
2 parents 97a85d9 + 3041d10 commit 564340e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ CC=gcc
#CFLAGS=-Wall -g

dhtest: dhtest.o functions.o
$(CC) dhtest.o functions.o -o dhtest
$(CC) $(LDFLAGS) dhtest.o functions.o -o dhtest

clean:
rm -f dhtest functions.o dhtest.o
4 changes: 1 addition & 3 deletions dhtest.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,10 @@ int main(int argc, char *argv[])
//scanf the custom dhcp option
//format - option_no_dec,str|num|hex|ip,option_value

u_int8_t option_no, option_type;
u_int8_t option_no;
char option_value[256] = { 0 };
u_int32_t option_value_num = { 0 }, option_value_ip = { 0 };
int option_index = 0;
int scanf_state;

if ((sscanf((char *)optarg, "%u,str,%255[^\n]s", (u_int32_t *) &option_no, option_value)) == 2) {
if ((strlen(option_value) >= 256)) {
Expand Down Expand Up @@ -490,7 +489,6 @@ int main(int argc, char *argv[])

if (verbose)
{
char *str[25];
fprintf (stderr, "Using Ethernet source addr: %s\n", mac2str (iface_mac));
fprintf (stderr, "Using DHCP chaddr: %s\n", mac2str (dhmac));
}
Expand Down
13 changes: 8 additions & 5 deletions functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ extern u_int32_t listen_timeout;

int open_socket()
{
int sock_new, non_block, tmp;
sock_packet = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
if(sock_packet < 0) {
perror("--Error on creating the socket--");
Expand Down Expand Up @@ -233,7 +232,7 @@ u_int32_t get_interface_address()
*/
int send_packet(int pkt_type)
{
int ret;
int ret = -1;
if(pkt_type == DHCP_MSGDISCOVER) {
ret = sendto(sock_packet,\
dhcp_packet_disc,\
Expand Down Expand Up @@ -400,7 +399,7 @@ int send_packet(int pkt_type)
*/
int recv_packet(int pkt_type)
{
int ret, sock_len, retval, chk_pkt_state, tmp = 0;
int ret = -1, sock_len, retval, chk_pkt_state;
fd_set read_fd;
struct timeval tval;
tval.tv_sec = 5;
Expand Down Expand Up @@ -1730,17 +1729,21 @@ int get_dhinfo()
{
FILE *dh_file;
u_char aux_dmac[ETHER_ADDR_LEN+3]; //[Fix for Seg Fault] @inov8shn - add a few extra chars to this buffer, since fscanf("%2X") below returns a u_int32_t, and was triggering a Segmentation Fault when run for last byte read (&aux_dmac[5]).
char mac_tmp[20], acq_ip_tmp[20], serv_id_tmp[20], dmac_tmp[20], ip_listen_tmp[10];
char mac_tmp[20], acq_ip_tmp[20], serv_id_tmp[20], ip_listen_tmp[10];
pid_t dh_pid;
int items;
dh_file = fopen(dhmac_fname, "r");
if(dh_file == NULL) {
return ERR_FILE_OPEN;
}
fscanf(dh_file, "Client_mac: %s\nAcquired_ip: %s\nServer_id: %s\n\
items = fscanf(dh_file, "Client_mac: %s\nAcquired_ip: %s\nServer_id: %s\n\
Host_mac: %2X:%2X:%2X:%2X:%2X:%2X\nIP_listen: %s Pid: %d", mac_tmp, acq_ip_tmp, serv_id_tmp, \
(u_int32_t *) &aux_dmac[0], (u_int32_t *) &aux_dmac[1], (u_int32_t *) &aux_dmac[2], \
(u_int32_t *) &aux_dmac[3], (u_int32_t *) &aux_dmac[4], (u_int32_t *) &aux_dmac[5], \
ip_listen_tmp, &dh_pid);
if (items == EOF || items < 11) {
return ERR_FILE_FORMAT;
}
memcpy(dmac, aux_dmac, sizeof(dmac));
option50_ip = inet_addr(acq_ip_tmp);
server_id = inet_addr(serv_id_tmp);
Expand Down
1 change: 1 addition & 0 deletions headers.h
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ struct custom_dhcp_option_hdr
#define ARP_SEND 13
#define ICMP_SEND 14
#define LISTEN_TIMOUET 15
#define ERR_FILE_FORMAT 16


/*
Expand Down

0 comments on commit 564340e

Please sign in to comment.