资源简介
改造后的在Linux和Windows均已测试过的局域网内进行远程开机和远程唤醒的例程, 可以很容易地改造封装成函数加以使用。
代码片段和文件信息
#include
#include // For errno
#if defined(WIN32) || defined(_WIN32)
#include
#include
typedef SOCKET WOLSocket;
typedef int socklen_t;
typedef char raw_type; // Type used for raw data on this platform
#pragma comment(lib “ws2_32“)
int CvtIP2Addr(char* strIP struct in_addr* addIn)
{
(*addIn).s_addr = inet_addr(strIP);
return 1;
}
#else
#include
#include
#include // For data types
#include // For socket() connect() send() and recv()
#include // For gethostbyname()
#include // For inet_addr()
#include // For close()
#include // For sockaddr_in
typedef void raw_type; // Type used for raw data on this platform
typedef int WOLSocket;
int CvtIP2Addr(char* strIP struct in_addr* addIn)
{
int iRet = inet_aton(strIP addIn);
return iRet;
}
#endif
int parseMac(unsigned char *mac char *str) {
int i;
int count;
char c;
unsigned char val;
int colon_ok = 1;
for (i = 0; i < 6; i++) {
mac[i] = 0;
}
for (i = 0; i < 6; i++) {
count = 0;
val = 0;
do {
c = toupper(*str++);
if (c >= ‘0‘ && c <= ‘9‘) {
val = (val * 16) + (c - ‘0‘);
} else if (c >= ‘A‘ && c <= ‘F‘) {
val = (val * 16) + (c - ‘A‘) + 10;
} else if (c == ‘:‘) {
if (colon_ok || count-- != 0)
break;
} else if (c == ‘\0‘) {
str--;
break;
} else {
return 0;
}
colon_ok=1;
} while (++count < 2);
colon_ok=(count<2);
*mac++ = val;
}
if (*str)
return 0;
return 1;
}
#define POWER_ON_ERROR_NO_ERROR 0
#define POWER_ON_ERROR_INVALID_MAC 1
#define POWER_ON_ERROR_INVALID_SOCKET 2
#define POWER_ON_ERROR_INVALID_SETOPT 4
#define POWER_ON_ERROR_INVALID_SEND 8
#define POWER_ON_ERROR_NOT_INITIALIZE 16
int main(int argc char *argv[])
{
unsigned char macaddr[8];
WOLSocket sock;
char strMAC[128] = “00:24:E8:23:1F:A6“;
char strTarget[128] = “255.255.255.255“;
char* mac = strMAC;
char* target = strTarget;
short bport = 32767;
int optval = 1;
unsigned char msg[1024];
int msglen = 0;
struct sockaddr_in bcast;
struct hostent *he;
struct in_addr inaddr;
#if defined(WIN32) || defined(_WIN32)
WSADATA wsaData;
//---------------------------------------------
// Initialize Winsock
WSAStartup(MAKEWORD(22) &wsaData);
#endif
if(argc > 1)
{
mac = argv[1];
}
printf(“macString = %s“ mac);
if(parseMac(macaddr mac) != 1)
{
printf(“Illlegal MAC address : %s \n“ mac);
return POWER_ON_ERROR_INVALID_MAC;
}
if(!CvtIP2Addr(target &inaddr))
{
he = gethostbyname(target
- 上一篇:杰奇模版幻世中文网.rar
- 下一篇:cvuqdisk-1.0.9-1.rar
相关资源
- IOSrv_OMRONHL
- FT245 usb fifo control
- 吴恩达老师深度学习课程作业用到的
- mitty多普达smartphone刷机工具
- HorizontalScrollView嵌套GridView实现水平滚
- 新增wifi dongle.pdf
- div+mui+vue.js 制作问卷调查单页造的j
- HALCON连接多摄像头以及图像合并
- 讲解虚拟机3种网络模式(桥接、nat、
- ConvexOptimizationAlgorithms(2015年DimitriP
- reignition_user.pscx
- ER/Studio Version 8.0.2(Build 5991)破解文
- StockControl.exe
- JasonQt_BaiduVop Demo
- jsonviewer(汉化中文版)
- get_hardware_information
- 对象克隆、复制工具
- Echarts扩展所需省级geomety数据 geoJson
- Keil Generic Keygen
- 最强destoon首页模块调用方法
- LitJson.dll中文版
- zw_jueqingnikong-10336909-PSOeconomic-dispatch
- MvCameraNode.xlsx
- hcgconv 游戏解包工具
- 爱普生彩色打印机 清零软件和图解(
- Keil uVision5美化
- 利用百度人脸识别API和pyqt5实现基于人
- 六、最新尚硅谷MongoDB视频链接.rar
- KUKA机器人通过EtherNetIP与工业相机通讯
- Michael Artin 代数 答案 solutions of Algeb
评论
共有 条评论