当前位置: 技术问答>linux和unix
socket问题,望高手帮忙解决
来源: 互联网 发布时间:2016-12-16
本文导语: 程序可以运行,但编译后总有如下警告,想破了头都不知道如何解决: denny@~/uplooking/mycode/Project/TCP >> gcc server.c wrap.c In file included from server.c:9:0: wrap.h:5:36: warning: ‘struct sockadrr’ declared inside parameter list wr...
程序可以运行,但编译后总有如下警告,想破了头都不知道如何解决:
denny@~/uplooking/mycode/Project/TCP >> gcc server.c wrap.c
In file included from server.c:9:0:
wrap.h:5:36: warning: ‘struct sockadrr’ declared inside parameter list
wrap.h:7:39: warning: ‘struct sockadrr’ declared inside parameter list
server.c: In function ‘main’:
server.c:31:25: warning: passing argument 2 of ‘Bind’ from incompatible pointer type
wrap.h:5:6: note: expected ‘const struct sockadrr *’ but argument is of type ‘struct sockaddr *’
当没有include "wrap.h"时,程序没有任何问题,一包括这个头,就会有如上警告,大家帮忙啊
server.c部分代码如下:
#include
#include
#include
#include
#include
#include
#include
#include "wrap.h"
#define SERV_PORT 8000
#define LISTEN_COUNT 10
#define MAX_COUNT 100
int main(int argc, char *argv[])
{
struct sockaddr_in servaddr, cliaddr;
socklen_t cliaddr_len;
int listenfd, connfd;
char buf[MAX_COUNT];
char str[INET_ADDRSTRLEN];
int i,n;
memset(&servaddr, 0, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(SERV_PORT);
servaddr.sin_addr.s_addr = INADDR_ANY;
listenfd = Socket(AF_INET, SOCK_STREAM, 0);
Bind(listenfd, (struct sockaddr *)&servaddr, sizeof(servaddr));
Listen(listenfd, LISTEN_COUNT);
wrap.c部分代码如下(用于部分函数的纠错):
#include
#include
#include
#include
#include
void Bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen)
{
if(bind(sockfd, addr, addrlen) == -1){
perr_exit("bind error n");
}
}
warp.h部分代码如下:
#pragma once
void Bind(int sockfd, const struct sockadrr *addr, socklen_t addrlen);
denny@~/uplooking/mycode/Project/TCP >> gcc server.c wrap.c
In file included from server.c:9:0:
wrap.h:5:36: warning: ‘struct sockadrr’ declared inside parameter list
wrap.h:7:39: warning: ‘struct sockadrr’ declared inside parameter list
server.c: In function ‘main’:
server.c:31:25: warning: passing argument 2 of ‘Bind’ from incompatible pointer type
wrap.h:5:6: note: expected ‘const struct sockadrr *’ but argument is of type ‘struct sockaddr *’
当没有include "wrap.h"时,程序没有任何问题,一包括这个头,就会有如上警告,大家帮忙啊
server.c部分代码如下:
#include
#include
#include
#include
#include
#include
#include
#include "wrap.h"
#define SERV_PORT 8000
#define LISTEN_COUNT 10
#define MAX_COUNT 100
int main(int argc, char *argv[])
{
struct sockaddr_in servaddr, cliaddr;
socklen_t cliaddr_len;
int listenfd, connfd;
char buf[MAX_COUNT];
char str[INET_ADDRSTRLEN];
int i,n;
memset(&servaddr, 0, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(SERV_PORT);
servaddr.sin_addr.s_addr = INADDR_ANY;
listenfd = Socket(AF_INET, SOCK_STREAM, 0);
Bind(listenfd, (struct sockaddr *)&servaddr, sizeof(servaddr));
Listen(listenfd, LISTEN_COUNT);
wrap.c部分代码如下(用于部分函数的纠错):
#include
#include
#include
#include
#include
void Bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen)
{
if(bind(sockfd, addr, addrlen) == -1){
perr_exit("bind error n");
}
}
warp.h部分代码如下:
#pragma once
void Bind(int sockfd, const struct sockadrr *addr, socklen_t addrlen);
|
void Bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen)
void Bind(int sockfd, const struct sockadrr *addr, socklen_t addrlen);
void Bind(int sockfd, const struct sockadrr *addr, socklen_t addrlen);