[Users] XMPP module: network.c file error
Daniel-Constantin Mierla
daniel at voice-system.ro
Mon Jun 18 09:36:30 CEST 2007
Hello,
looks like you don't have the C devel libraries. Is the rest of openser
compiling fine?
Cheers,
Daniel
On 06/12/07 14:56, isetien001 at ikasle.ehu.es wrote:
> Hi!
>
> I'm trying to make xmpp module, to do this I'm configurating according
> to my file system several files (xmpp_component.c, util.c, xmpp.c ...).
> But I get error while compiling the file 'network.c'.
>
> I don't know where these errors come from because the rest of the files
> are OK.
>
> These are the errors and my 'network.c' file:
>
> Any help would be wellcomed.
>
> Izortze.
>
> network.c:27: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’
> before ‘<’ token
> network.c: In function ‘net_connect’:
> network.c:95: error: storage size of ‘sin’ isn’t known
> network.c:97: warning: implicit declaration of function ‘memset’
> network.c:97: warning: incompatible implicit declaration of built-in
> function ‘memset’
> network.c:97: error: invalid application of ‘sizeof’ to incomplete type
> ‘struct sockaddr_in’
> network.c:98: error: ‘AF_INET’ undeclared (first use in this function)
> network.c:98: error: (Each undeclared identifier is reported only once
> network.c:98: error: for each function it appears in.)
> network.c:99: warning: implicit declaration of function ‘htons’
> network.c:101: warning: implicit declaration of function ‘inet_aton’
> network.c:104: warning: implicit declaration of function ‘DBG’
> network.c:106: warning: implicit declaration of function ‘gethostbyname’
> network.c:106: warning: assignment makes pointer from integer without a
> castnetwork.c:107: warning: implicit declaration of function ‘LOG’
> network.c:107: error: ‘L_ERR’ undeclared (first use in this function)
> network.c:108: warning: implicit declaration of function ‘hstrerror’
> network.c:108: error: ‘h_errno’ undeclared (first use in this function)
> network.c:111: warning: implicit declaration of function ‘memcpy’
> network.c:111: warning: incompatible implicit declaration of built-in
> function ‘memcpy’
> network.c:111: error: dereferencing pointer to incomplete type
> network.c:111: error: dereferencing pointer to incomplete type
> network.c:114: warning: implicit declaration of function ‘socket’
> network.c:114: error: ‘PF_INET’ undeclared (first use in this function)
> network.c:114: error: ‘SOCK_STREAM’ undeclared (first use in this function)
> network.c:115: warning: implicit declaration of function ‘strerror’
> network.c:115: error: ‘errno’ undeclared (first use in this function)
> network.c:119: warning: implicit declaration of function ‘inet_ntoa’
> network.c:121: warning: implicit declaration of function ‘connect’
> network.c:121: error: invalid application of ‘sizeof’ to incomplete type
> ‘struct sockaddr_in’
> network.c:123: warning: implicit declaration of function ‘close’
> network.c:95: warning: unused variable ‘sin’
> network.c: In function ‘net_send’:
> network.c:137: warning: implicit declaration of function ‘send’
> network.c: In function ‘net_printf’:
> network.c:149: error: ‘va_list’ undeclared (first use in this function)
> network.c:149: error: expected ‘;’ before ‘args’
> network.c:152: warning: implicit declaration of function ‘va_start’
> network.c:152: error: ‘args’ undeclared (first use in this function)
> network.c:153: warning: implicit declaration of function ‘vsnprintf’
> network.c:154: warning: implicit declaration of function ‘va_end’
> network.c:158: warning: implicit declaration of function ‘strlen’
> network.c:158: warning: incompatible implicit declaration of built-in
> function ‘strlen’
> network.c: In function ‘net_read_static’:
> network.c:166: warning: implicit declaration of function ‘recv’
> network.c:168: error: ‘L_ERR’ undeclared (first use in this function)
> network.c:168: error: ‘errno’ undeclared (first use in this function)
> network.c:169: error: ‘NULL’ undeclared (first use in this function)
> make: *** [network.o] Error 1
>
>
> /*
> * $Id: network.c 1827 2007-03-12 15:22:53Z bogdan_iancu $
> *
> */
>
> include <stdio.h>
> include <stdlib.h>
> include <string.h>
> include <unistd.h>
> include <stdarg.h>
> include <errno.h>
>
> include <sys/socket.h>
> include <netinet/in.h>
> include <arpa/inet.h>
> include <netdb.h>
>
>
> include "/usr/local/src/openser-1.2.0/sip-server/sr_module.h"
>
> int net_listen(char *server, int port)
> {
> int fd;
> struct sockaddr_in sin;
> int on = 1;
>
> memset(&sin, 0, sizeof(struct sockaddr_in));
> sin.sin_family = AF_INET;
> sin.sin_port = htons(port);
>
> if (!inet_aton(server, &sin.sin_addr)) {
> struct hostent *host;
>
> DBG("xmpp: resolving %s...\n", server);
>
> if (!(host = gethostbyname(server))) {
> LOG(L_ERR, "xmpp: resolving %s failed (%s).\n", server,
> hstrerror(h_errno));
> return -1;
> }
> memcpy(&sin.sin_addr, host->h_addr_list[0], host->h_length);
> }
>
> if ((fd = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
> LOG(L_ERR, "xmpp: cannot socket(): %s\n", strerror(errno));
> return -1;
> }
>
> DBG("xmpp: listening on %s:%d\n", inet_ntoa(sin.sin_addr), port);
>
> if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) < 0) {
> LOG(L_WARN, "xmpp: cannot setsockopt(SO_REUSEADDR): %s\n",
> strerror(errno));
> }
>
> if (bind(fd, (struct sockaddr *) &sin, sizeof(struct sockaddr_in)) < 0) {
> LOG(L_ERR, "xmpp: cannot bind(): %s\n", strerror(errno));
> close(fd);
> return -1;
> }
>
> if (listen(fd, 1) < 0) {
> LOG(L_ERR, "xmpp: cannot listen(): %s\n", strerror(errno));
> close(fd);
> return -1;
> }
>
> return fd;
> }
>
> int net_connect(char *server, int port)
> {
> int fd;
> struct sockaddr_in sin;
>
> memset(&sin, 0, sizeof(struct sockaddr_in));
> sin.sin_family = AF_INET;
> sin.sin_port = htons(port);
>
> if (!inet_aton(server, &sin.sin_addr)) {
> struct hostent *host;
>
> DBG("xmpp: resolving %s...\n", server);
>
> if (!(host = gethostbyname(server))) {
> LOG(L_ERR, "xmpp: resolving %s failed (%s).\n", server,
> hstrerror(h_errno));
> return -1;
> }
> memcpy(&sin.sin_addr, host->h_addr_list[0], host->h_length);
> }
>
> if ((fd = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
> LOG(L_ERR, "xmpp: cannot socket(): %s\n", strerror(errno));
> return -1;
> }
>
> DBG("xmpp: connecting to %s:%d...\n", inet_ntoa(sin.sin_addr), port);
>
> if (connect(fd, (struct sockaddr *) &sin, sizeof(struct sockaddr_in)) <
> 0) {
> LOG(L_ERR, "xmpp: cannot connect(): %s\n", strerror(errno));
> close(fd);
> return -1;
> }
>
> DBG("xmpp: connected to %s:%d...\n", inet_ntoa(sin.sin_addr), port);
> return fd;
> }
>
> int net_send(int fd, const char *buf, int len)
> {
> const char *p = buf;
> int res;
>
> do {
> res = send(fd, p, len, 0);
> if (res <= 0)
> return res;
> len -= res;
> p += res;
> } while (len);
>
> return (p - buf);
> }
>
> int net_printf(int fd, char *format, ...)
> {
> va_list args;
> char buf[4096];
>
> va_start(args, format);
> vsnprintf(buf, sizeof(buf) - 1, format, args);
> va_end(args);
>
> DBG("xmpp: net_printf: [%s]\n", buf);
>
> return net_send(fd, buf, strlen(buf));
> }
>
> char *net_read_static(int fd)
> {
> static char buf[4096];
> int res;
>
> res = recv(fd, buf, sizeof(buf) - 1, 0);
> if (res < 0) {
> LOG(L_ERR, "xmpp: recv() error: %s\n", strerror(errno));
> return NULL;
> }
> if (!res)
> return NULL;
> buf[res] = 0;
> return buf;
> }
>
>
> _______________________________________________
> Users mailing list
> Users at openser.org
> http://openser.org/cgi-bin/mailman/listinfo/users
>
>
More information about the sr-users
mailing list