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

📄 checkentry.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 ConfigEntry *convertLine (struct ConfigLine *line, int *errno) {    int portno;  struct ElementList *uids, *programs, *IPAddresses, *ports;  struct ConfigEntry *entry;  char *endptr; /* for strtol */  uids = line->uids;  programs = line->programs;  IPAddresses = line->IPAddresses;  ports = line->ports;  if (uids->next || programs->next || IPAddresses->next || ports->next) {    *errno = ILLEGAL_PROGRAM;    return NULL;  }  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 NULL;    }  }  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;    return entry;}/* only called from checkEntry. Frees temporarily used structures. configLine and entry share substructures, so they are freed only once */void freeStructures (struct ConfigLine *configLine, struct ConfigEntry *entry) {  if (configLine) {    freeElementList (configLine->uids);    freeElementList (configLine->programs);    freeElementList (configLine->IPAddresses);    freeElementList (configLine->ports);    free (configLine);  }    free (entry); /* components have already been freed before */}    char checkEntry (char *line, struct FirewallConfig *firewallTable, int *errno) {  struct ConfigLine *configLine;  struct ConfigEntry *entry;  int result;  *errno = 0;   configLine = parseLine (line, errno);  if (!configLine) {    /* error has happend */    return 0;  }  entry = convertLine (configLine, errno);  if (!entry) {    freeStructures (configLine, entry);    return ENTRY_NOT_FOUND;  }  while (firewallTable) {    result = compareEntry (entry, firewallTable->entry);    if (result == 0) {      freeStructures (configLine, entry);      return ENTRY_FOUND;    }    if (result < 0) {      firewallTable = firewallTable->left;    }    else {      firewallTable = firewallTable->right;    }  }  /* not found */  freeStructures(configLine, entry);  return ENTRY_NOT_FOUND;  }

⌨️ 快捷键说明

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