📄 00000018.htm
字号:
typedef struct { /* one Client struct per connected client */ <BR> int fd; /* fd, or -1 if available */ <BR> pid_t pid; /* child pid while dialing */ <BR> uid_t uid; /* client's user ID */ <BR> int childdone; /* nonzero when SIGCHLD from dialing child recvd: <BR> 1 means exit(0), 2 means exit(1) */ <BR> long sysftell; /* next line to read in Systems file */ <BR> long foundone; /* true if we find a matching sysfile entry */ <BR> int Debug; /* option from client */ <BR> enum parity parity; /* option from client */ <BR> char speed[MAXSPEEDSTR]; /* option from client */ <BR> char sysname[MAXSYSNAME];/* option from client */ <BR>} Client; <BR>extern Client *client; /* ptr to malloc'ed array of Client structs */ <BR>extern int client_size;/* # entries in client[] array */ <BR> /* (both manipulated by client_XXX() fun <BR>tions) */ <BR>typedef struct { /* everything for one entry in Systems file */ <BR> char *name; /* system name */ <BR> char *time; /* (e.g., "Any") time to call (ignored) */ <BR> char *type; /* (e.g., "ACU") or system name if direct connect */ <BR> char *class; /* (e.g., "9600") speed */ <BR> char *phone; /* phone number or "-" if direct connect */ <BR> char *login; /* uucp login chat (ignored) */ <BR>} Systems; <BR>typedef struct { /* everything for one entry in Devices file */ <BR> char *type; /* (e.g., "ACU") matched by type in Systems */ <BR> char *line; /* (e.g., "cua0") without preceding "/dev/" */ <BR> char *line2; /* (ignored) */ <BR> char *class; /* matched by class in Systems */ <BR> char *dialer; /* name of dialer in Dialers */ <BR>} Devices; <BR>typedef struct { /* everything for one entry in Dialers file */ <BR> char *dialer; /* matched by dialer in Devices */ <BR> char *sub; /* phone number substitution string (ignored) */ <BR> char *expsend; /* expect/send chat */ <BR>} Dialers; <BR>extern Systems systems; /* filled in by sys_next() */ <BR>extern Devices devices; /* filled in by dev_next() */ <BR>extern Dialers dialers; /* filled in by dial_next() */ <BR> /* our function prototypes */ <BR>void child_dial(Client *); /* childdial.c * <BR> <BR>int cli_args(int, char **); /* cliar <BR>s.c */ <BR>int client_add(int, uid_t); /* clien <BR>.c */ <BR>void client_del(int); <BR>void client_sigchld(pid_t, int); <BR>void loop(void); /* loop. <BR> */ <BR>char *ctl_str(char); /* ctlst <BR>.c */ <BR>int dev_find(Devices *, const Systems *); /* devfile.c */ <BR>int dev_next(Devices *); <BR>void dev_rew(void); <BR>int dial_find(Dialers *, const Devices *); /* dialfile.c */ <BR>int dial_next(Dialers *); <BR>void dial_rew(void); <BR>int expect_str(int, char *); /* expec <BR>str.c */ <BR>int request(Client *); <BR>* request.c */ <BR>int send_str(int, char *, char *, int); /* sendstr.c */ <BR>void sig_chld(int); /* sigch <BR>d.c */ <BR>long sys_next(Systems *); /* sysfile.c */ <BR>void sys_posn(long); <BR>void sys_rew(void); <BR>int tty_open(char *, char *, enum parity, int); /* ttyopen.c */ <BR>int tty_dial(int, char *, char *, char *, char *); /* ttydial.c */ <BR>pid_t is_locked(char *); /* lock. <BR> */ <BR>void lock_set(char *, pid_t); <BR>void lock_rel(pid_t); <BR>void DEBUG(char *, ...); /* debug.c */ <BR>void DEBUG_NONL(char *, ...); <BR>_______________________________________________________________________ <BR>_______ <BR>程序18.1 call.h 头文件 <BR> 我们定义了一个Client结构,它包含了每一客户的所有信息。这是一个对程序 <BR>15.26中类似结构的扩展。在创建一个子进程为客户端拨号和子进程终止之间,我 <BR>们可以处理任意多的其他客户。这个结构同时包含了我们所需要的其他信息,如尝 <BR>试找到Systems文件中的其他项,重新拨号等。 <BR> 我们同样为Systems、Devices、Dialers文件中每一项定义了一个结构。 <BR> 程序18.2 是这个服务器端程序的main函数。因为这个程序一般是作为精灵进 <BR>程运行,我们提供了一个 -d 的命令行选项,允许交互式运行。 <BR>_______________________________________________________________________ <BR>_______ <BR>#include "calld.h" <BR>#include <syslog.h> <BR> /* define global variables */ <BR>int clifd; <BR>int debug; /* daemon's command line flag */ <BR>int Debug; /* Debug controlled by client, not cmd line */ <BR>char errmsg[MAXLINE]; <BR>char *speed; <BR>char *sysname; <BR>uid_t uid; <BR>Client *client = NULL; <BR>int client_size; <BR>Systems systems; <BR>Devices devices; <BR>Dialers dialers; <BR>volatile sig_atomic_t chld_flag; <BR>enum parity parity = NONE; <BR>int <BR>main(int argc, char *argv[]) <BR>{ <BR> int c; <BR> log_open("calld", LOG_PID, LOG_USER); <BR> opterr = 0; /* don't want getopt() writing to stderr */ <BR> while ( (c = getopt(argc, argv, "d")) != EOF) { <BR> switch (c) { <BR> case 'd': /* debug */ <BR> debug = 1; <BR> break; <BR> case '?': <BR>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -