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个回答
大雅新科技有限公司
2024-11-19 广告
2024-11-19 广告
这方面更多更全面的信息其实可以找下大雅新。深圳市大雅新科技有限公司从事KVM延长器,DVI延长器,USB延长器,键盘鼠标延长器,双绞线视频传输器,VGA视频双绞线传输器,VGA延长器,VGA视频延长器,DVI KVM 切换器等,优质供应商,...
点击进入详情页
本回答由大雅新科技有限公司提供
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")
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询