📄 ipa_adm.c
字号:
if (pheader->code != 0)
{
printf("%s", outbuf+sizeof(Header_t));
}
else
{
printf("reset white list success!\n");
}
return 0;
}
int reset_ip_list(char *argv[])
{
char buf[256];
char outbuf[256];
int outlen;
Header_t *pheader;
char hostname[256];
int ret;
ret = gethostname(hostname, sizeof(hostname));
if (ret < 0)
{
printf("gethostname fail![%s]\n", strerror(errno));
return -1;
}
pheader = (Header_t *)buf;
pheader->buflen = sizeof(Header_t);
pheader->code = RESET_IP_LIST;
pheader->buflen = htonl(pheader->buflen);
pheader->code = htonl(pheader->code );
ret = client_request(hostname, getenv("IPA_SERVICE_PORT"), buf, ntohl(pheader->buflen),
outbuf, &outlen);
if (ret < 0) return -1;
pheader = (Header_t *)outbuf;
pheader->buflen = ntohl(pheader->buflen);
pheader->code = ntohl(pheader->code );
if (pheader->code != 0)
{
printf("%s", outbuf+sizeof(Header_t));
}
else
{
printf("reset_ip_list success!\n");
}
return 0;
}
int print_white_list(char *argv[])
{
char buf[256];
char outbuf[256];
int outlen;
Header_t *pheader;
char hostname[256];
int ret;
ret = gethostname(hostname, sizeof(hostname));
if (ret < 0)
{
printf("gethostname fail![%s]\n", strerror(errno));
return -1;
}
pheader = (Header_t *)buf;
pheader->buflen = sizeof(Header_t);
pheader->code = PRINT_WHITE_LIST;
pheader->buflen = htonl(pheader->buflen);
pheader->code = htonl(pheader->code );
ret = client_request(hostname, getenv("IPA_SERVICE_PORT"), buf, ntohl(pheader->buflen),
outbuf, &outlen);
if (ret < 0) return -1;
pheader = (Header_t *)outbuf;
pheader->buflen = ntohl(pheader->buflen);
pheader->code = ntohl(pheader->code );
if (pheader->code != 0)
{
printf("%s", outbuf+sizeof(Header_t));
}
else
{
printf("Printing of white list is successing!\n");
}
return 0;
}
int print_ip_list(char *argv[])
{
char buf[256];
char outbuf[256];
int outlen;
Header_t *pheader;
char hostname[256];
int ret;
ret = gethostname(hostname, sizeof(hostname));
if (ret < 0)
{
printf("gethostname fail![%s]\n", strerror(errno));
return -1;
}
pheader = (Header_t *)buf;
pheader->buflen = sizeof(Header_t);
pheader->code = PRINT_IP_LIST;
pheader->buflen = htonl(pheader->buflen);
pheader->code = htonl(pheader->code );
ret = client_request(hostname, getenv("IPA_SERVICE_PORT"), buf, ntohl(pheader->buflen),
outbuf, &outlen);
if (ret < 0) return -1;
pheader = (Header_t *)outbuf;
pheader->buflen = ntohl(pheader->buflen);
pheader->code = ntohl(pheader->code );
if (pheader->code != 0)
{
printf("%s", outbuf+sizeof(Header_t));
}
else
{
printf("print ip list success!\n");
}
return 0;
}
int delete_white_list(char *argv[])
{
char buf[256];
char outbuf[256];
int outlen;
Header_t *pheader;
IP_MAC_NAME_t *plist;
char hostname[256];
int ret;
ret = gethostname(hostname, sizeof(hostname));
if (ret < 0)
{
printf("gethostname fail![%s]\n", strerror(errno));
return -1;
}
pheader = (Header_t *)buf;
plist = (IP_MAC_NAME_t *)(buf+sizeof(Header_t));
pheader->buflen = sizeof(Header_t) + sizeof(IP_MAC_NAME_t);
pheader->code = DELETE_WHITE_LIST;
pheader->buflen = htonl(pheader->buflen);
pheader->code = htonl(pheader->code );
if ( (strlen(argv[2]) > 15) || (strlen(argv[2]) < 7) )
{
printf("Bad ip[%s]\n", argv[2]);
return -1;
}
memset(plist, 0, sizeof(IP_MAC_NAME_t));
strcpy(plist->ip, argv[2]);
ret = client_request(hostname, getenv("IPA_SERVICE_PORT"), buf, ntohl(pheader->buflen),
outbuf, &outlen);
if (ret < 0) return -1;
pheader = (Header_t *)outbuf;
pheader->buflen = ntohl(pheader->buflen);
pheader->code = ntohl(pheader->code );
if (pheader->code != 0)
{
printf("%s", outbuf+sizeof(Header_t));
}
else
{
printf("del success!\n");
}
return 0;
}
int add_white_list(char *argv[])
{
char buf[256];
char outbuf[256];
int outlen;
Header_t *pheader;
IP_MAC_NAME_t *plist;
char hostname[256];
int ret;
ret = gethostname(hostname, sizeof(hostname));
if (ret < 0)
{
printf("gethostname fail![%s]\n", strerror(errno));
return -1;
}
memset(buf, 0, sizeof(buf));
memset(outbuf, 0, sizeof(outbuf));
pheader = (Header_t *)buf;
plist = (IP_MAC_NAME_t *)(buf+sizeof(Header_t));
pheader->buflen = sizeof(Header_t) + sizeof(IP_MAC_NAME_t);
pheader->code = ADD_WHITE_LIST;
pheader->buflen = htonl(pheader->buflen);
pheader->code = htonl(pheader->code );
if ( (strlen(argv[2]) > 15) || (strlen(argv[2]) < 7) )
{
printf("Bad ip[%s]\n", argv[2]);
return -1;
}
if ( strlen(argv[3]) != 17)
{
printf("Bad mac[%s]\n", argv[3]);
return -1;
}
if ( (strlen(argv[4]) > 31) || (strlen(argv[4]) < 1) )
{
printf("Bad name[%s], too long(1-31)\n", argv[4]);
return -1;
}
strcpy(plist->ip, argv[2]);
strcpy(plist->mac, argv[3]);
strcpy(plist->name, argv[4]);
ret = client_request(hostname, getenv("IPA_SERVICE_PORT"), buf, ntohl(pheader->buflen),
outbuf, &outlen);
if (ret < 0) return -1;
pheader = (Header_t *)outbuf;
pheader->buflen = ntohl(pheader->buflen);
pheader->code = ntohl(pheader->code );
if (pheader->code != 0)
{
printf("%s", outbuf+sizeof(Header_t));
}
else
{
printf("Add white list success!\n");
}
return 0;
}
int add_ip_list(char *argv[])
{
char buf[256];
char outbuf[256];
int outlen;
Header_t *pheader;
IP_MAC_NAME_t *plist;
char hostname[256];
int ret;
ret = gethostname(hostname, sizeof(hostname));
if (ret < 0)
{
printf("gethostname fail![%s]\n", strerror(errno));
return -1;
}
pheader = (Header_t *)buf;
plist = (IP_MAC_NAME_t *)(buf+sizeof(Header_t));
pheader->buflen = sizeof(Header_t) + sizeof(IP_MAC_NAME_t);
pheader->code = ADD_IP_LIST;
pheader->buflen = htonl(pheader->buflen);
pheader->code = htonl(pheader->code );
if ( (strlen(argv[2]) > 15) || (strlen(argv[2]) < 7) )
{
printf("Bad ip[%s]\n", argv[2]);
return -1;
}
if ( strlen(argv[3]) != 17)
{
printf("Bad mac[%s]\n", argv[3]);
return -1;
}
if ( (strlen(argv[4]) > 31) || (strlen(argv[4]) < 1) )
{
printf("Bad name[%s], too long(1-31)\n", argv[4]);
return -1;
}
strcpy(plist->ip, argv[2]);
strcpy(plist->mac, argv[3]);
strcpy(plist->name, argv[4]);
ret = client_request(hostname, getenv("IPA_SERVICE_PORT"), buf, ntohl(pheader->buflen),
outbuf, &outlen);
if (ret < 0) return -1;
pheader = (Header_t *)outbuf;
pheader->buflen = ntohl(pheader->buflen);
pheader->code = ntohl(pheader->code );
if (pheader->code != 0)
{
printf("%s", outbuf+sizeof(Header_t));
}
else
{
printf("add success!\n");
}
return 0;
}
int delete_ip_list(char *argv[])
{
char buf[256];
char outbuf[256];
int outlen;
Header_t *pheader;
IP_MAC_NAME_t *plist;
char hostname[256];
int ret;
ret = gethostname(hostname, sizeof(hostname));
if (ret < 0)
{
printf("gethostname fail![%s]\n", strerror(errno));
return -1;
}
pheader = (Header_t *)buf;
plist = (IP_MAC_NAME_t *)(buf+sizeof(Header_t));
pheader->buflen = sizeof(Header_t) + sizeof(IP_MAC_NAME_t);
pheader->code = DELETE_IP_LIST;
pheader->buflen = htonl(pheader->buflen);
pheader->code = htonl(pheader->code );
if ( (strlen(argv[2]) > 15) || (strlen(argv[2]) < 7) )
{
printf("Bad ip[%s]\n", argv[2]);
return -1;
}
memset(plist, 0, sizeof(IP_MAC_NAME_t));
strcpy(plist->ip, argv[2]);
ret = client_request(hostname, getenv("IPA_SERVICE_PORT"), buf, ntohl(pheader->buflen),
outbuf, &outlen);
if (ret < 0) return -1;
pheader = (Header_t *)outbuf;
pheader->buflen = ntohl(pheader->buflen);
pheader->code = ntohl(pheader->code );
if (pheader->code != 0)
{
printf("%s", outbuf+sizeof(Header_t));
}
else
{
printf("del success!\n");
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -