1: /*
2: ** igmpproxy - IGMP proxy based multicast router
3: ** Copyright (C) 2005 Johnny Egeland <johnny@rlo.org>
4: **
5: ** This program is free software; you can redistribute it and/or modify
6: ** it under the terms of the GNU General Public License as published by
7: ** the Free Software Foundation; either version 2 of the License, or
8: ** (at your option) any later version.
9: **
10: ** This program is distributed in the hope that it will be useful,
11: ** but WITHOUT ANY WARRANTY; without even the implied warranty of
12: ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13: ** GNU General Public License for more details.
14: **
15: ** You should have received a copy of the GNU General Public License
16: ** along with this program; if not, write to the Free Software
17: ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18: **
19: **----------------------------------------------------------------------------
20: **
21: ** This software is derived work from the following software. The original
22: ** source code has been modified from it's original state by the author
23: ** of igmpproxy.
24: **
25: ** smcroute 0.92 - Copyright (C) 2001 Carsten Schill <carsten@cschill.de>
26: ** - Licensed under the GNU General Public License, version 2
27: **
28: ** mrouted 3.9-beta3 - COPYRIGHT 1989 by The Board of Trustees of
29: ** Leland Stanford Junior University.
30: ** - Original license can be found in the Stanford.txt file.
31: **
32: */
33: /**
34: * udpsock.c contains function for creating a UDP socket.
35: *
36: */
37:
38: #include "igmpproxy.h"
39:
40: /**
41: * Creates and connects a simple UDP socket to the target
42: * 'PeerInAdr':'PeerPort'
43: *
44: * @param PeerInAdr - The address to connect to
45: * @param PeerPort - The port to connect to
46: *
47: */
48: int openUdpSocket( uint32_t PeerInAdr, uint16_t PeerPort ) {
49: int Sock;
50: struct sockaddr_in SockAdr;
51:
52: if( (Sock = socket( AF_INET, SOCK_RAW, IPPROTO_IGMP )) < 0 )
53: my_log( LOG_ERR, errno, "UDP socket open" );
54:
55: memset( &SockAdr, 0, sizeof( SockAdr ) );
56: SockAdr.sin_family = AF_INET;
57: SockAdr.sin_port = htons(PeerPort);
58: SockAdr.sin_addr.s_addr = htonl(PeerInAdr);
59:
60: if( bind( Sock, (struct sockaddr *)&SockAdr, sizeof( SockAdr ) ) )
61: my_log( LOG_ERR, errno, "UDP socket bind" );
62:
63: return Sock;
64: }
65:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>