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

📄 addrule.c

📁 Linux下server与client的通信实现。Server支持多线程。附有makefile可供编译。Linux下调试通过。
💻 C
字号:
#define _GNU_SOURCE#include <stdio.h>#include <stdlib.h>#include <string.h>#include <firewall.h>#include <server.h>struct FirewallConfig *addEntry (struct ConfigEntry *entry, struct FirewallConfig *config) {    struct FirewallConfig *leaf;  if (config == NULL) {    leaf = malloc (sizeof (struct FirewallConfig));    if (!leaf) {      fprintf (stderr, "Out of memory!\n");      exit (1);    }      leaf->entry = entry;    leaf->left = NULL;    leaf->right = NULL;        return leaf;  }  else if (compareEntry (entry, config->entry) < 0) {    config->left = addEntry (entry, config->left);  }  else if (compareEntry (entry, config->entry) > 0) {    config->right = addEntry (entry, config->right);  }  return config;}struct FirewallConfig *addLine (struct ConfigLine *line, struct FirewallConfig *config, int *errno) {    int portno;  struct ElementList *uids, *programs, *IPAddresses, *ports;  struct ConfigEntry *entry;  char *endptr;  uids = line->uids;  while (uids) {    programs = line->programs;    while (programs) {      IPAddresses = line->IPAddresses;      while (IPAddresses) {	ports = line->ports;	while (ports) {	  if (strcmp (ports->element, "*") == 0) {	    portno = 0;	  }	  else {	    portno = strtol (ports->element, &endptr, 10);	    if ((portno == 0 ) || (endptr == NULL) || (*endptr != '\0')) {	      *errno = ILLEGAL_PORT;	      return config;	    }	  }   	  entry  = malloc (sizeof (struct ConfigEntry));	  if (!entry) {	    fprintf (stderr, "Out of memory!\n");	    exit (1);	  }	  entry->uid = uids->element;	  entry->program = programs->element;	  entry->IPAddress = IPAddresses->element;	  entry->port = portno;	  	  config = addEntry (entry, config);	  	  ports = ports->next;	}	IPAddresses = IPAddresses->next;      }      programs = programs->next;    }    uids = uids->next;  }  return config;}struct FirewallConfig  *addRule (char *line, struct FirewallConfig *firewallTable, int *errno) {  struct ConfigLine *configLine;  *errno = 0;   configLine = parseLine (line, errno);  if (configLine) {    firewallTable = addLine (configLine, firewallTable, errno);    }   return firewallTable;}

⌨️ 快捷键说明

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