sock = socket(AF_INET, SOCK_STREAM, 0);报错,是不是少什么lib?
sock=socket(AF_INET,SOCK_STREAM,0);sin.sin_family=AF_INET;sin.sin_port=htons(22);sin....
sock = socket(AF_INET, SOCK_STREAM, 0);
sin.sin_family = AF_INET;
sin.sin_port = htons(22);
sin.sin_addr.s_addr = hostaddr;
if (connect(sock, (struct sockaddr*)(&sin),
sizeof(struct sockaddr_in)) != 0) {
fprintf(stderr, "failed to connect!\n");
return -1;
}
ssh2.c: In function ‘main’:
ssh2.c:83:24: error: storage size of ‘sin’ isn’t known
ssh2.c:126:19: error: ‘AF_INET’ undeclared (first use in this function)
ssh2.c:126:19: note: each undeclared identifier is reported only once for each function it appears in
ssh2.c:126:28: error: ‘SOCK_STREAM’ undeclared (first use in this function)
ssh2.c:132:24: error: invalid application of ‘sizeof’ to incomplete type ‘struct sockaddr_in’
#include "libssh2_config.h"
#include <libssh2.h>
#ifdef HAVE_WINSOCK2_H
# include <winsock2.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
# include <sys/socket.h>
#endif
#ifdef HAVE_NETINET_IN_H
# include <netinet/in.h>
#endif
#ifdef HAVE_SYS_SELECT_H
# include <sys/select.h>
#endif
# ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_ARPA_INET_H
# include <arpa/inet.h>
#endif
#include <sys/time.h>
#include <sys/types.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#include <ctype.h>
这个是头
我在linux gcc编译报错的
代码都是从官网上拷贝的
我觉得还是少什么lib 展开
sin.sin_family = AF_INET;
sin.sin_port = htons(22);
sin.sin_addr.s_addr = hostaddr;
if (connect(sock, (struct sockaddr*)(&sin),
sizeof(struct sockaddr_in)) != 0) {
fprintf(stderr, "failed to connect!\n");
return -1;
}
ssh2.c: In function ‘main’:
ssh2.c:83:24: error: storage size of ‘sin’ isn’t known
ssh2.c:126:19: error: ‘AF_INET’ undeclared (first use in this function)
ssh2.c:126:19: note: each undeclared identifier is reported only once for each function it appears in
ssh2.c:126:28: error: ‘SOCK_STREAM’ undeclared (first use in this function)
ssh2.c:132:24: error: invalid application of ‘sizeof’ to incomplete type ‘struct sockaddr_in’
#include "libssh2_config.h"
#include <libssh2.h>
#ifdef HAVE_WINSOCK2_H
# include <winsock2.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
# include <sys/socket.h>
#endif
#ifdef HAVE_NETINET_IN_H
# include <netinet/in.h>
#endif
#ifdef HAVE_SYS_SELECT_H
# include <sys/select.h>
#endif
# ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_ARPA_INET_H
# include <arpa/inet.h>
#endif
#include <sys/time.h>
#include <sys/types.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#include <ctype.h>
这个是头
我在linux gcc编译报错的
代码都是从官网上拷贝的
我觉得还是少什么lib 展开
威孚半导体技术
2024-08-19 广告
2024-08-19 广告
威孚(苏州)半导体技术有限公司是一家专注生产、研发、销售晶圆传输设备整机模块(EFEM/SORTER)及核心零部件的高科技半导体公司。公司核心团队均拥有多年半导体行业从业经验,其中技术团队成员博士、硕士学历占比80%以上,依托丰富的软件底层...
点击进入详情页
本回答由威孚半导体技术提供
2011-07-13
展开全部
头文件有木有少?
#include <winsock2.h>
#include <ws2tcpip.h>
#pragma comment(lib,"Ws2_32.lib")
#include <winsock2.h>
#include <ws2tcpip.h>
#pragma comment(lib,"Ws2_32.lib")
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询