-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathipconfig.cpp
More file actions
47 lines (41 loc) · 1.09 KB
/
ipconfig.cpp
File metadata and controls
47 lines (41 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <iostream>
#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
using namespace std;
#include<gtest/gtest.h>
TEST(IPCONFIG,AddIP1)
{
int vlan_id = 1;
ASSERT_GT(vlan_id,0);
return;
FILE *stream = NULL;
char rbuf[4096];
char cbuf[1024];
sprintf(cbuf,"sudo config interface ip add Ethernet2 30.2.1.1/16 2>&1");
stream = popen(cbuf,"r");
if(stream == NULL)return;
fread(rbuf,sizeof(char),sizeof(rbuf),stream);
sprintf(cbuf,"sudo ping -c 1 30.2.1.1 2>&1");
stream = popen(cbuf,"r");
memset(rbuf,0,sizeof(rbuf));
fread(rbuf,sizeof(char),sizeof(rbuf),stream);
char *p = strstr(rbuf,"64 bytes from 30.2.1.1: icmp_seq=1 ttl=64");
if(p == NULL){
ASSERT_FALSE(1==1);
return;
}
p[strlen("64 bytes from 30.2.1.1: icmp_seq=1 ttl=64")] = 0;
//printf("1:%s:",p);
sprintf(cbuf,"64 bytes from 30.2.1.1: icmp_seq=1 ttl=64");
//printf("2:%s:",cbuf);
ASSERT_STREQ(p,cbuf);
}