Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

新增网卡选择 #42

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Options:
--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
--interface <IFNAME>, -i <IFNAME> bind interface
--802.1x, -x enable 802.1x
--daemon, -d set daemon flag
--eternal, -e set eternal flag
Expand All @@ -30,6 +31,7 @@ $ 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
$ dogcom -m dhcp -c dogcom.conf -i eth0.2 # (PS: only on Linux build)
```

#### To build:
Expand Down
17 changes: 17 additions & 0 deletions auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ typedef int socklen_t;
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <net/if.h>
#endif

#include "auth.h"
Expand Down Expand Up @@ -568,6 +569,7 @@ int dogcom(int try_times) {
#endif
return 1;
}

// bind socket
if (bind(sockfd, (struct sockaddr *)&bind_addr, sizeof(bind_addr)) < 0) {
#ifdef WIN32
Expand Down Expand Up @@ -595,6 +597,21 @@ int dogcom(int try_times) {
return 1;
}

// bind interface
#ifdef linux
if (strlen(bind_ifr_name) > 0)
{
struct ifreq ifr;
memset(&ifr, 0, sizeof(ifr));
strcpy(ifr.ifr_name, bind_ifr_name);
if (setsockopt(sockfd, SOL_SOCKET, SO_BINDTODEVICE, &ifr, sizeof(ifr)) < 0)
{
perror("Failed to bind ifr");
return 1;
}
}
#endif

// start dogcoming
if (strcmp(mode, "dhcp") == 0) {
int login_failed_attempts = 0;
Expand Down
1 change: 1 addition & 0 deletions configparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ int eternal_flag = 0;
char *log_path;
char mode[10];
char bind_ip[20];
char bind_ifr_name[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 @@ -30,6 +30,7 @@ extern int eternal_flag;
extern char *log_path;
extern char mode[10];
extern char bind_ip[20];
extern char bind_ifr_name[20];

int config_parse(char *filepath);

Expand Down
10 changes: 9 additions & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ int main(int argc, char *argv[]) {
{"bindip", required_argument, 0, 'b'},
{"log", required_argument, 0, 'l'},
#ifdef linux
{"interface", required_argument,0, 'i'},
{"daemon", no_argument, 0, 'd'},
{"802.1x", no_argument, 0, 'x'},
#endif
Expand All @@ -44,7 +45,7 @@ int main(int argc, char *argv[]) {
int c;
int option_index = 0;
#ifdef linux
c = getopt_long(argc, argv, "m:c:b:l:dxevh", long_options, &option_index);
c = getopt_long(argc, argv, "m:c:b:l:i:dxevh", long_options, &option_index);
#else
c = getopt_long(argc, argv, "m:c:b:l:evh", long_options, &option_index);
#endif
Expand Down Expand Up @@ -98,6 +99,9 @@ int main(int argc, char *argv[]) {
#endif
break;
#ifdef linux
case 'i':
strcpy(bind_ifr_name, optarg);
break;
case 'd':
daemon_flag = 1;
break;
Expand Down Expand Up @@ -151,6 +155,9 @@ int main(int argc, char *argv[]) {
if (strlen(bind_ip) == 0) {
memcpy(bind_ip, default_bind_ip, sizeof(default_bind_ip));
}
if (strlen(bind_ifr_name) == 0) {
memset(bind_ifr_name, 0, 20);
}
dogcom(5);
} else {
return 1;
Expand All @@ -177,6 +184,7 @@ void print_help(int exval) {
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--interface, -i bind interface\n");
printf("\t--daemon, -d set daemon flag\n");
printf("\t--802.1x, -x enable 802.1x\n");
#endif
Expand Down