sockaddr_storage作为函数的参数

时间:2015-12-10 14:47:14

标签: c sockets

编译时我的“简单”服务器出了点问题。

gcc -lnsl -lresolv server_main.c server_function.c -o server

这是我在使用此命令时遇到的错误:

noah@noah-amd64:~/c/RvS/Abgabe3/Aufgabe6$ gcc -lnsl -lresolv 

server_main.c server_function.c -o server
In file included from server_main.c:12:0:
server_function.h:31:53: error: unknown type name ‘sockaddr_storage’
 void write_ip_port_to_buffer(unsigned char* buffer, sockaddr_storage* their_addr);
                                                 ^
In file included from server_function.c:13:0:

server_function.h:31:53: error: unknown type name ‘sockaddr_storage’

void write_ip_port_to_buffer(unsigned char* buffer, sockaddr_storage* their_addr);
                                                     ^
server_function.c:15:53: error: unknown type name ‘sockaddr_storage’
 void write_ip_port_to_buffer(unsigned char* buffer, sockaddr_storage their_addr)

以下是代码的一些行:

server_main.c:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>

#include "server_function.h"

#define HASH_TABLE_SIZE 64


int main(int argc, char *argv[])

server_function.h:

    #ifndef INC_SERVER_FUNCTION_H
    #define INC_SERVER_FUNCTION_H



struct entry_s
{
    int key;
    int value;
    struct entry_s *next;
};

struct hashtable_s
{
    int size;
    struct entry_s *first;

};

void write_ip_port_to_buffer(unsigned char* buffer, sockaddr_storage* their_addr);

int peek_key(unsigned char* buffer);

int unpack_data_8byte(unsigned char *buffer, int *a, int *b,unsigned char *answer);

int pack_data(unsigned char* buffer,unsigned char* command_array, int a, int b);

int set_in_ht (struct hashtable_s *my_ht, int key_n, int value_n);

int get_in_ht (struct hashtable_s *my_ht,int key_n);

int del_in_ht (struct hashtable_s *my_ht,int key_n, int value_n);

#endif

和最后一个:

server_function.c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <netinet/ip.h>

#include "server_function.h"

我猜,我错过了一些包含或类似的东西,但我不知道现在该做什么

1 个答案:

答案 0 :(得分:1)

问题在于:

void write_ip_port_to_buffer(unsigned char* buffer, sockaddr_storage* their_addr);

您遗漏了struct参数声明的their_addr关键字:

void write_ip_port_to_buffer(unsigned char* buffer, struct sockaddr_storage* their_addr);