赞
踩
内存中多字节分为大端小端,网络字节之间又具有大小端之分,那么如何定义网络数据流的地址?
#include<arpa/inet.h>
uni32_t htonl(uni32_t hostlong);
uni16_t htons(uni16_t hostshort);
uni32_t ntohl(uni32_t hostlong);
uni16_t ntogs(uni16_t hostshort;
//服务端(要绑定) #include<iostream> #include<unistd.h> #include<cstring> #include<sys/types.h> #include<sys/socket.h> #include<string> #include<netinet/in.h> #include<arpa/inet.h> #include<stdio.h> #include<stdlib.h> using namespace std; int Usage(string s) { cerr << "Usage: " << s << " IP PORT" << endl; cerr << "Version: 0.0.1" << endl; } int main(int argc, char* argv[]) { if(argc != 3) { Usage(argv[0])
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。