我目前正在为一些嵌入式系统编写一个小型套接字代码,一个有ARM,另一个有PowerPC,
据我所知,ARM是小端,而PowerPC是大端,我的代码是:
void foo() {
...declarations here...
struct sockaddr_in socket_address = {0};
socket_descriptor = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
socket_address.sin_family = AF_INET;
socket_address.sin_addr.s_addr = inet_addr("127.0.0.1");
socket_address.sin_port = htons(9100);
call_result = connect(socket_descriptor, (struct sockaddr*)&socket_address, sizeof(socket_address));
...clean ups........
}
代码在为ARM编译时有效,但是在为PowerPC编译时失败,特别是connect()函数返回-1,我怀疑这与分配inet地址和端口以及endianess有关。平台,当我为PowerPC编译时,我错过了什么?