Statistics
| Branch: | Revision:

ml / util / udpSocket.h @ 3edb5149

History | View | Annotate | Download (5.25 KB)

1
/*
2
 *          Policy Management 
3
 *
4
 *          NEC Europe Ltd. PROPRIETARY INFORMATION
5
 *
6
 * This software is supplied under the terms of a license agreement
7
 * or nondisclosure agreement with NEC Europe Ltd. and may not be
8
 * copied or disclosed except in accordance with the terms of that
9
 * agreement.
10
 *
11
 *      Copyright (c) 2009 NEC Europe Ltd. All Rights Reserved.
12
 *
13
 * Authors: Kristian Beckers  <beckers@nw.neclab.eu>
14
 *          Sebastian Kiesel  <kiesel@nw.neclab.eu>
15
 *          
16
 *
17
 * NEC Europe Ltd. DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED,
18
 * INCLUDING BUT NOT LIMITED TO IMPLIED WARRANTIES OF MERCHANTABILITY
19
 * AND FITNESS FOR A PARTICULAR PURPOSE AND THE WARRANTY AGAINST LATENT
20
 * DEFECTS, WITH RESPECT TO THE PROGRAM AND THE ACCOMPANYING
21
 * DOCUMENTATION.
22
 *
23
 * No Liability For Consequential Damages IN NO EVENT SHALL NEC Europe
24
 * Ltd., NEC Corporation OR ANY OF ITS SUBSIDIARIES BE LIABLE FOR ANY
25
 * DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS
26
 * OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF INFORMATION, OR
27
 * OTHER PECUNIARY LOSS AND INDIRECT, CONSEQUENTIAL, INCIDENTAL,
28
 * ECONOMIC OR PUNITIVE DAMAGES) ARISING OUT OF THE USE OF OR INABILITY
29
 * TO USE THIS PROGRAM, EVEN IF NEC Europe Ltd. HAS BEEN ADVISED OF THE
30
 * POSSIBILITY OF SUCH DAMAGES.
31
 *
32
 *     THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.
33
 */
34

    
35
/**
36
 * @file udpSocket.h 
37
 * @brief This file contains a udp socket abstraction. 
38
 *
39
 * The udpSocket is in the current implementation an abstraction for the linux operating system and developed with ubuntu version 8.04. Should it be neccassy to run the messaging layer under another OS the udpSocket would have to be replaced by an implementation for that operating system. 
40
 *
41
 * @author Kristian Beckers  <beckers@nw.neclab.eu> 
42
 * @author Sebastian Kiesel  <kiesel@nw.neclab.eu>
43
 * 
44
 * @date 7/28/2009
45
 */
46

    
47

    
48

    
49
#ifndef UDPSOCKET_H
50
#define UDPSOCKET_H
51

    
52
#include <string.h>
53
#include <netinet/in.h>
54

    
55
/**
56
 * The maximum buffer size for a send or received packet.  
57
 * The value is set to the maximal pmtu size.  
58
 */
59
#define MAXBUF 2000
60

    
61
/// @{
62
/**
63
  * socket error variable: No error occurred  
64
  */
65
#define SO_EE_ORIGIN_NONE       0
66

    
67
/**
68
  * Socket error variable: local error
69
  */
70
#define SO_EE_ORIGIN_LOCAL      1
71

    
72
/**
73
  * Socket error variable: icmp message received  
74
  */
75
#define SO_EE_ORIGIN_ICMP       2
76

    
77
/**
78
  * Socket error variable: icmp version 6 message received  
79
  */
80
#define SO_EE_ORIGIN_ICMP6      3
81
/// @}
82

    
83
typedef enum {OK = 0, MSGLEN, FAILURE} error_codes;
84

    
85
/** 
86
 * A callback functions for received pmtu errors (icmp packets type 3 code 4) 
87
 */
88
typedef void(*icmp_error_cb)(char *buf,int bufsize);
89

    
90
/** 
91
 * Create a messaging layer socket 
92
 * @param port The port of the socket
93
 * @param ipaddr The ip address of the socket. If left NULL the socket is bound to all local interfaces (INADDR_ANY).
94
 * @return The udpSocket file descriptor that the OS assigned. 
95
 */
96
int createSocket(const int port,const char *ipaddr);
97

    
98
/** 
99
 * A function to get the standard TTL from the operating system. 
100
 * @param udpSocket The file descriptor of the udpSocket. 
101
 * @param *ttl A pointer to an int that is used to store the ttl information. 
102
 * @return 1 if the operation is successful and 0 if a mistake occured. 
103
 */
104
int getTTL(const int udpSocket,uint8_t *ttl);
105

    
106
/** 
107
 * Sends a udp packet.
108
 * @param udpSocket The udpSocket file descriptor.
109
 * @param *buffer A pointer to the send buffer. 
110
 * @param bufferSize The size of the send buffer. 
111
 * @param *socketaddr The address of the remote socket
112
 */
113
int sendPacket(const int udpSocket, struct iovec *iov, int len, struct sockaddr_in *socketaddr);
114

    
115
/**
116
 * Receive a udp packet
117
 * @param udpSocket The udpSocket file descriptor.
118
 * @param *buffer A pointer to the receive buffer.
119
 * @param *recvSize A pointer to an int that is used to store the size of the recv buffer. 
120
 * @param *udpdst The socket address from the remote socket that send the packet.
121
 * @param icmpcb_value A function pointer to a callback function from type icmp_error_cb.   
122
 * @param *ttl A pointer to an int that is used to store the ttl information.
123
 */
124
void recvPacket(const int udpSocket,char *buffer,int *recvSize,struct sockaddr_in *udpdst,icmp_error_cb icmpcb_value,int *ttl);
125

    
126
/** 
127
 * This function is used for Error Handling. If an icmp packet is received it processes the packet. 
128
 * @param udpSocket The udpSocket file descriptor
129
 * @param iofunc An integer that states if the function was called from sendPacket or recvPaket. The value for sendPacket is 1 and for recvPacket 2.
130
 * @param *buf A pointer to the send or receive buffer
131
 * @param *bufsize A pointer to an int that ha the size of buf
132
 * @param *addr The address of the remote socket
133
 * @param icmpcb_value A function pointer to a callback function from type icmp_error_cb
134
 * @param *ttl A pointer to an int that is used to store the ttl information
135
 * @return 0 if everything went well and -1 if an error occured
136
 */
137
int handleSocketError(const int udpSocket,const int iofunc,char *buf,int *bufsize,struct sockaddr_in *addr,icmp_error_cb icmpcb_value,int *ttl);
138

    
139
/** 
140
 * This function closes a socket  
141
 * @param udpSocket The file descriptor of the udp socket 
142
 * @return 0 if everything went well and -1 if an error occured 
143
 */
144
int closeSocket(const int udpSocket);
145

    
146
#endif