root/trunk/src/remote_output.c @ 2

Revision 2, 2.8 KB (checked in by andreu, 17 years ago)

First RENETCOL CVS Integration

  • Property svn:eol-style set to native
Line 
1/*
2 * File: remote_output.c
3 *
4 * Authors: ANDREU François-Xavier
5 *
6 * Copyright (C) 2005 GIP RENATER
7 */
8
9/*  This file is part of renetcol.
10 *
11 *  renetcol is free software; you can redistribute it and/or modify
12 *  it under the terms of the GNU General Public License as published by
13 *  the Free Software Foundation; either version 2 of the License, or
14 *  (at your option) any later version.
15 *
16 *  renetcol is distributed in the hope that it will be useful,
17 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 *  GNU General Public License for more details.
20 *
21 *  You should have received a copy of the GNU General Public License
22 *  along with renetcol; if not, write to the Free Software
23 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
24 */
25
26#include <string.h> /* for memset */
27#include "remote_output.h"
28
29
30void 
31printHostDef(RemoteHostPtr rHPtr)
32{
33  fprintf(stderr, " socket : %d\n", rHPtr->sockId);
34  fprintf(stderr, " address : %s:%u\n",
35          inet_ntoa(rHPtr->hostAddressPtr->sin_addr),
36          ntohs(rHPtr->hostAddressPtr->sin_port));
37}
38
39/*
40 * freeRemoteHost()
41 */
42void
43freeRemoteHost(RemoteHostPtr rHPtr)
44{
45  if (rHPtr->msgIpv4){
46    free(rHPtr->msgIpv4);
47    rHPtr->msgIpv4 = NULL;
48  }
49  if (rHPtr->msgIpv6){
50    free(rHPtr->msgIpv6);
51    rHPtr->msgIpv6 = NULL;
52  }
53  if (rHPtr->msgXcast){
54    free(rHPtr->msgXcast);
55    rHPtr->msgXcast = NULL;
56  }
57  free(rHPtr);
58  rHPtr = NULL;
59}
60
61/*
62 * freeDb()
63 */
64void
65freeDb(DbPtr dbPtr)
66{
67  if (dbPtr->dbName){
68    free(dbPtr->dbName);
69    dbPtr->dbName = NULL;
70  }
71  if (dbPtr->password){
72    free(dbPtr->password);
73    dbPtr->password = NULL;
74  }
75  if (dbPtr->tableName){
76    free(dbPtr->tableName);
77    dbPtr->tableName = NULL;
78  } 
79  free(dbPtr);
80  dbPtr = NULL;
81}
82
83/*
84 * freeFile()
85 */
86void
87freeFile(FilePtr fPtr)
88{
89  if (fPtr->fileName){
90    free(fPtr->fileName);
91    fPtr->fileName = NULL;
92  }
93  free(fPtr);
94  fPtr = NULL;
95}
96
97/*
98 * create_socket
99 */
100int 
101create_socket(char *remote_address, int remote_port, struct sockaddr_in *addr)
102{
103  int s;
104  s = socket(AF_INET, SOCK_DGRAM, 0);
105  if (s < 0)
106    {
107      perror("opening datagram socket");
108      exit(1);
109    }
110  memset(addr, 0, sizeof(struct sockaddr_in));
111  addr->sin_addr.s_addr = inet_addr(remote_address); /* FIXME obsolete */
112  addr->sin_family = AF_INET;
113  addr->sin_port = htons(remote_port);
114  return s;
115}
116
117/*
118 * send_message
119 */
120int 
121sendMessage(int socket_number, unsigned char *msg, int msgSize,
122            struct sockaddr_in *addr)
123{
124  int s;
125  if ((s=sendto(socket_number, msg, (size_t)msgSize, 0,
126                (struct sockaddr *)addr,
127                sizeof(struct sockaddr_in))) < 0)
128    {
129      fprintf(stderr, "Error ******** : %d bytes sent\n", s);
130      perror("sending packet");
131      exit(1);
132    }
133  return s;
134}
Note: See TracBrowser for help on using the browser.