⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ppp.c

📁 这是ppp的源代码 这是ppp的源代码
💻 C
字号:
/* ppp.c||  Copyright (C) 2001 Kent Robotti <robotti@metconnect.com>||  This ppp.c is based on source from the dial2net v0.1.3 package below.||  Author: Ted Harden <xted@users.sourceforge.net>|  Latest versions might be found at: http://dial2net.sourceforge.net||  This program is free software which I release under the GNU General Public|  License. You may redistribute and/or modify this program under the terms|  of that license as published by the Free Software Foundation; either|  version 2 of the License, or (at your option) any later version.||  This program is distributed in the hope that it will be useful,|  but WITHOUT ANY WARRANTY; without even the implied warranty of|  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the|  GNU General Public License for more details.| |  To get a copy of the GNU General Puplic License, write to the Free Software|  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA*/#include <stdio.h>#include <stdlib.h>#include <getopt.h>#include <unistd.h>#include <sys/stat.h>void setup() {char login[50];char password[50];char phone_number[14];char modem[15];FILE *paps, *chaps, *opts, *cs, *ipup;void write_setup( char *login, char *password, char *phone_number, char *modem ) {mkdir("/etc/ppp",0755);ipup = fopen("/etc/ppp/ip-up","w");paps = fopen("/etc/ppp/pap-secrets","w");chaps = fopen("/etc/ppp/chap-secrets","w");opts = fopen("/etc/ppp/options","w");cs = fopen("/etc/ppp/chat-script","w");fprintf(paps,"\"%s\" * \"%s\" *",login,password);fprintf(chaps,"\"%s\" * \"%s\" *",login,password);fprintf(cs,"ABORT ERROR\n");fprintf(cs,"ABORT BUSY\n");fprintf(cs,"ABORT \"NO CARRIER\"\n");fprintf(cs,"ABORT \"NO DIALTONE\"\n");fprintf(cs,"REPORT CONNECT\n");fprintf(cs,"\"\" \"AT&FW2\"\n");fprintf(cs,"OK \"ATD%s\"\n",phone_number);fprintf(cs,"TIMEOUT 60\n");fprintf(cs,"CONNECT \"\\c\"\n");fprintf(opts,"lock\ndefaultroute\nnoipdefault\nnoauth\nusepeerdns\nmodem\n/dev/%s\n115200\ncrtscts\ndebug\nasyncmap 0\nname \"%s\"",modem,login);fprintf(ipup,"#!/bin/sh ## This file was created when you ran 'ppp -s'.    #  # This file /etc/ppp/ip-up is run by pppd when there's a successful ppp # connection. #  # Put any commands you want run after a successful connection in this file.  #  # The companion file is /etc/ppp/ip-down, it's run when the ppp connection # ends.  # # The environment is cleared before executing this script so the path must # be reset. # PATH=/usr/bin:/usr/sbin:/usr/X11R6/bin:/sbin:/bin export PATH  # This will print to the screen the local & remote ip address when you  # make a successful ppp connection.  # $4 = Local IP  $5 = Remote IP## The CARRIER speed at which you connect will be reported if your modem # reports it.  ## You may have to add W2 or S95=1 to your modem init string to get your # modem to report the DCE = CARRIER speed.  # Examples: AT&FW2 or AT&FS95=1  [ ! -z $DNS1 ] && echo \"nameserver $DNS1\" > /etc/resolv.conf[ ! -z $DNS2 ] && echo \"nameserver $DNS2\" >> /etc/resolv.confCS=\"`grep CONNECT /var/log/report-chat 2>/dev/null | cut -b 24-40 2>/dev/null`\"if (echo \"$CS $4 > $5 $1\" | /usr/X11R6/bin/xmessage -display $HOSTNAME:0.0 -file - 2>/dev/null); then:  else  echo \"$CS $4 > $5 $1\" >/dev/tty0 fi  #End!"); chmod("/etc/ppp/pap-secrets",0600);chmod("/etc/ppp/chap-secrets",0600);chmod("/etc/ppp/options",0644);chmod("/etc/ppp/chat-script",0644);chmod("/etc/ppp/ip-up",0755);fclose(ipup);fclose(cs);fclose(opts);fclose(chaps);fclose(paps);} printf("\nPress Ctrl-C to quit!\n");printf("\nEnter your login name: ");scanf("%s",login);printf("Enter your password: ");scanf("%s",password);printf("Enter your ISP's phone number. (ie 6661776): ");scanf("%s",phone_number);printf("What port is your modem on? (ttyS0 ttyS1 ttyS2 or ttyS3): ");scanf("%s",modem);write_setup(login, password, phone_number, modem);}int menu;void ifnotroot(){if( getuid() != 0){printf("You need to be root to setup ppp.\n");exit(0);}}void dialout(){unlink("/var/log/report-chat");system("exec /usr/sbin/pppd connect '/usr/sbin/chat -v -r /var/log/report-chat -f /etc/ppp/chat-script'");}void disconnect(){system("kill -INT 2>/dev/null `cat /var/run/ppp*.pid 2>/dev/null` && sleep 3");system("rm -f /var/run/ppp*.pid");}void usage(){	  printf("Usage: ppp [option]\n\nOptions:\n");	  printf("\t-c\tMake ppp connection!\n");	  printf("\t-d\tEnd ppp connectiom!\n");	  printf("\t-h\tHelp!\n");	  printf("\t-l\tShow last 24 messages from /var/log/messages!\n");	  printf("\t-s\tSetup ppp connection!\n");	  printf("\t-v\tShow version!\n\n");	  exit(0);}int main(int argc, char *argv[]){	if (argc < 2) {		usage();	}while((menu = getopt(argc, argv, "cdhlsv")) != -1) 	{switch(menu)    {	case 'c':		printf("Dialing...\n");		disconnect();		dialout();		exit(0);	case 'd':		printf("Disconnecting...\n");		disconnect();		exit(0);	case 'h':	        usage();        case 'l':                system("tail -n 24 /var/log/messages | cut -d ' ' -f 5- | grep -v \" \\^M\" | sed \"s/\\^M//g\"");		exit(0);	case 's':                ifnotroot();		setup();		printf("\nPPP Configured!\nRun 'ppp -c' to connect to your ISP.\n");			exit(0);        case 'v':                printf("PPPsetup v2.28\n");		exit(0);       default:		exit(1);       }}exit(0);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -