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 展开
2个回答
Storm代理
2023-07-25 广告
2023-07-25 广告
StormProxies是全球大数据IP资源服务商,其住宅代理网络由真实的家庭住宅IP组成,可为企业或个人提供满足各种场景的代理产品。点击免费测试(注册即送1G流量)StormProxies有哪些优势?1、IP+端口提取形式,不限带宽,IP...
点击进入详情页
本回答由Storm代理提供
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")
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询