作者appleway (apple)
看板MacDev
标题Re: [问题] IPPROTO_TCP 常数
时间Mon May 2 10:27:35 2005
※ 引述《fayhong (出世入世一线间)》之铭言:
: 这两天在 OSX 10.3 上面写 socket 程式
: 用 Xcode 1.5 附的 gcc 3.3
: 我发现在书本上 ANSI C 范例中
: IPPROTO_TCP 这常数不存在於 include 档中
: (include了:
: stdio.h
: sys/socket.h
: arpa/inet.h
: stdlib.h
: string.h
: unistd.h)
: 现在最困惑的,莫过於这两点:
: 1. 没 IPPROTO_TCP,怎麽开 socket() 咧?
: 2. ANSI C 的范例中有,那麽,gcc 的 library 跟 ANSI C 不相容
: 还是在 OSX 上的 library 比较特别
: 麻烦各位大大指引了 @@"
太久没写socket了,所以查了一下。
这是我之前在OSX 10.3 上面写的 socket 程式
我的include 是这样的
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <errno.h>
#include <string.h>
#include <netinet/in.h>
#include <unistd.h>
#include <netdb.h>
当然程式中的
if( (*S_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP) ) < 0 ){
printf("socket error\n");
exit(1);
}
完全没有错误
至於上面socket的include 是按照BSD 的socket 写法
当然这些lib当时也都是按照老师的讲义include 的,老师只有教BSD跟winsock,
没有特别教任何MAC上的socket :P 当然OSX是BSD的分枝就是了
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 211.22.17.106
1F:推 fayhong:嗯嗯,谢谢 :) 163.25.118.81 05/02