2022-04-11 11:40阅读: 190评论: 0推荐: 0

Mac OS配置UNP(Unix网络套接字 V1)环境

最近在温习UNP(《Unix网络套接字 V1》),以前都是在linux下搞,现在打算在自己机器弄下,于是google了下,把编译的事情搞定了,修改了一些教程的一些错误,比如下载链接之类的。

  1. 下载源文件
wget http://www.unpbook.com/unpv13e.tar.gz #使用wget
git clone https://github.com/unpbook/unpv13e #使用git
  1. 解压(可选)
tar -zxf unpv13e.tar.gz #使用wget下载需要
  1. 编译
cd unpv13e
./configure
cd lib
make
cd ../libfree
make
  1. 报错及修改
#报错
inet_ntop.c:56:1: error: conflicting types for 'inet_ntop'
inet_ntop(af, src, dst, size)
^
/usr/include/arpa/inet.h:77:13: note: previous declaration is here
const char *inet_ntop(int, const void *, char *, socklen_t);
^
1 error generated.

unpv13e/libfree找到inte_ntop.c文件,把#include<arph/inet.h>注释掉,再次执行make`编译。
具体操作如下:

vim unpv13e/libfree/inte_ntop.c
#查找头文件,找到后注释
/arph/inet.h
  1. 拷贝头文件
    回到主目录,首先修改./lib/unp.h/,将其中#include "../config.h"修改为#include "config.h",然后执行拷贝操作。
vim unpv13e/lib/unp.h
#查找头文件,找到后修改
/config.h
#拷贝
sudo cp ./config.h /usr/local/include
sudo cp ./lib/unp.h /usr/local/include
sudo cp ./libunp.a /usr/local/lib
  1. 测试
// byteorder.c
#include "unp.h"
int main(int argc, char *argv[]) {
union {
short s;
char c[sizeof(short)];
} un;
un.s = 0x0102;
printf("%s: ", CPU_VENDOR_OS);
if (sizeof(short) == 2) {
if (un.c[0] == 1 && un.c[1] == 2) {
printf("big-endian\n");
} else if (un.c[0] == 2 && un.c[1] == 1) {
printf("little-endian\n");
} else {
printf("unknown\n");
}
} else {
printf("sizeof(short) = %d\n", sizeof(short));
}
exit(0);
}

编译时制定链接库文件-lunp

gcc byteorder.c -lunp -o byteorder
./byteorder
i386-apple-darwin17.7.0: little-endian
posted @   Tsunho12  阅读(190)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
💬
评论
📌
收藏
💗
关注
👍
推荐
🚀
回顶
收起
🔑
  1. 1 404 not found REOL
404 not found - REOL
00:00 / 00:00
An audio error has occurred.