Skip to content

Commit

Permalink
add bindip argument to indicate ip binding. (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
mchome committed Jun 15, 2017
1 parent df2e335 commit cfda241
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 9 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# dogcom [![travis-ci](https://travis-ci.org/mchome/dogcom.svg "Build status")](https://travis-ci.org/mchome/dogcom) [![badge](https://img.shields.io/badge/%20built%20with-%20%E2%9D%A4-ff69b4.svg "build with love")](https://github.com/mchome/dogcom) [![version](https://img.shields.io/badge/stable%20-%20v1.3.1-4dc71f.svg "stable version")](https://github.com/mchome/dogcom/tree/v1.3.1)
# dogcom [![travis-ci](https://travis-ci.org/mchome/dogcom.svg "Build status")](https://travis-ci.org/mchome/dogcom) [![badge](https://img.shields.io/badge/%20built%20with-%20%E2%9D%A4-ff69b4.svg "build with love")](https://github.com/mchome/dogcom) [![version](https://img.shields.io/badge/stable%20-%20v1.4.0-4dc71f.svg "stable version")](https://github.com/mchome/dogcom/tree/v1.4.0)

[Drcom-generic](https://github.com/drcoms/drcom-generic) implementation in C.

Expand All @@ -9,6 +9,7 @@ Usage:
Options:
--mode <dhcp/pppoe>, -m <dhcp/pppoe> set your dogcom mode
--conf <FILEPATH>, -c <FILEPATH> import configuration file
--bindip <IPADDR>, -b <IPADDR> bind your ip address(default is 0.0.0.0)
--log <LOGPATH>, -l <LOGPATH> specify log file
--802.1x, -x enable 802.1x
--daemon, -d set daemon flag
Expand All @@ -28,6 +29,7 @@ $ dogcom -m dhcp -c dogcom.conf -d # (PS: only on Linux build)
$ dogcom -m pppoe -c dogcom.conf -x # (PS: only on Linux build)
$ dogcom -m pppoe -c dogcom.conf -e # eternal dogcoming (default times is 5)
$ dogcom -m pppoe -c dogcom.conf -v
$ dogcom -m dhcp -c dogcom.conf -b 10.2.3.12 -v
```

#### To build:
Expand Down
10 changes: 6 additions & 4 deletions auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ typedef int socklen_t;
#include "keepalive.h"
#include "debug.h"

#define BIND_IP "0.0.0.0"
#define BIND_PORT 61440
#define DEST_PORT 61440

Expand Down Expand Up @@ -418,10 +417,13 @@ int dogcom(int try_times) {
struct sockaddr_in bind_addr;
memset(&bind_addr, 0, sizeof(bind_addr));
bind_addr.sin_family = AF_INET;
if (verbose_flag) {
printf("Your are binding at %s.\n\n", bind_ip);
}
#ifdef WIN32
bind_addr.sin_addr.S_un.S_addr = inet_addr(BIND_IP);
bind_addr.sin_addr.S_un.S_addr = inet_addr(bind_ip);
#else
bind_addr.sin_addr.s_addr = inet_addr(BIND_IP);
bind_addr.sin_addr.s_addr = inet_addr(bind_ip);
#endif
bind_addr.sin_port = htons(BIND_PORT);

Expand Down Expand Up @@ -595,4 +597,4 @@ void logging(char msg[10], unsigned char *packet, int length) {
fprintf(ptr_file, "\n");

fclose(ptr_file);
}
}
1 change: 1 addition & 0 deletions configparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ int eapol_flag = 0;
int eternal_flag = 0;
char *log_path;
char mode[10];
char bind_ip[20];
struct config drcom_config;

static int read_d_config(char *buf, int size);
Expand Down
1 change: 1 addition & 0 deletions configparse.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ extern int eapol_flag;
extern int eternal_flag;
extern char *log_path;
extern char mode[10];
extern char bind_ip[20];

int config_parse(char *filepath);

Expand Down
18 changes: 14 additions & 4 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
#include "libs/common.h"
#endif

#define VERSION "1.3.2"
#define VERSION "1.4.0"

void print_help(int exval);
int try_smart_eaplogin(void);

static const char default_bind_ip[20] = "0.0.0.0";

int main(int argc, char *argv[]) {
if (argc == 1) {
print_help(1);
Expand All @@ -28,6 +30,7 @@ int main(int argc, char *argv[]) {
static const struct option long_options[] = {
{ "mode", required_argument, 0, 'm' },
{ "conf", required_argument, 0, 'c' },
{ "bindip", required_argument, 0, 'b' },
{ "log", required_argument, 0, 'l' },
#ifdef linux
{ "daemon", no_argument, 0, 'd' },
Expand All @@ -42,11 +45,11 @@ int main(int argc, char *argv[]) {
int c;
int option_index = 0;
#ifdef linux
c = getopt_long(argc, argv, "m:c:l:xdevh", long_options, &option_index);
c = getopt_long(argc, argv, "m:c:b:l:dxevh", long_options, &option_index);
#else
c = getopt_long(argc, argv, "m:c:l:evh", long_options, &option_index);
c = getopt_long(argc, argv, "m:c:b:l:evh", long_options, &option_index);
#endif

if (c == -1) {
break;
}
Expand Down Expand Up @@ -76,6 +79,9 @@ int main(int argc, char *argv[]) {
}
#endif
break;
case 'b':
strcpy(bind_ip, optarg);
break;
case 'l':
#ifndef __APPLE__
if (mode != NULL) {
Expand Down Expand Up @@ -143,6 +149,9 @@ int main(int argc, char *argv[]) {
}
}
#endif
if (strlen(bind_ip) == 0) {
memcpy(bind_ip, default_bind_ip, sizeof(default_bind_ip));
}
dogcom(5);
} else {
return 1;
Expand All @@ -166,6 +175,7 @@ void print_help(int exval) {
printf("Options:\n");
printf("\t--mode <dhcp/pppoe>, -m <dhcp/pppoe> set your dogcom mode \n");
printf("\t--conf <FILEPATH>, -c <FILEPATH> import configuration file\n");
printf("\t--bindip <IPADDR>, -b <IPADDR> bind your ip address(default is 0.0.0.0)\n");
printf("\t--log <LOGPATH>, -l <LOGPATH> specify log file\n");
#ifdef linux
printf("\t--daemon, -d set daemon flag\n");
Expand Down

0 comments on commit cfda241

Please sign in to comment.