**我的orangepi每次开机后都自动从路由获取IP,使用固定IP总是会出现这样那样的问题,每次自动获取的IP又不一定都相同,所以需要开机后把获取到的IP地址发送到邮箱里。
上网查阅资料,编写了一个c语言的程序,实现了想要的功能。据说用python能实现起来更简单,但是自我感觉用c语言实现能学到更多的知识!
c语言代码如下:**
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <errno.h>
#include <unistd.h>
#include <netinet/in.h>
#include <limits.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <ctype.h>
#include <ifaddrs.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <sys/types.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <sys/vfs.h>
#include <signal.h>
#include <sys/stat.h>
#include <sys/socket.h>
#define SMTPNAME "smtp.sina.com"
#define SMTPPORT 25
#define USERBASE64 "c2h5Ym95emhhbmdwZW5n\r\n"
#define PASSBASE64 "emhhbmcxNTk5MzQ2NTYzNA==\r\n"
#define USERNAME "MAIL FROM: <shyboyzhangpeng@sina.com>\r\n"
#define RECVNAME "RCPT TO: <1028371415@qq.com>\r\n"
void StreamClient();
void GetIp(char *c);
char context[2048];
int main(int argc, char