/src/kamailio/src/core/sock_ut.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (C) 2010 iptelorg GmbH |
3 | | * |
4 | | * Permission to use, copy, modify, and distribute this software for any |
5 | | * purpose with or without fee is hereby granted, provided that the above |
6 | | * copyright notice and this permission notice appear in all copies. |
7 | | * |
8 | | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
9 | | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
10 | | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
11 | | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
12 | | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
13 | | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
14 | | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
15 | | */ |
16 | | |
17 | | /** Kamailio core :: various socket related functions. |
18 | | * @file sock_ut.c |
19 | | * @ingroup: core |
20 | | */ |
21 | | |
22 | | #include "sock_ut.h" |
23 | | |
24 | | #include <sys/types.h> |
25 | | #include <sys/socket.h> |
26 | | #include <netinet/in.h> |
27 | | #include <netinet/in_systm.h> |
28 | | #include <netinet/ip.h> |
29 | | #include <errno.h> |
30 | | #include <arpa/inet.h> |
31 | | |
32 | | |
33 | | /** get the IP TTL. |
34 | | * @return ttl on success, < 0 on error |
35 | | */ |
36 | | int sock_get_ttl(int sock) |
37 | 0 | { |
38 | 0 | int ioptval = 0; |
39 | 0 | unsigned int ioptvallen = 0; |
40 | |
|
41 | 0 | ioptvallen = sizeof(ioptval); |
42 | 0 | if(getsockopt(sock, IPPROTO_IP, IP_TTL, (void *)&ioptval, &ioptvallen) |
43 | 0 | == -1) { |
44 | 0 | return -1; |
45 | 0 | } |
46 | 0 | return ioptval; |
47 | 0 | } |
48 | | |
49 | | |
50 | | /** set the IP TTL on a socket. |
51 | | * @return ttl on success, < 0 on error |
52 | | */ |
53 | | int sock_set_ttl(int sock, int ttl) |
54 | 0 | { |
55 | 0 | int ioptval = 0; |
56 | |
|
57 | 0 | if(setsockopt(sock, IPPROTO_IP, IP_TTL, (void *)&ioptval, sizeof(ioptval)) |
58 | 0 | == -1) |
59 | 0 | return -1; |
60 | 0 | return ioptval; |
61 | 0 | } |
62 | | |
63 | | /* vi: set ts=4 sw=4 tw=79:ai:cindent: */ |